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

Commit bd06a15

Browse files
committed
WIP: Allow passing ParseOptions to parse() with GraphQL Language Server
I want to pass some ParseOptions. The obvious way to do this is to specify it in `.graphqlconfig` and make graphql-language-service pick this up and respect it. This is only a start. I haven't figured out the cleanest way to pass this to `GraphQLCache`. That will come next.
1 parent 0ac376c commit bd06a15

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

packages/interface/src/GraphQLLanguageService.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export class GraphQLLanguageService {
7979
const projectConfig = this._graphQLConfig.getConfigForFile(uri);
8080
const schemaPath = projectConfig.schemaPath;
8181
try {
82-
const queryAST = parse(query);
82+
const queryAST = parse(query, projectConfig.parseOptions);
8383
if (!schemaPath || uri !== schemaPath) {
8484
queryHasExtensions = queryAST.definitions.some(definition => {
8585
switch (definition.kind) {
@@ -121,6 +121,7 @@ export class GraphQLLanguageService {
121121
const fragmentDependencies = await this._graphQLCache.getFragmentDependencies(
122122
query,
123123
fragmentDefinitions,
124+
projectConfig.projectName,
124125
);
125126
const dependenciesSource = fragmentDependencies.reduce(
126127
(prev, cur) => `${prev} ${print(cur.definition)}`,
@@ -131,7 +132,7 @@ export class GraphQLLanguageService {
131132

132133
let validationAst = null;
133134
try {
134-
validationAst = parse(source);
135+
validationAst = parse(source, projectConfig.parseOptions);
135136
} catch (error) {
136137
// the query string is already checked to be parsed properly - errors
137138
// from this parse must be from corrupted fragment dependencies.
@@ -205,7 +206,7 @@ export class GraphQLLanguageService {
205206

206207
let ast;
207208
try {
208-
ast = parse(query);
209+
ast = parse(query, projectConfig.parseOptions);
209210
} catch (error) {
210211
return null;
211212
}

packages/server/src/GraphQLCache.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,13 @@ export class GraphQLCache implements GraphQLCacheInterface {
8383
getFragmentDependencies = async (
8484
query: string,
8585
fragmentDefinitions: ?Map<string, FragmentInfo>,
86+
projectName: ?string,
8687
): Promise<Array<FragmentInfo>> => {
88+
const projectConfig = this._graphQLConfig.getProjectConfig(projectName);
89+
if (projectConfig == null) {
90+
return [];
91+
}
92+
8793
// If there isn't context for fragment references,
8894
// return an empty array.
8995
if (!fragmentDefinitions) {
@@ -93,7 +99,7 @@ export class GraphQLCache implements GraphQLCacheInterface {
9399
// Return an empty array.
94100
let parsedQuery;
95101
try {
96-
parsedQuery = parse(query);
102+
parsedQuery = parse(query, projectConfig.parseOptions);
97103
} catch (error) {
98104
return [];
99105
}

packages/types/src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ export interface GraphQLCache {
113113
getFragmentDependencies: (
114114
query: string,
115115
fragmentDefinitions: ?Map<string, FragmentInfo>,
116+
projectName: ?string,
116117
) => Promise<Array<FragmentInfo>>;
117118

118119
getFragmentDependenciesForAST: (

0 commit comments

Comments
 (0)