diff --git a/packages/interface/src/GraphQLLanguageService.js b/packages/interface/src/GraphQLLanguageService.js index b262db30..4f9628ec 100644 --- a/packages/interface/src/GraphQLLanguageService.js +++ b/packages/interface/src/GraphQLLanguageService.js @@ -79,7 +79,7 @@ export class GraphQLLanguageService { const projectConfig = this._graphQLConfig.getConfigForFile(uri); const schemaPath = projectConfig.schemaPath; try { - const queryAST = parse(query); + const queryAST = parse(query, projectConfig.parseOptions); if (!schemaPath || uri !== schemaPath) { queryHasExtensions = queryAST.definitions.some(definition => { switch (definition.kind) { @@ -121,6 +121,7 @@ export class GraphQLLanguageService { const fragmentDependencies = await this._graphQLCache.getFragmentDependencies( query, fragmentDefinitions, + projectConfig, ); const dependenciesSource = fragmentDependencies.reduce( (prev, cur) => `${prev} ${print(cur.definition)}`, @@ -131,7 +132,7 @@ export class GraphQLLanguageService { let validationAst = null; try { - validationAst = parse(source); + validationAst = parse(source, projectConfig.parseOptions); } catch (error) { // the query string is already checked to be parsed properly - errors // from this parse must be from corrupted fragment dependencies. @@ -154,7 +155,7 @@ export class GraphQLLanguageService { } const schema = await this._graphQLCache - .getSchema(projectConfig.projectName, queryHasExtensions) + .getSchema(projectConfig, queryHasExtensions) .catch(() => null); if (!schema) { @@ -171,7 +172,7 @@ export class GraphQLLanguageService { ): Promise> { const projectConfig = this._graphQLConfig.getConfigForFile(filePath); const schema = await this._graphQLCache - .getSchema(projectConfig.projectName) + .getSchema(projectConfig) .catch(() => null); if (schema) { @@ -187,7 +188,7 @@ export class GraphQLLanguageService { ): Promise { const projectConfig = this._graphQLConfig.getConfigForFile(filePath); const schema = await this._graphQLCache - .getSchema(projectConfig.projectName) + .getSchema(projectConfig) .catch(() => null); if (schema) { @@ -205,7 +206,7 @@ export class GraphQLLanguageService { let ast; try { - ast = parse(query); + ast = parse(query, projectConfig.parseOptions); } catch (error) { return null; } diff --git a/packages/server/src/GraphQLCache.js b/packages/server/src/GraphQLCache.js index 111ca97f..ebf892cf 100644 --- a/packages/server/src/GraphQLCache.js +++ b/packages/server/src/GraphQLCache.js @@ -83,6 +83,7 @@ export class GraphQLCache implements GraphQLCacheInterface { getFragmentDependencies = async ( query: string, fragmentDefinitions: ?Map, + projectConfig: GraphQLProjectConfig, ): Promise> => { // If there isn't context for fragment references, // return an empty array. @@ -93,7 +94,7 @@ export class GraphQLCache implements GraphQLCacheInterface { // Return an empty array. let parsedQuery; try { - parsedQuery = parse(query); + parsedQuery = parse(query, projectConfig.parseOptions); } catch (error) { return []; } @@ -183,6 +184,7 @@ export class GraphQLCache implements GraphQLCacheInterface { getObjectTypeDependencies = async ( query: string, objectTypeDefinitions: ?Map, + projectConfig: GraphQLProjectConfig, ): Promise> => { // If there isn't context for object type references, // return an empty array. @@ -193,7 +195,7 @@ export class GraphQLCache implements GraphQLCacheInterface { // Return an empty array. let parsedQuery; try { - parsedQuery = parse(query); + parsedQuery = parse(query, projectConfig.parseOptions); } catch (error) { return []; } @@ -320,7 +322,7 @@ export class GraphQLCache implements GraphQLCacheInterface { return; } - const fileAndContent = await this.promiseToReadGraphQLFile(filePath); + const fileAndContent = await this.promiseToReadGraphQLFile(filePath, projectConfig); graphQLFileMap.set(filePath, { ...fileAndContent, size, @@ -337,6 +339,7 @@ export class GraphQLCache implements GraphQLCacheInterface { {size, mtime}, filePath, exists, + projectConfig, ), ); } @@ -413,9 +416,10 @@ export class GraphQLCache implements GraphQLCacheInterface { metrics: {size: number, mtime: number}, filePath: Uri, exists: boolean, + projectConfig: GraphQLProjectConfig, ): Promise> { const fileAndContent = exists - ? await this.promiseToReadGraphQLFile(filePath) + ? await this.promiseToReadGraphQLFile(filePath, projectConfig) : null; const graphQLFileInfo = {...fileAndContent, ...metrics}; @@ -438,11 +442,12 @@ export class GraphQLCache implements GraphQLCacheInterface { rootDir: Uri, filePath: Uri, contents: Array, + projectConfig: GraphQLProjectConfig, ): Promise { const cache = this._fragmentDefinitionsCache.get(rootDir); const asts = contents.map(({query}) => { try { - return {ast: parse(query), query}; + return {ast: parse(query, projectConfig.parseOptions), query}; } catch (error) { return {ast: null, query}; } @@ -475,9 +480,10 @@ export class GraphQLCache implements GraphQLCacheInterface { rootDir: Uri, filePath: Uri, exists: boolean, + projectConfig: GraphQLProjectConfig, ): Promise { const fileAndContent = exists - ? await this.promiseToReadGraphQLFile(filePath) + ? await this.promiseToReadGraphQLFile(filePath, projectConfig) : null; // In the case of fragment definitions, the cache could just map the // definition name to the parsed ast, whether or not it existed @@ -489,7 +495,7 @@ export class GraphQLCache implements GraphQLCacheInterface { cache.delete(filePath); } } else if (fileAndContent && fileAndContent.queries) { - this.updateFragmentDefinition(rootDir, filePath, fileAndContent.queries); + this.updateFragmentDefinition(rootDir, filePath, fileAndContent.queries, projectConfig); } } @@ -497,11 +503,12 @@ export class GraphQLCache implements GraphQLCacheInterface { rootDir: Uri, filePath: Uri, contents: Array, + projectConfig: GraphQLProjectConfig, ): Promise { const cache = this._typeDefinitionsCache.get(rootDir); const asts = contents.map(({query}) => { try { - return {ast: parse(query), query}; + return {ast: parse(query, projectConfig.parseOptions), query}; } catch (error) { return {ast: null, query}; } @@ -538,6 +545,7 @@ export class GraphQLCache implements GraphQLCacheInterface { rootDir: Uri, filePath: Uri, exists: boolean, + projectConfig: GraphQLProjectConfig, ): Promise { const fileAndContent = exists ? await this.promiseToReadGraphQLFile(filePath) @@ -623,16 +631,10 @@ export class GraphQLCache implements GraphQLCacheInterface { } getSchema = async ( - appName: ?string, + projectConfig: GraphQLProjectConfig, queryHasExtensions?: ?boolean = false, ): Promise => { - const projectConfig = this._graphQLConfig.getProjectConfig(appName); - - if (!projectConfig) { - return null; - } - - const projectName = appName || 'undefinedName'; + const projectName = projectConfig.projectName || 'undefinedName'; const schemaPath = projectConfig.schemaPath; const endpointInfo = this._getDefaultEndpoint(projectConfig); @@ -678,7 +680,7 @@ export class GraphQLCache implements GraphQLCacheInterface { const customDirectives = projectConfig.extensions.customDirectives; if (customDirectives && schema) { const directivesSDL = customDirectives.join('\n\n'); - schema = extendSchema(schema, parse(directivesSDL)); + schema = extendSchema(schema, parse(directivesSDL, projectConfig.parseOptions)); } if (!schema) { @@ -826,6 +828,7 @@ export class GraphQLCache implements GraphQLCacheInterface { */ promiseToReadGraphQLFile = ( filePath: Uri, + projectConfig: GraphQLProjectConfig, ): Promise<{ filePath: Uri, content: string, @@ -850,7 +853,7 @@ export class GraphQLCache implements GraphQLCacheInterface { return; } - queries.forEach(({query}) => asts.push(parse(query))); + queries.forEach(({query}) => asts.push(parse(query, projectConfig.parseOptions))); } catch (_) { // If query has syntax errors, go ahead and still resolve // the filePath and the content, but leave ast empty. diff --git a/packages/types/src/index.js b/packages/types/src/index.js index d136cf9d..c676f3fb 100644 --- a/packages/types/src/index.js +++ b/packages/types/src/index.js @@ -87,6 +87,7 @@ export interface GraphQLCache { getObjectTypeDependencies: ( query: string, fragmentDefinitions: ?Map, + projectConfig: GraphQLProjectConfig, ) => Promise>; getObjectTypeDependenciesForAST: ( @@ -95,24 +96,27 @@ export interface GraphQLCache { ) => Promise>; getObjectTypeDefinitions: ( - graphQLConfig: GraphQLProjectConfig, + projectConfig: GraphQLProjectConfig, ) => Promise>; +updateObjectTypeDefinition: ( rootDir: Uri, filePath: Uri, contents: Array, + projectConfig: GraphQLProjectConfig, ) => Promise; +updateObjectTypeDefinitionCache: ( rootDir: Uri, filePath: Uri, exists: boolean, + projectConfig: GraphQLProjectConfig, ) => Promise; getFragmentDependencies: ( query: string, fragmentDefinitions: ?Map, + projectConfig: GraphQLProjectConfig, ) => Promise>; getFragmentDependenciesForAST: ( @@ -121,23 +125,25 @@ export interface GraphQLCache { ) => Promise>; getFragmentDefinitions: ( - graphQLConfig: GraphQLProjectConfig, + projectConfig: GraphQLProjectConfig, ) => Promise>; +updateFragmentDefinition: ( rootDir: Uri, filePath: Uri, contents: Array, + projectConfig: GraphQLProjectConfig, ) => Promise; +updateFragmentDefinitionCache: ( rootDir: Uri, filePath: Uri, exists: boolean, + projectConfig: GraphQLProjectConfig, ) => Promise; getSchema: ( - appName: ?string, + projectConfig: GraphQLProjectConfig, queryHasExtensions?: ?boolean, ) => Promise;