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

Commit 4f9d017

Browse files
committed
Add shortcircuit & tests
1 parent 6e31f5e commit 4f9d017

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

packages/server/src/GraphQLCache.js

Lines changed: 6 additions & 0 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,

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
});

0 commit comments

Comments
 (0)