vscode-apollo 1.20.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.circleci/config.yml +27 -18
- package/.git-blame-ignore-revs +2 -0
- package/.nvmrc +1 -1
- package/.vscode/launch.json +9 -4
- package/.vscode/tasks.json +58 -16
- package/.vscodeignore +12 -1
- package/CHANGELOG.md +84 -0
- package/CODEOWNERS +4 -0
- package/README.md +97 -48
- package/graphql.configuration.json +5 -1
- package/images/marketplace/apollo-wordmark.png +0 -0
- package/jest.config.ts +14 -4
- package/jest.e2e.config.js +17 -0
- package/package.json +67 -68
- package/renovate.json +7 -0
- package/sampleWorkspace/clientSchema/apollo.config.cjs +10 -0
- package/sampleWorkspace/clientSchema/src/clientSchema.js +16 -0
- package/sampleWorkspace/clientSchema/src/test.js +18 -0
- package/sampleWorkspace/fixtures/starwarsSchema.graphql +299 -0
- package/sampleWorkspace/httpSchema/apollo.config.ts +8 -0
- package/sampleWorkspace/httpSchema/src/test.js +9 -0
- package/sampleWorkspace/localSchema/apollo.config.js +8 -0
- package/sampleWorkspace/localSchema/src/test.js +8 -0
- package/sampleWorkspace/localSchemaArray/apollo.config.js +12 -0
- package/sampleWorkspace/localSchemaArray/planets.graphql +20 -0
- package/sampleWorkspace/localSchemaArray/src/test.js +12 -0
- package/sampleWorkspace/sampleWorkspace.code-workspace +20 -0
- package/sampleWorkspace/spotifyGraph/apollo.config.mjs +5 -0
- package/sampleWorkspace/spotifyGraph/src/test.js +11 -0
- package/src/__e2e__/mockServer.js +117 -0
- package/src/__e2e__/mocks.js +13094 -0
- package/src/__e2e__/run.js +23 -0
- package/src/__e2e__/runTests.js +44 -0
- package/src/__e2e__/setup.js +1 -0
- package/src/__e2e__/vscode-environment.js +16 -0
- package/src/__e2e__/vscode.js +1 -0
- package/src/build.js +57 -0
- package/src/env/index.ts +0 -3
- package/src/extension.ts +251 -225
- package/src/language-server/__e2e__/clientSchema.e2e.ts +147 -0
- package/src/language-server/__e2e__/httpSchema.e2e.ts +21 -0
- package/src/language-server/__e2e__/localSchema.e2e.ts +25 -0
- package/src/language-server/__e2e__/localSchemaArray.e2e.ts +31 -0
- package/src/language-server/__e2e__/studioGraph.e2e.ts +65 -0
- package/src/language-server/__e2e__/utils.ts +151 -0
- package/src/language-server/__tests__/diagnostics.test.ts +8 -8
- package/src/language-server/__tests__/fileSet.test.ts +1 -1
- package/src/language-server/__tests__/fixtures/starwarsSchema.ts +2 -2
- package/src/language-server/config/__tests__/config.ts +22 -96
- package/src/language-server/config/__tests__/loadConfig.ts +120 -220
- package/src/language-server/config/__tests__/utils.ts +22 -29
- package/src/language-server/config/config.ts +221 -156
- package/src/language-server/config/loadConfig.ts +32 -153
- package/src/language-server/config/loadTsConfig.ts +70 -0
- package/src/language-server/config/utils.ts +5 -16
- package/src/language-server/diagnostics.ts +17 -8
- package/src/language-server/document.ts +16 -16
- package/src/language-server/engine/index.ts +57 -39
- package/src/language-server/engine/operations/frontendUrlRoot.ts +9 -1
- package/src/language-server/engine/operations/schemaTagsAndFieldStats.ts +9 -1
- package/src/language-server/errors/__tests__/NoMissingClientDirectives.test.ts +10 -5
- package/src/language-server/errors/logger.ts +1 -1
- package/src/language-server/errors/validation.ts +20 -23
- package/src/language-server/fileSet.ts +10 -12
- package/src/language-server/format.ts +1 -1
- package/src/language-server/graphqlTypes.ts +13020 -3455
- package/src/language-server/index.ts +0 -1
- package/src/language-server/languageProvider.ts +29 -32
- package/src/language-server/loadingHandler.ts +10 -27
- package/src/language-server/project/base.ts +32 -25
- package/src/language-server/project/client.ts +80 -114
- package/src/language-server/project/defaultClientSchema.ts +29 -4
- package/src/language-server/providers/schema/__tests__/file.ts +60 -19
- package/src/language-server/providers/schema/base.ts +2 -2
- package/src/language-server/providers/schema/endpoint.ts +15 -34
- package/src/language-server/providers/schema/engine.ts +25 -18
- package/src/language-server/providers/schema/file.ts +41 -32
- package/src/language-server/providers/schema/index.ts +5 -21
- package/src/language-server/server.ts +72 -50
- package/src/language-server/typings/graphql.d.ts +3 -3
- package/src/language-server/utilities/__tests__/graphql.test.ts +42 -54
- package/src/language-server/utilities/debouncer.ts +1 -1
- package/src/language-server/utilities/debug.ts +6 -5
- package/src/language-server/utilities/graphql.ts +17 -16
- package/src/language-server/utilities/source.ts +16 -16
- package/src/language-server/utilities/uri.ts +2 -2
- package/src/language-server/workspace.ts +29 -37
- package/src/languageServerClient.ts +4 -4
- package/src/messages.ts +38 -47
- package/src/tools/__tests__/buildServiceDefinition.test.ts +2 -2
- package/src/tools/buildServiceDefinition.ts +11 -11
- package/src/tools/schema/resolveObject.ts +1 -1
- package/src/tools/utilities/predicates.ts +1 -1
- package/src/utils.ts +7 -6
- package/syntaxes/graphql.dart.json +2 -4
- package/syntaxes/graphql.ex.json +1 -4
- package/tsconfig.build.json +8 -1
- package/tsconfig.json +5 -3
- package/src/env/fetch/fetch.ts +0 -32
- package/src/env/fetch/global.ts +0 -30
- package/src/env/fetch/index.d.ts +0 -2
- package/src/env/fetch/index.ts +0 -2
- package/src/env/fetch/url.ts +0 -9
- package/src/env/polyfills/array.ts +0 -17
- package/src/env/polyfills/index.ts +0 -2
- package/src/env/polyfills/object.ts +0 -7
- package/src/language-server/engine/GraphQLDataSource.ts +0 -124
- package/src/language-server/project/service.ts +0 -48
- package/src/language-server/typings/codemirror.d.ts +0 -4
|
@@ -7,7 +7,6 @@ export { LoadingHandler } from "./loadingHandler";
|
|
|
7
7
|
// projects
|
|
8
8
|
export { GraphQLProject } from "./project/base";
|
|
9
9
|
export { isClientProject, GraphQLClientProject } from "./project/client";
|
|
10
|
-
export { isServiceProject, GraphQLServiceProject } from "./project/service";
|
|
11
10
|
|
|
12
11
|
// GraphQLSchemaProvider
|
|
13
12
|
export {
|
|
@@ -16,15 +16,12 @@ import {
|
|
|
16
16
|
CodeActionKind,
|
|
17
17
|
MarkupKind,
|
|
18
18
|
CompletionItemKind,
|
|
19
|
-
} from "vscode-languageserver";
|
|
19
|
+
} from "vscode-languageserver/node";
|
|
20
20
|
|
|
21
21
|
// should eventually be moved into this package, since we're overriding a lot of the existing behavior here
|
|
22
|
-
import { getAutocompleteSuggestions } from "graphql-language-service
|
|
23
|
-
import { Position as GraphQlPosition } from "graphql-language-service
|
|
24
|
-
import {
|
|
25
|
-
getTokenAtPosition,
|
|
26
|
-
getTypeInfo,
|
|
27
|
-
} from "graphql-language-service-interface/dist/getAutocompleteSuggestions";
|
|
22
|
+
import { getAutocompleteSuggestions } from "graphql-language-service";
|
|
23
|
+
import { Position as GraphQlPosition } from "graphql-language-service";
|
|
24
|
+
import { getTokenAtPosition, getTypeInfo } from "graphql-language-service";
|
|
28
25
|
import type { GraphQLWorkspace } from "./workspace";
|
|
29
26
|
import type { DocumentUri } from "./project/base";
|
|
30
27
|
|
|
@@ -65,7 +62,7 @@ import { GraphQLClientProject, isClientProject } from "./project/client";
|
|
|
65
62
|
import { isNotNullOrUndefined } from "../tools";
|
|
66
63
|
import type { CodeActionInfo } from "./errors/validation";
|
|
67
64
|
import { GraphQLDiagnostic } from "./diagnostics";
|
|
68
|
-
import type { ProjectStats } from "
|
|
65
|
+
import type { ProjectStats } from "../messages";
|
|
69
66
|
import { isInterfaceType } from "graphql";
|
|
70
67
|
|
|
71
68
|
const DirectiveLocations = Object.keys(DirectiveLocation);
|
|
@@ -93,7 +90,7 @@ function locationForASTNode(node: ASTNode): Location | null {
|
|
|
93
90
|
}
|
|
94
91
|
|
|
95
92
|
function symbolForFieldDefinition(
|
|
96
|
-
definition: FieldDefinitionNode
|
|
93
|
+
definition: FieldDefinitionNode,
|
|
97
94
|
): DocumentSymbol {
|
|
98
95
|
return {
|
|
99
96
|
name: definition.name.value,
|
|
@@ -118,7 +115,7 @@ export class GraphQLLanguageProvider {
|
|
|
118
115
|
async provideCompletionItems(
|
|
119
116
|
uri: DocumentUri,
|
|
120
117
|
position: Position,
|
|
121
|
-
_token: CancellationToken
|
|
118
|
+
_token: CancellationToken,
|
|
122
119
|
): Promise<CompletionItem[]> {
|
|
123
120
|
const project = this.workspace.projectForFile(uri);
|
|
124
121
|
if (!(project && project instanceof GraphQLClientProject)) return [];
|
|
@@ -130,11 +127,11 @@ export class GraphQLLanguageProvider {
|
|
|
130
127
|
|
|
131
128
|
const rawPositionInDocument = positionFromPositionInContainingDocument(
|
|
132
129
|
document.source,
|
|
133
|
-
position
|
|
130
|
+
position,
|
|
134
131
|
);
|
|
135
132
|
const positionInDocument = new GraphQlPosition(
|
|
136
133
|
rawPositionInDocument.line,
|
|
137
|
-
rawPositionInDocument.character
|
|
134
|
+
rawPositionInDocument.character,
|
|
138
135
|
);
|
|
139
136
|
|
|
140
137
|
const token = getTokenAtPosition(document.source.body, positionInDocument);
|
|
@@ -152,7 +149,7 @@ export class GraphQLLanguageProvider {
|
|
|
152
149
|
const suggestions = getAutocompleteSuggestions(
|
|
153
150
|
project.schema,
|
|
154
151
|
document.source.body,
|
|
155
|
-
positionInDocument
|
|
152
|
+
positionInDocument,
|
|
156
153
|
);
|
|
157
154
|
|
|
158
155
|
if (
|
|
@@ -185,7 +182,7 @@ export class GraphQLLanguageProvider {
|
|
|
185
182
|
return suggest;
|
|
186
183
|
} else {
|
|
187
184
|
const requiredArgs = suggestedField.args.filter((a) =>
|
|
188
|
-
isNonNullType(a.type)
|
|
185
|
+
isNonNullType(a.type),
|
|
189
186
|
);
|
|
190
187
|
const paramsSection =
|
|
191
188
|
requiredArgs.length > 0
|
|
@@ -239,7 +236,7 @@ export class GraphQLLanguageProvider {
|
|
|
239
236
|
|
|
240
237
|
const content = [
|
|
241
238
|
[`\`\`\`graphql`, `@${suggest.label}${argsString}`, `\`\`\``].join(
|
|
242
|
-
"\n"
|
|
239
|
+
"\n",
|
|
243
240
|
),
|
|
244
241
|
];
|
|
245
242
|
|
|
@@ -273,7 +270,7 @@ export class GraphQLLanguageProvider {
|
|
|
273
270
|
async provideHover(
|
|
274
271
|
uri: DocumentUri,
|
|
275
272
|
position: Position,
|
|
276
|
-
_token: CancellationToken
|
|
273
|
+
_token: CancellationToken,
|
|
277
274
|
): Promise<Hover | null> {
|
|
278
275
|
const project = this.workspace.projectForFile(uri);
|
|
279
276
|
if (!(project && project instanceof GraphQLClientProject)) return null;
|
|
@@ -285,14 +282,14 @@ export class GraphQLLanguageProvider {
|
|
|
285
282
|
|
|
286
283
|
const positionInDocument = positionFromPositionInContainingDocument(
|
|
287
284
|
document.source,
|
|
288
|
-
position
|
|
285
|
+
position,
|
|
289
286
|
);
|
|
290
287
|
|
|
291
288
|
const nodeAndTypeInfo = getASTNodeAndTypeInfoAtPosition(
|
|
292
289
|
document.source,
|
|
293
290
|
positionInDocument,
|
|
294
291
|
document.ast,
|
|
295
|
-
project.schema
|
|
292
|
+
project.schema,
|
|
296
293
|
);
|
|
297
294
|
|
|
298
295
|
if (nodeAndTypeInfo) {
|
|
@@ -332,7 +329,7 @@ export class GraphQLLanguageProvider {
|
|
|
332
329
|
const isResolvedLocally =
|
|
333
330
|
node.directives &&
|
|
334
331
|
node.directives.some(
|
|
335
|
-
(directive) => directive.name.value === "client"
|
|
332
|
+
(directive) => directive.name.value === "client",
|
|
336
333
|
);
|
|
337
334
|
|
|
338
335
|
const content = [
|
|
@@ -370,7 +367,7 @@ export class GraphQLLanguageProvider {
|
|
|
370
367
|
|
|
371
368
|
case Kind.NAMED_TYPE: {
|
|
372
369
|
const type = project.schema.getType(
|
|
373
|
-
node.name.value
|
|
370
|
+
node.name.value,
|
|
374
371
|
) as GraphQLNamedType | void;
|
|
375
372
|
if (!type) break;
|
|
376
373
|
|
|
@@ -436,7 +433,7 @@ export class GraphQLLanguageProvider {
|
|
|
436
433
|
async provideDefinition(
|
|
437
434
|
uri: DocumentUri,
|
|
438
435
|
position: Position,
|
|
439
|
-
_token: CancellationToken
|
|
436
|
+
_token: CancellationToken,
|
|
440
437
|
): Promise<Definition | null> {
|
|
441
438
|
const project = this.workspace.projectForFile(uri);
|
|
442
439
|
if (!(project && project instanceof GraphQLClientProject)) return null;
|
|
@@ -448,14 +445,14 @@ export class GraphQLLanguageProvider {
|
|
|
448
445
|
|
|
449
446
|
const positionInDocument = positionFromPositionInContainingDocument(
|
|
450
447
|
document.source,
|
|
451
|
-
position
|
|
448
|
+
position,
|
|
452
449
|
);
|
|
453
450
|
|
|
454
451
|
const nodeAndTypeInfo = getASTNodeAndTypeInfoAtPosition(
|
|
455
452
|
document.source,
|
|
456
453
|
positionInDocument,
|
|
457
454
|
document.ast,
|
|
458
|
-
project.schema
|
|
455
|
+
project.schema,
|
|
459
456
|
);
|
|
460
457
|
|
|
461
458
|
if (nodeAndTypeInfo) {
|
|
@@ -500,7 +497,7 @@ export class GraphQLLanguageProvider {
|
|
|
500
497
|
uri: DocumentUri,
|
|
501
498
|
position: Position,
|
|
502
499
|
_context: ReferenceContext,
|
|
503
|
-
_token: CancellationToken
|
|
500
|
+
_token: CancellationToken,
|
|
504
501
|
): Promise<Location[] | null> {
|
|
505
502
|
const project = this.workspace.projectForFile(uri);
|
|
506
503
|
if (!project) return null;
|
|
@@ -511,14 +508,14 @@ export class GraphQLLanguageProvider {
|
|
|
511
508
|
|
|
512
509
|
const positionInDocument = positionFromPositionInContainingDocument(
|
|
513
510
|
document.source,
|
|
514
|
-
position
|
|
511
|
+
position,
|
|
515
512
|
);
|
|
516
513
|
|
|
517
514
|
const nodeAndTypeInfo = getASTNodeAndTypeInfoAtPosition(
|
|
518
515
|
document.source,
|
|
519
516
|
positionInDocument,
|
|
520
517
|
document.ast,
|
|
521
|
-
project.schema
|
|
518
|
+
project.schema,
|
|
522
519
|
);
|
|
523
520
|
|
|
524
521
|
if (nodeAndTypeInfo) {
|
|
@@ -579,7 +576,7 @@ export class GraphQLLanguageProvider {
|
|
|
579
576
|
|
|
580
577
|
async provideDocumentSymbol(
|
|
581
578
|
uri: DocumentUri,
|
|
582
|
-
_token: CancellationToken
|
|
579
|
+
_token: CancellationToken,
|
|
583
580
|
): Promise<DocumentSymbol[]> {
|
|
584
581
|
const project = this.workspace.projectForFile(uri);
|
|
585
582
|
if (!project) return [];
|
|
@@ -628,7 +625,7 @@ export class GraphQLLanguageProvider {
|
|
|
628
625
|
|
|
629
626
|
async provideWorkspaceSymbol(
|
|
630
627
|
query: string,
|
|
631
|
-
_token: CancellationToken
|
|
628
|
+
_token: CancellationToken,
|
|
632
629
|
): Promise<SymbolInformation[]> {
|
|
633
630
|
const symbols: SymbolInformation[] = [];
|
|
634
631
|
for (const project of this.workspace.projects) {
|
|
@@ -650,7 +647,7 @@ export class GraphQLLanguageProvider {
|
|
|
650
647
|
|
|
651
648
|
async provideCodeLenses(
|
|
652
649
|
uri: DocumentUri,
|
|
653
|
-
_token: CancellationToken
|
|
650
|
+
_token: CancellationToken,
|
|
654
651
|
): Promise<CodeLens[]> {
|
|
655
652
|
const project = this.workspace.projectForFile(uri);
|
|
656
653
|
if (!(project && project instanceof GraphQLClientProject)) return [];
|
|
@@ -736,7 +733,7 @@ export class GraphQLLanguageProvider {
|
|
|
736
733
|
async provideCodeAction(
|
|
737
734
|
uri: DocumentUri,
|
|
738
735
|
range: Range,
|
|
739
|
-
_token: CancellationToken
|
|
736
|
+
_token: CancellationToken,
|
|
740
737
|
): Promise<CodeAction[]> {
|
|
741
738
|
function isPositionLessThanOrEqual(a: Position, b: Position) {
|
|
742
739
|
return a.line !== b.line ? a.line < b.line : a.character <= b.character;
|
|
@@ -782,12 +779,12 @@ export class GraphQLLanguageProvider {
|
|
|
782
779
|
const { extensions } = error;
|
|
783
780
|
if (!extensions || !extensions.codeAction) continue;
|
|
784
781
|
|
|
785
|
-
const { message, edits }: CodeActionInfo = extensions.codeAction;
|
|
782
|
+
const { message, edits }: CodeActionInfo = extensions.codeAction as any;
|
|
786
783
|
|
|
787
784
|
const codeAction = CodeAction.create(
|
|
788
785
|
message,
|
|
789
786
|
{ changes: { [uri]: edits } },
|
|
790
|
-
CodeActionKind.QuickFix
|
|
787
|
+
CodeActionKind.QuickFix,
|
|
791
788
|
);
|
|
792
789
|
|
|
793
790
|
result.push(codeAction);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LanguageServerNotifications as Notifications } from "../messages";
|
|
2
|
+
import { Connection, NotificationType } from "vscode-languageserver/node";
|
|
2
3
|
|
|
3
4
|
// XXX I think we want to combine this into an interface
|
|
4
5
|
// with the errors tooling as well
|
|
@@ -10,27 +11,18 @@ export interface LoadingHandler {
|
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
export class LanguageServerLoadingHandler implements LoadingHandler {
|
|
13
|
-
constructor(private connection:
|
|
14
|
+
constructor(private connection: Connection) {}
|
|
14
15
|
private latestLoadingToken = 0;
|
|
15
16
|
async handle<T>(message: string, value: Promise<T>): Promise<T> {
|
|
16
17
|
const token = this.latestLoadingToken;
|
|
17
18
|
this.latestLoadingToken += 1;
|
|
18
|
-
this.connection.sendNotification(
|
|
19
|
-
new NotificationType<any, void>("apollographql/loading"),
|
|
20
|
-
{ message, token }
|
|
21
|
-
);
|
|
19
|
+
this.connection.sendNotification(Notifications.Loading, { message, token });
|
|
22
20
|
try {
|
|
23
21
|
const ret = await value;
|
|
24
|
-
this.connection.sendNotification(
|
|
25
|
-
new NotificationType<any, void>("apollographql/loadingComplete"),
|
|
26
|
-
token
|
|
27
|
-
);
|
|
22
|
+
this.connection.sendNotification(Notifications.LoadingComplete, token);
|
|
28
23
|
return ret;
|
|
29
24
|
} catch (e) {
|
|
30
|
-
this.connection.sendNotification(
|
|
31
|
-
new NotificationType<any, void>("apollographql/loadingComplete"),
|
|
32
|
-
token
|
|
33
|
-
);
|
|
25
|
+
this.connection.sendNotification(Notifications.LoadingComplete, token);
|
|
34
26
|
this.showError(`Error in "${message}": ${e}`);
|
|
35
27
|
throw e;
|
|
36
28
|
}
|
|
@@ -38,23 +30,14 @@ export class LanguageServerLoadingHandler implements LoadingHandler {
|
|
|
38
30
|
handleSync<T>(message: string, value: () => T): T {
|
|
39
31
|
const token = this.latestLoadingToken;
|
|
40
32
|
this.latestLoadingToken += 1;
|
|
41
|
-
this.connection.sendNotification(
|
|
42
|
-
new NotificationType<any, void>("apollographql/loading"),
|
|
43
|
-
{ message, token }
|
|
44
|
-
);
|
|
33
|
+
this.connection.sendNotification(Notifications.Loading, { message, token });
|
|
45
34
|
try {
|
|
46
35
|
const ret = value();
|
|
47
|
-
this.connection.sendNotification(
|
|
48
|
-
new NotificationType<any, void>("apollographql/loadingComplete"),
|
|
49
|
-
token
|
|
50
|
-
);
|
|
36
|
+
this.connection.sendNotification(Notifications.LoadingComplete, token);
|
|
51
37
|
return ret;
|
|
52
38
|
} catch (e) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
token
|
|
56
|
-
);
|
|
57
|
-
this.showError(`Error in "${message}": ${e}`);
|
|
39
|
+
Notifications.LoadingComplete,
|
|
40
|
+
this.showError(`Error in "${message}": ${e}`);
|
|
58
41
|
throw e;
|
|
59
42
|
}
|
|
60
43
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path, { extname } from "path";
|
|
2
2
|
import { lstatSync, readFileSync } from "fs";
|
|
3
|
-
import URI from "vscode-uri";
|
|
3
|
+
import { URI } from "vscode-uri";
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
6
|
TypeSystemDefinitionNode,
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
NotificationHandler,
|
|
18
18
|
PublishDiagnosticsParams,
|
|
19
19
|
Position,
|
|
20
|
-
} from "vscode-languageserver";
|
|
20
|
+
} from "vscode-languageserver/node";
|
|
21
21
|
|
|
22
22
|
import { GraphQLDocument, extractGraphQLDocuments } from "../document";
|
|
23
23
|
|
|
@@ -28,9 +28,8 @@ import {
|
|
|
28
28
|
ClientConfig,
|
|
29
29
|
isClientConfig,
|
|
30
30
|
isLocalServiceConfig,
|
|
31
|
-
isServiceConfig,
|
|
32
31
|
keyEnvVar,
|
|
33
|
-
|
|
32
|
+
RoverConfig,
|
|
34
33
|
} from "../config";
|
|
35
34
|
import {
|
|
36
35
|
schemaProviderFromConfig,
|
|
@@ -38,7 +37,7 @@ import {
|
|
|
38
37
|
SchemaResolveConfig,
|
|
39
38
|
} from "../providers/schema";
|
|
40
39
|
import { ApolloEngineClient, ClientIdentity } from "../engine";
|
|
41
|
-
import type { ProjectStats } from "
|
|
40
|
+
import type { ProjectStats } from "../../messages";
|
|
42
41
|
|
|
43
42
|
export type DocumentUri = string;
|
|
44
43
|
|
|
@@ -60,8 +59,8 @@ const fileAssociations: { [extension: string]: string } = {
|
|
|
60
59
|
};
|
|
61
60
|
|
|
62
61
|
interface GraphQLProjectConfig {
|
|
63
|
-
clientIdentity
|
|
64
|
-
config: ClientConfig |
|
|
62
|
+
clientIdentity: ClientIdentity;
|
|
63
|
+
config: ClientConfig | RoverConfig;
|
|
65
64
|
configFolderURI: URI;
|
|
66
65
|
loadingHandler: LoadingHandler;
|
|
67
66
|
}
|
|
@@ -98,12 +97,21 @@ export abstract class GraphQLProject implements GraphQLSchemaProvider {
|
|
|
98
97
|
// if a config doesn't have a uri associated, we can assume the `rootURI` is the project's root.
|
|
99
98
|
this.rootURI = config.configDirURI || configFolderURI;
|
|
100
99
|
|
|
101
|
-
const { includes, excludes } = config
|
|
100
|
+
const { includes = [], excludes = [] } = isClientConfig(config)
|
|
102
101
|
? config.client
|
|
103
|
-
:
|
|
102
|
+
: {
|
|
103
|
+
/** TODO */
|
|
104
|
+
};
|
|
104
105
|
const fileSet = new FileSet({
|
|
105
106
|
rootURI: this.rootURI,
|
|
106
|
-
includes: [
|
|
107
|
+
includes: [
|
|
108
|
+
...includes,
|
|
109
|
+
".env",
|
|
110
|
+
"apollo.config.js",
|
|
111
|
+
"apollo.config.cjs",
|
|
112
|
+
"apollo.config.mjs",
|
|
113
|
+
"apollo.config.ts",
|
|
114
|
+
],
|
|
107
115
|
// We do not want to include the local schema file in our list of documents
|
|
108
116
|
excludes: [...excludes, ...this.getRelativeLocalSchemaFilePaths()],
|
|
109
117
|
configURI: config.configURI,
|
|
@@ -116,7 +124,7 @@ export abstract class GraphQLProject implements GraphQLSchemaProvider {
|
|
|
116
124
|
this.engineClient = new ApolloEngineClient(
|
|
117
125
|
engine.apiKey!,
|
|
118
126
|
engine.endpoint,
|
|
119
|
-
clientIdentity
|
|
127
|
+
clientIdentity,
|
|
120
128
|
);
|
|
121
129
|
}
|
|
122
130
|
|
|
@@ -130,7 +138,7 @@ export abstract class GraphQLProject implements GraphQLSchemaProvider {
|
|
|
130
138
|
.catch((error) => {
|
|
131
139
|
console.error(error);
|
|
132
140
|
this.loadingHandler.showError(
|
|
133
|
-
`Error initializing Apollo GraphQL project "${this.displayName}": ${error}
|
|
141
|
+
`Error initializing Apollo GraphQL project "${this.displayName}": ${error}`,
|
|
134
142
|
);
|
|
135
143
|
});
|
|
136
144
|
}
|
|
@@ -202,7 +210,7 @@ export abstract class GraphQLProject implements GraphQLSchemaProvider {
|
|
|
202
210
|
|
|
203
211
|
this.fileDidChange(uri);
|
|
204
212
|
}
|
|
205
|
-
})()
|
|
213
|
+
})(),
|
|
206
214
|
);
|
|
207
215
|
}
|
|
208
216
|
|
|
@@ -231,7 +239,7 @@ export abstract class GraphQLProject implements GraphQLSchemaProvider {
|
|
|
231
239
|
documentDidChange(document: TextDocument) {
|
|
232
240
|
const documents = extractGraphQLDocuments(
|
|
233
241
|
document,
|
|
234
|
-
this.config.client && this.config.client.tagName
|
|
242
|
+
this.config.client && this.config.client.tagName,
|
|
235
243
|
);
|
|
236
244
|
if (documents) {
|
|
237
245
|
this.documentsByFile.set(document.uri, documents);
|
|
@@ -258,7 +266,7 @@ export abstract class GraphQLProject implements GraphQLSchemaProvider {
|
|
|
258
266
|
const conflictingFilePath =
|
|
259
267
|
filePathForOperationName[operationName];
|
|
260
268
|
throw new Error(
|
|
261
|
-
`️️There are multiple definitions for the \`${definition.name.value}\` operation. Please fix all naming conflicts before continuing.\nConflicting definitions found at ${filePath} and ${conflictingFilePath}
|
|
269
|
+
`️️There are multiple definitions for the \`${definition.name.value}\` operation. Please fix all naming conflicts before continuing.\nConflicting definitions found at ${filePath} and ${conflictingFilePath}.`,
|
|
262
270
|
);
|
|
263
271
|
}
|
|
264
272
|
filePathForOperationName[operationName] = filePath;
|
|
@@ -298,13 +306,12 @@ export abstract class GraphQLProject implements GraphQLSchemaProvider {
|
|
|
298
306
|
}
|
|
299
307
|
|
|
300
308
|
private getRelativeLocalSchemaFilePaths(): string[] {
|
|
301
|
-
const serviceConfig =
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
: undefined;
|
|
309
|
+
const serviceConfig =
|
|
310
|
+
isClientConfig(this.config) &&
|
|
311
|
+
typeof this.config.client.service === "object" &&
|
|
312
|
+
isLocalServiceConfig(this.config.client.service)
|
|
313
|
+
? this.config.client.service
|
|
314
|
+
: undefined;
|
|
308
315
|
const localSchemaFile = serviceConfig?.localSchemaFile;
|
|
309
316
|
return (
|
|
310
317
|
localSchemaFile === undefined
|
|
@@ -313,7 +320,7 @@ export abstract class GraphQLProject implements GraphQLSchemaProvider {
|
|
|
313
320
|
? localSchemaFile
|
|
314
321
|
: [localSchemaFile]
|
|
315
322
|
).map((filePath) =>
|
|
316
|
-
path.relative(this.rootURI.fsPath, path.join(process.cwd(), filePath))
|
|
323
|
+
path.relative(this.rootURI.fsPath, path.join(process.cwd(), filePath)),
|
|
317
324
|
);
|
|
318
325
|
}
|
|
319
326
|
|
|
@@ -333,13 +340,13 @@ export abstract class GraphQLProject implements GraphQLSchemaProvider {
|
|
|
333
340
|
|
|
334
341
|
documentAt(
|
|
335
342
|
uri: DocumentUri,
|
|
336
|
-
position: Position
|
|
343
|
+
position: Position,
|
|
337
344
|
): GraphQLDocument | undefined {
|
|
338
345
|
const queryDocuments = this.documentsByFile.get(uri);
|
|
339
346
|
if (!queryDocuments) return undefined;
|
|
340
347
|
|
|
341
348
|
return queryDocuments.find((document) =>
|
|
342
|
-
document.containsPosition(position)
|
|
349
|
+
document.containsPosition(position),
|
|
343
350
|
);
|
|
344
351
|
}
|
|
345
352
|
|