Skip to content
This repository was archived by the owner on Sep 2, 2020. It is now read-only.

Commit ea24875

Browse files
authored
Merge pull request #228 from lostplan/glob-error-227
Check type of statCache entries
2 parents 93d1595 + 4f9d017 commit ea24875

File tree

4 files changed

+38
-10
lines changed

4 files changed

+38
-10
lines changed

packages/server/src/GraphQLCache.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,11 @@ export class GraphQLCache implements GraphQLCacheInterface {
243243
includes: string[],
244244
): Promise<Array<GraphQLFileMetadata>> => {
245245
let pattern: string;
246+
247+
if (includes.length === 0) {
248+
return Promise.resolve([]);
249+
}
250+
246251
// See https://github.com/graphql/graphql-language-service/issues/221
247252
// for details on why special handling is required here for the
248253
// includes.length === 1 case.
@@ -251,6 +256,7 @@ export class GraphQLCache implements GraphQLCacheInterface {
251256
} else {
252257
pattern = `{${includes.join(',')}}`;
253258
}
259+
254260
return new Promise((resolve, reject) => {
255261
const globResult = new glob.Glob(
256262
pattern,
@@ -276,13 +282,17 @@ export class GraphQLCache implements GraphQLCacheInterface {
276282
);
277283
globResult.on('end', () => {
278284
resolve(
279-
Object.keys(globResult.statCache).map(filePath => ({
280-
filePath,
281-
mtime: Math.trunc(
282-
globResult.statCache[filePath].mtime.getTime() / 1000,
283-
),
284-
size: globResult.statCache[filePath].size,
285-
})),
285+
Object.keys(globResult.statCache)
286+
.filter(
287+
filePath => typeof globResult.statCache[filePath] === 'object',
288+
)
289+
.map(filePath => ({
290+
filePath,
291+
mtime: Math.trunc(
292+
globResult.statCache[filePath].mtime.getTime() / 1000,
293+
),
294+
size: globResult.statCache[filePath].size,
295+
})),
286296
);
287297
});
288298
});

packages/server/src/__tests__/.graphqlconfig

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,19 @@
3636
"schemaPath": "__schema__/StarWarsSchema.graphql",
3737
"includes": [ "__queries__/*.graphql" ]
3838
},
39-
"testSingularMultipleIncludes": {
39+
"testMultipleIncludes": {
4040
"schemaPath": "__schema__/StarWarsSchema.graphql",
4141
"includes": [
4242
"__queries__/*.graphql",
4343
"__fragments__/*.graphql"
4444
]
45+
},
46+
"testNoIncludes": {
47+
"schemaPath": "__schema__/StarWarsSchema.graphql"
48+
},
49+
"testBadIncludes": {
50+
"schemaPath": "__schema__/StarWarsSchema.graphql",
51+
"includes": ["nope.nopeql"]
4552
}
4653
},
4754
"extensions": {

packages/server/src/__tests__/GraphQLCache-test.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,21 @@ describe('GraphQLCache', () => {
166166
});
167167

168168
it('it caches fragments found through multiple globs in `includes`', async () => {
169-
const config = graphQLRC.getProjectConfig('testSingularMultipleIncludes');
169+
const config = graphQLRC.getProjectConfig('testMultipleIncludes');
170170
const fragmentDefinitions = await cache.getFragmentDefinitions(config);
171171
expect(fragmentDefinitions.get('testFragment')).to.not.be.undefined;
172172
});
173+
174+
it('handles empty includes', async () => {
175+
const config = graphQLRC.getProjectConfig('testNoIncludes');
176+
const fragmentDefinitions = await cache.getFragmentDefinitions(config);
177+
expect(fragmentDefinitions.get('testFragment')).to.be.undefined;
178+
});
179+
180+
it('handles non-existent includes', async () => {
181+
const config = graphQLRC.getProjectConfig('testBadIncludes');
182+
const fragmentDefinitions = await cache.getFragmentDefinitions(config);
183+
expect(fragmentDefinitions.get('testFragment')).to.be.undefined;
184+
});
173185
});
174186
});

packages/server/src/__tests__/MessageProcessor-test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {beforeEach, describe, it} from 'mocha';
1515
import {MessageProcessor} from '../MessageProcessor';
1616
import MockWatchmanClient from '../__mocks__/MockWatchmanClient';
1717
import {GraphQLConfig} from 'graphql-config';
18-
import {GraphQLCache} from '../GraphQLCache';
1918

2019
describe('MessageProcessor', () => {
2120
const mockWatchmanClient = new MockWatchmanClient();

0 commit comments

Comments
 (0)