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

Commit 3852ced

Browse files
committed
Don't import GraphQL types from internal module
See: graphql/graphql-js#1221 (comment)
1 parent 7055643 commit 3852ced

File tree

3 files changed

+63
-30
lines changed

3 files changed

+63
-30
lines changed

packages/interface/src/GraphQLLanguageService.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,18 @@ import type {
2828
import type {Position} from 'graphql-language-service-utils';
2929
import type {Hover} from 'vscode-languageserver-types';
3030

31+
import {Kind, parse, print} from 'graphql';
32+
import {getAutocompleteSuggestions} from './getAutocompleteSuggestions';
33+
import {getHoverInformation} from './getHoverInformation';
34+
import {validateQuery, getRange, SEVERITY} from './getDiagnostics';
3135
import {
36+
getDefinitionQueryResultForFragmentSpread,
37+
getDefinitionQueryResultForDefinitionNode,
38+
getDefinitionQueryResultForNamedType,
39+
} from './getDefinition';
40+
import {getASTNodeAtPosition} from 'graphql-language-service-utils';
41+
42+
const {
3243
FRAGMENT_DEFINITION,
3344
OBJECT_TYPE_DEFINITION,
3445
INTERFACE_TYPE_DEFINITION,
@@ -46,18 +57,7 @@ import {
4657
FRAGMENT_SPREAD,
4758
OPERATION_DEFINITION,
4859
NAMED_TYPE,
49-
} from 'graphql/language/kinds';
50-
51-
import {parse, print} from 'graphql';
52-
import {getAutocompleteSuggestions} from './getAutocompleteSuggestions';
53-
import {getHoverInformation} from './getHoverInformation';
54-
import {validateQuery, getRange, SEVERITY} from './getDiagnostics';
55-
import {
56-
getDefinitionQueryResultForFragmentSpread,
57-
getDefinitionQueryResultForDefinitionNode,
58-
getDefinitionQueryResultForNamedType,
59-
} from './getDefinition';
60-
import {getASTNodeAtPosition} from 'graphql-language-service-utils';
60+
} = Kind;
6161

6262
export class GraphQLLanguageService {
6363
_graphQLCache: GraphQLCache;

packages/interface/src/getOutline.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ import type {
1414
TokenKind,
1515
} from 'graphql-language-service-types';
1616

17-
import {parse, visit} from 'graphql';
18-
import {INLINE_FRAGMENT} from 'graphql/language/kinds';
17+
import {Kind, parse, visit} from 'graphql';
1918
import {offsetToPosition} from 'graphql-language-service-utils';
2019

20+
const {INLINE_FRAGMENT} = Kind;
21+
2122
const OUTLINEABLE_KINDS = {
2223
Field: true,
2324
OperationDefinition: true,

packages/server/src/GraphQLCache.js

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,18 @@ import type {
2323

2424
import fs from 'fs';
2525
import path from 'path';
26-
import {GraphQLSchema, extendSchema, parse, visit} from 'graphql';
26+
import {GraphQLSchema, Kind, extendSchema, parse, visit} from 'graphql';
2727
import nullthrows from 'nullthrows';
2828

29-
import {
29+
import {getGraphQLConfig, GraphQLConfig, GraphQLEndpoint} from 'graphql-config';
30+
import {getQueryAndRange} from './MessageProcessor';
31+
import stringToHash from './stringToHash';
32+
import glob from 'glob';
33+
34+
// Maximum files to read when processing GraphQL files.
35+
const MAX_READS = 200;
36+
37+
const {
3038
DOCUMENT,
3139
FRAGMENT_DEFINITION,
3240
OBJECT_TYPE_DEFINITION,
@@ -42,14 +50,7 @@ import {
4250
ENUM_TYPE_EXTENSION,
4351
INPUT_OBJECT_TYPE_EXTENSION,
4452
DIRECTIVE_DEFINITION,
45-
} from 'graphql/language/kinds';
46-
import {getGraphQLConfig, GraphQLConfig, GraphQLEndpoint} from 'graphql-config';
47-
import {getQueryAndRange} from './MessageProcessor';
48-
import stringToHash from './stringToHash';
49-
import glob from 'glob';
50-
51-
// Maximum files to read when processing GraphQL files.
52-
const MAX_READS = 200;
53+
} = Kind;
5354

5455
export async function getGraphQLCache(
5556
configDir: Uri,
@@ -93,7 +94,10 @@ export class GraphQLCache implements GraphQLCacheInterface {
9394
// Return an empty array.
9495
let parsedQuery;
9596
try {
96-
parsedQuery = parse(query);
97+
parsedQuery = parse(query, {
98+
allowLegacySDLImplementsInterfaces: true,
99+
allowLegacySDLEmptyFields: true,
100+
});
97101
} catch (error) {
98102
return [];
99103
}
@@ -193,7 +197,10 @@ export class GraphQLCache implements GraphQLCacheInterface {
193197
// Return an empty array.
194198
let parsedQuery;
195199
try {
196-
parsedQuery = parse(query);
200+
parsedQuery = parse(query, {
201+
allowLegacySDLImplementsInterfaces: true,
202+
allowLegacySDLEmptyFields: true,
203+
});
197204
} catch (error) {
198205
return [];
199206
}
@@ -442,7 +449,13 @@ export class GraphQLCache implements GraphQLCacheInterface {
442449
const cache = this._fragmentDefinitionsCache.get(rootDir);
443450
const asts = contents.map(({query}) => {
444451
try {
445-
return {ast: parse(query), query};
452+
return {
453+
ast: parse(query, {
454+
allowLegacySDLImplementsInterfaces: true,
455+
allowLegacySDLEmptyFields: true,
456+
}),
457+
query,
458+
};
446459
} catch (error) {
447460
return {ast: null, query};
448461
}
@@ -501,7 +514,13 @@ export class GraphQLCache implements GraphQLCacheInterface {
501514
const cache = this._typeDefinitionsCache.get(rootDir);
502515
const asts = contents.map(({query}) => {
503516
try {
504-
return {ast: parse(query), query};
517+
return {
518+
ast: parse(query, {
519+
allowLegacySDLImplementsInterfaces: true,
520+
allowLegacySDLEmptyFields: true,
521+
}),
522+
query,
523+
};
505524
} catch (error) {
506525
return {ast: null, query};
507526
}
@@ -678,7 +697,13 @@ export class GraphQLCache implements GraphQLCacheInterface {
678697
const customDirectives = projectConfig.extensions.customDirectives;
679698
if (customDirectives && schema) {
680699
const directivesSDL = customDirectives.join('\n\n');
681-
schema = extendSchema(schema, parse(directivesSDL));
700+
schema = extendSchema(
701+
schema,
702+
parse(directivesSDL, {
703+
allowLegacySDLImplementsInterfaces: true,
704+
allowLegacySDLEmptyFields: true,
705+
}),
706+
);
682707
}
683708

684709
if (!schema) {
@@ -850,7 +875,14 @@ export class GraphQLCache implements GraphQLCacheInterface {
850875
return;
851876
}
852877

853-
queries.forEach(({query}) => asts.push(parse(query)));
878+
queries.forEach(({query}) =>
879+
asts.push(
880+
parse(query, {
881+
allowLegacySDLImplementsInterfaces: true,
882+
allowLegacySDLEmptyFields: true,
883+
}),
884+
),
885+
);
854886
} catch (_) {
855887
// If query has syntax errors, go ahead and still resolve
856888
// the filePath and the content, but leave ast empty.

0 commit comments

Comments
 (0)