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

Fixes #221 and #222 - fixes GraphQLCache file globbing #224

Merged
merged 4 commits into from
Apr 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions packages/server/src/GraphQLCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,9 @@ export class GraphQLCache implements GraphQLCacheInterface {
return this._fragmentDefinitionsCache.get(rootDir) || new Map();
}

const includes = projectConfig.includes.map(
filePath => filePath.split('*')[0],
);

const filesFromInputDirs = await this._readFilesFromInputDirs(
rootDir,
includes,
projectConfig.includes,
);
const list = filesFromInputDirs.filter(fileInfo =>
projectConfig.includesFile(fileInfo.filePath),
Expand Down Expand Up @@ -246,9 +242,18 @@ export class GraphQLCache implements GraphQLCacheInterface {
rootDir: string,
includes: string[],
): Promise<Array<GraphQLFileMetadata>> => {
let pattern: string;
// See https://github.com/graphql/graphql-language-service/issues/221
// for details on why special handling is required here for the
// includes.length === 1 case.
if (includes.length === 1) {
pattern = includes[0];
} else {
pattern = `{${includes.join(',')}}`;
}
return new Promise((resolve, reject) => {
const globResult = new glob.Glob(
`{${includes.join(',')}}/**/*.{js,graphql}`,
pattern,
{
cwd: rootDir,
stat: true,
Expand Down
13 changes: 11 additions & 2 deletions packages/server/src/__tests__/.graphqlconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"includes": ["__queries__"],
"excludes": ["__excludedQueries__"],
"projects": {
"testWithSchema": {
"schemaPath": "__schema__/StarWarsSchema.graphql"
Expand Down Expand Up @@ -33,6 +31,17 @@
"directive @customDirective on FIELD"
]
}
},
"testSingularIncludesGlob": {
"schemaPath": "__schema__/StarWarsSchema.graphql",
"includes": [ "__queries__/*.graphql" ]
},
"testSingularMultipleIncludes": {
"schemaPath": "__schema__/StarWarsSchema.graphql",
"includes": [
"__queries__/*.graphql",
"__fragments__/*.graphql"
]
}
},
"extensions": {
Expand Down
14 changes: 14 additions & 0 deletions packages/server/src/__tests__/GraphQLCache-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,18 @@ describe('GraphQLCache', () => {
expect(result.length).to.equal(1);
});
});

describe('getFragmentDefinitions', () => {
it('it caches fragments found through single glob in `includes`', async () => {
const config = graphQLRC.getProjectConfig('testSingularIncludesGlob');
const fragmentDefinitions = await cache.getFragmentDefinitions(config);
expect(fragmentDefinitions.get('testFragment')).to.not.be.undefined;
});

it('it caches fragments found through multiple globs in `includes`', async () => {
const config = graphQLRC.getProjectConfig('testSingularMultipleIncludes');
const fragmentDefinitions = await cache.getFragmentDefinitions(config);
expect(fragmentDefinitions.get('testFragment')).to.not.be.undefined;
});
});
});