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

Commit 55b4380

Browse files
authored
Merge pull request #224 from mgadda/mgadda/fix_globbing
Fixes #221 and #222 - fixes GraphQLCache file globbing
2 parents a937700 + ec0f37a commit 55b4380

File tree

3 files changed

+36
-8
lines changed

3 files changed

+36
-8
lines changed

packages/server/src/GraphQLCache.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,9 @@ export class GraphQLCache implements GraphQLCacheInterface {
158158
return this._fragmentDefinitionsCache.get(rootDir) || new Map();
159159
}
160160

161-
const includes = projectConfig.includes.map(
162-
filePath => filePath.split('*')[0],
163-
);
164-
165161
const filesFromInputDirs = await this._readFilesFromInputDirs(
166162
rootDir,
167-
includes,
163+
projectConfig.includes,
168164
);
169165
const list = filesFromInputDirs.filter(fileInfo =>
170166
projectConfig.includesFile(fileInfo.filePath),
@@ -246,9 +242,18 @@ export class GraphQLCache implements GraphQLCacheInterface {
246242
rootDir: string,
247243
includes: string[],
248244
): Promise<Array<GraphQLFileMetadata>> => {
245+
let pattern: string;
246+
// See https://github.com/graphql/graphql-language-service/issues/221
247+
// for details on why special handling is required here for the
248+
// includes.length === 1 case.
249+
if (includes.length === 1) {
250+
pattern = includes[0];
251+
} else {
252+
pattern = `{${includes.join(',')}}`;
253+
}
249254
return new Promise((resolve, reject) => {
250255
const globResult = new glob.Glob(
251-
`{${includes.join(',')}}/**/*.{js,graphql}`,
256+
pattern,
252257
{
253258
cwd: rootDir,
254259
stat: true,

packages/server/src/__tests__/.graphqlconfig

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
{
2-
"includes": ["__queries__"],
3-
"excludes": ["__excludedQueries__"],
42
"projects": {
53
"testWithSchema": {
64
"schemaPath": "__schema__/StarWarsSchema.graphql"
@@ -33,6 +31,17 @@
3331
"directive @customDirective on FIELD"
3432
]
3533
}
34+
},
35+
"testSingularIncludesGlob": {
36+
"schemaPath": "__schema__/StarWarsSchema.graphql",
37+
"includes": [ "__queries__/*.graphql" ]
38+
},
39+
"testSingularMultipleIncludes": {
40+
"schemaPath": "__schema__/StarWarsSchema.graphql",
41+
"includes": [
42+
"__queries__/*.graphql",
43+
"__fragments__/*.graphql"
44+
]
3645
}
3746
},
3847
"extensions": {

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,18 @@ describe('GraphQLCache', () => {
157157
expect(result.length).to.equal(1);
158158
});
159159
});
160+
161+
describe('getFragmentDefinitions', () => {
162+
it('it caches fragments found through single glob in `includes`', async () => {
163+
const config = graphQLRC.getProjectConfig('testSingularIncludesGlob');
164+
const fragmentDefinitions = await cache.getFragmentDefinitions(config);
165+
expect(fragmentDefinitions.get('testFragment')).to.not.be.undefined;
166+
});
167+
168+
it('it caches fragments found through multiple globs in `includes`', async () => {
169+
const config = graphQLRC.getProjectConfig('testSingularMultipleIncludes');
170+
const fragmentDefinitions = await cache.getFragmentDefinitions(config);
171+
expect(fragmentDefinitions.get('testFragment')).to.not.be.undefined;
172+
});
173+
});
160174
});

0 commit comments

Comments
 (0)