vscode-apollo 2.0.0 → 2.1.0

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.
Files changed (39) hide show
  1. package/.circleci/config.yml +1 -1
  2. package/.vscode/launch.json +4 -1
  3. package/CHANGELOG.md +33 -0
  4. package/package.json +9 -3
  5. package/renovate.json +2 -1
  6. package/sampleWorkspace/localSchema/src/test.js +3 -0
  7. package/sampleWorkspace/rover/apollo.config.js +3 -0
  8. package/sampleWorkspace/rover/src/test.graphql +14 -0
  9. package/sampleWorkspace/rover/src/test.js +30 -0
  10. package/sampleWorkspace/sampleWorkspace.code-workspace +25 -19
  11. package/src/language-server/__tests__/document.test.ts +161 -3
  12. package/src/language-server/__tests__/fixtures/TypeScript.tmLanguage.json +5749 -0
  13. package/src/language-server/__tests__/fixtures/documents/commentWithTemplate.ts +41 -0
  14. package/src/language-server/__tests__/fixtures/documents/commentWithTemplate.ts.snap +185 -0
  15. package/src/language-server/__tests__/fixtures/documents/functionCall.ts +93 -0
  16. package/src/language-server/__tests__/fixtures/documents/functionCall.ts.snap +431 -0
  17. package/src/language-server/__tests__/fixtures/documents/taggedTemplate.ts +80 -0
  18. package/src/language-server/__tests__/fixtures/documents/taggedTemplate.ts.snap +353 -0
  19. package/src/language-server/__tests__/fixtures/documents/templateWithComment.ts +38 -0
  20. package/src/language-server/__tests__/fixtures/documents/templateWithComment.ts.snap +123 -0
  21. package/src/language-server/config/__tests__/loadConfig.ts +43 -10
  22. package/src/language-server/config/config.ts +26 -1
  23. package/src/language-server/config/loadConfig.ts +7 -1
  24. package/src/language-server/config/loadTsConfig.ts +70 -0
  25. package/src/language-server/config/which.d.ts +19 -0
  26. package/src/language-server/document.ts +86 -53
  27. package/src/language-server/fileSet.ts +7 -0
  28. package/src/language-server/project/base.ts +58 -316
  29. package/src/language-server/project/client.ts +730 -7
  30. package/src/language-server/project/internal.ts +349 -0
  31. package/src/language-server/project/rover/DocumentSynchronization.ts +308 -0
  32. package/src/language-server/project/rover/__tests__/DocumentSynchronization.test.ts +302 -0
  33. package/src/language-server/project/rover/project.ts +276 -0
  34. package/src/language-server/server.ts +129 -62
  35. package/src/language-server/utilities/__tests__/source.test.ts +162 -0
  36. package/src/language-server/utilities/source.ts +38 -3
  37. package/src/language-server/workspace.ts +34 -9
  38. package/syntaxes/graphql.js.json +18 -21
  39. package/src/language-server/languageProvider.ts +0 -795
@@ -6,7 +6,7 @@ orbs:
6
6
  executors:
7
7
  node:
8
8
  docker:
9
- - image: cimg/node:22.5.1
9
+ - image: cimg/node:22.7.0
10
10
  working_directory: ~/vscode-graphql
11
11
 
12
12
  commands:
@@ -14,7 +14,10 @@
14
14
  "${workspaceFolder}/sampleWorkspace/sampleWorkspace.code-workspace"
15
15
  ],
16
16
  "sourceMaps": true,
17
- "env": { "APOLLO_ENGINE_ENDPOINT": "http://localhost:7096/apollo" },
17
+ "env": {
18
+ "APOLLO_ENGINE_ENDPOINT": "http://localhost:7096/apollo",
19
+ "APOLLO_FEATURE_FLAGS": "rover"
20
+ },
18
21
  "outFiles": ["${workspaceRoot}/lib/**/*.js"]
19
22
  },
20
23
  {
package/CHANGELOG.md CHANGED
@@ -1,5 +1,38 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 2.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#179](https://github.com/apollographql/vscode-graphql/pull/179) [`b4687eb`](https://github.com/apollographql/vscode-graphql/commit/b4687eb52458c7fd80f447c8060922e23ef77590) Thanks [@phryneas](https://github.com/phryneas)! - Improve detection of GraphQL inside of JavaScript/TypeScript files.
8
+ Add support for `/** GraphQL */` annotations before a template string.
9
+
10
+ ### Patch Changes
11
+
12
+ - [#173](https://github.com/apollographql/vscode-graphql/pull/173) [`415ff4a1`](https://github.com/apollographql/vscode-graphql/commit/415ff4a1bb85adba6fc2da190510c8a4ba3a74d1) Thanks [@phryneas](https://github.com/phryneas)! - Fix a bug where when rapidly changing multiple files some of the changes might have gotten lost.
13
+
14
+ - [#176](https://github.com/apollographql/vscode-graphql/pull/176) [`cbc1c638`](https://github.com/apollographql/vscode-graphql/commit/cbc1c6384a1275bfc9fddbb0ff2bdfddaa6464f9) Thanks [@phryneas](https://github.com/phryneas)! - Fixed a bug where annotations might have mapped to the wrong position on the first line of an embedded document.
15
+
16
+ - [#173](https://github.com/apollographql/vscode-graphql/pull/173) [`415ff4a1`](https://github.com/apollographql/vscode-graphql/commit/415ff4a1bb85adba6fc2da190510c8a4ba3a74d1) Thanks [@phryneas](https://github.com/phryneas)! - Fixed a bug where hints on the 0-th line of an embedded GraphQL document were offset incorrectly.
17
+
18
+ E.g. in
19
+
20
+ ```js
21
+ const veryLongVariableName = gql`
22
+ type Foo {
23
+ baaaaaar: String
24
+ }
25
+ `;
26
+ ```
27
+
28
+ the hover on `String` would only appear when hovering characters left of it.
29
+
30
+ ## 2.0.1
31
+
32
+ ### Patch Changes
33
+
34
+ - [#171](https://github.com/apollographql/vscode-graphql/pull/171) [`37a2b292`](https://github.com/apollographql/vscode-graphql/commit/37a2b292c0de22ee76645fc2dcde03b8f4843051) Thanks [@phryneas](https://github.com/phryneas)! - Also try parsing `.ts` files as CommonJS, not only ESM.
35
+
3
36
  ## 2.0.0
4
37
 
5
38
  ### Major Changes
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "vscode-apollo",
3
3
  "displayName": "Apollo GraphQL",
4
4
  "description": "Rich editor support for GraphQL client and server development that seamlessly integrates with the Apollo platform",
5
- "version": "2.0.0",
5
+ "version": "2.1.0",
6
6
  "referenceID": "87197759-7617-40d0-b32e-46d378e907c7",
7
7
  "author": "Apollo GraphQL <opensource@apollographql.com>",
8
8
  "license": "MIT",
@@ -29,6 +29,7 @@
29
29
  "format": "prettier --write .",
30
30
  "test": "NODE_OPTIONS=--experimental-vm-modules jest",
31
31
  "test:extension": "node src/__e2e__/runTests.js",
32
+ "test:textmate": "npx vscode-tmgrammar-snap -s source.ts -g src/language-server/__tests__/fixtures/TypeScript.tmLanguage.json src/language-server/__tests__/fixtures/documents/*.ts",
32
33
  "codegen": "graphql-codegen",
33
34
  "vscode:prepublish": "npm run build:production"
34
35
  },
@@ -38,17 +39,19 @@
38
39
  "dependencies": {
39
40
  "@apollo/client": "3.11.4",
40
41
  "@apollo/subgraph": "2.8.4",
41
- "@graphql-tools/schema": "10.0.4",
42
+ "@graphql-tools/schema": "10.0.5",
42
43
  "@wry/context": "0.7.4",
43
44
  "@wry/equality": "0.5.7",
44
45
  "cosmiconfig": "9.0.0",
45
46
  "dotenv": "16.4.5",
47
+ "fractional-indexing": "2.1.0",
46
48
  "glob": "11.0.0",
47
49
  "graphql": "16.9.0",
48
50
  "graphql-language-service": "5.2.2",
49
51
  "graphql-tag": "2.12.6",
50
52
  "lodash.debounce": "4.0.8",
51
53
  "lodash.merge": "4.6.2",
54
+ "lodash.throttle": "4.1.1",
52
55
  "lz-string": "1.5.0",
53
56
  "minimatch": "10.0.1",
54
57
  "moment": "2.30.1",
@@ -56,6 +59,7 @@
56
59
  "vscode-languageserver": "9.0.1",
57
60
  "vscode-languageserver-textdocument": "1.0.12",
58
61
  "vscode-uri": "3.0.8",
62
+ "which": "4.0.0",
59
63
  "zod": "3.23.8",
60
64
  "zod-validation-error": "3.3.1"
61
65
  },
@@ -67,6 +71,7 @@
67
71
  "@types/jest": "29.5.12",
68
72
  "@types/lodash.debounce": "4.0.9",
69
73
  "@types/lodash.merge": "4.6.9",
74
+ "@types/lodash.throttle": "^4.1.9",
70
75
  "@types/node": "20.14.10",
71
76
  "@types/vscode": "1.90.0",
72
77
  "@typescript-eslint/eslint-plugin": "6.9.1",
@@ -87,7 +92,8 @@
87
92
  "rimraf": "6.0.1",
88
93
  "ts-jest": "29.1.2",
89
94
  "ts-node": "^10.9.2",
90
- "typescript": "^5.5.3"
95
+ "typescript": "^5.5.3",
96
+ "vscode-tmgrammar-test": "^0.1.3"
91
97
  },
92
98
  "publisher": "apollographql",
93
99
  "categories": [
package/renovate.json CHANGED
@@ -25,6 +25,7 @@
25
25
  "@types/vscode",
26
26
  "@typescript-eslint/eslint-plugin",
27
27
  "@typescript-eslint/parser",
28
- "eslint"
28
+ "eslint",
29
+ "fractional-indexing"
29
30
  ]
30
31
  }
@@ -6,3 +6,6 @@ gql`
6
6
  }
7
7
  }
8
8
  `;
9
+
10
+ // prettier-ignore
11
+ const verylonglala = gql`type Foo { baaaaaar: String }`
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ rover: {},
3
+ };
@@ -0,0 +1,14 @@
1
+ """
2
+ The query type, represents all of the entry points into our object graph
3
+ """
4
+ type Query {
5
+ me: User!
6
+ }
7
+
8
+ """
9
+ Test
10
+ """
11
+ type User {
12
+ id: ID!
13
+ name: String!
14
+ }
@@ -0,0 +1,30 @@
1
+ import gql from "graphql-tag";
2
+
3
+ sdfsdfs;
4
+ gql`
5
+ """
6
+ The query type, represents all of the entry points into our object graph
7
+ """
8
+ type Query {
9
+ me: User!
10
+ }
11
+
12
+ """
13
+ Test
14
+ """
15
+ type User {
16
+ id: ID!
17
+ name: String!
18
+ }
19
+ `;
20
+
21
+ console.log("foobar!");
22
+
23
+ gql`
24
+ type User {
25
+ lastName: String!
26
+ }
27
+ `;
28
+
29
+ // prettier-ignore
30
+ const verylonglala = gql`type Foo { baaaaaar: String }`
@@ -1,20 +1,26 @@
1
1
  {
2
- "folders": [
3
- {
4
- "path": "localSchema"
5
- },
6
- {
7
- "path": "clientSchema"
8
- },
9
- {
10
- "path": "spotifyGraph"
11
- },
12
- {
13
- "path": "httpSchema"
14
- },
15
- {
16
- "path": "localSchemaArray"
17
- }
18
- ],
19
- "settings": {}
20
- }
2
+ "folders": [
3
+ {
4
+ "path": "localSchema"
5
+ },
6
+ {
7
+ "path": "clientSchema"
8
+ },
9
+ {
10
+ "path": "spotifyGraph"
11
+ },
12
+ {
13
+ "path": "httpSchema"
14
+ },
15
+ {
16
+ "path": "localSchemaArray"
17
+ },
18
+ {
19
+ "path": "rover"
20
+ },
21
+ {
22
+ "path": "../src/language-server/__tests__/fixtures/documents"
23
+ }
24
+ ],
25
+ "settings": {}
26
+ }
@@ -1,5 +1,8 @@
1
- import { extractGraphQLDocuments } from "../document";
1
+ import { readFileSync } from "fs";
2
+ import { extractGraphQLDocuments, GraphQLDocument } from "../document";
2
3
  import { TextDocument, Position } from "vscode-languageserver";
4
+ import { join } from "path";
5
+ import { DocumentNode, OperationDefinitionNode } from "graphql";
3
6
 
4
7
  describe("extractGraphQLDocuments", () => {
5
8
  describe("extracting documents from JavaScript template literals", () => {
@@ -38,6 +41,18 @@ describe("extractGraphQLDocuments", () => {
38
41
  expect(documents?.length).toEqual(1);
39
42
  expect(documents?.[0].syntaxErrors.length).toBe(0);
40
43
  expect(documents?.[0].ast?.definitions.length).toBe(1);
44
+ expect(replaceWhitespaceWithDots(documents![0].source.body))
45
+ .toMatchInlineSnapshot(`
46
+ "
47
+ ········{
48
+ ··········hero·{
49
+ ············...Hero_character
50
+ ··········}
51
+ ········}
52
+
53
+ ·············································
54
+ ······"
55
+ `);
41
56
  });
42
57
 
43
58
  it("works with multiple placeholders in a document", () => {
@@ -65,6 +80,26 @@ describe("extractGraphQLDocuments", () => {
65
80
  expect(documents?.length).toEqual(1);
66
81
  expect(documents?.[0].syntaxErrors.length).toBe(0);
67
82
  expect(documents?.[0].ast?.definitions.length).toBe(2);
83
+ expect(replaceWhitespaceWithDots(documents![0].source.body))
84
+ .toMatchInlineSnapshot(`
85
+ "
86
+ ········{
87
+ ··········hero·{
88
+ ············...Hero_character
89
+ ··········}
90
+ ········}
91
+
92
+ ··································
93
+
94
+ ········{
95
+ ··········reviews(episode:·NEWHOPE)·{
96
+ ············...ReviewList_reviews
97
+ ··········}
98
+ ········}
99
+
100
+ ······································
101
+ ······"
102
+ `);
68
103
  });
69
104
 
70
105
  it("works with a custom tagname", () => {
@@ -90,8 +125,28 @@ describe("extractGraphQLDocuments", () => {
90
125
  const documents = extractGraphQLDocuments(textDocument, "gqltag");
91
126
 
92
127
  expect(documents?.length).toEqual(1);
93
- expect(documents?.[0].syntaxErrors.length).toBe(0);
94
- expect(documents?.[0].ast?.definitions.length).toBe(2);
128
+ expect(documents![0].syntaxErrors.length).toBe(0);
129
+ expect(documents![0].ast?.definitions.length).toBe(2);
130
+ expect(replaceWhitespaceWithDots(documents![0].source.body))
131
+ .toMatchInlineSnapshot(`
132
+ "
133
+ ········{
134
+ ··········hero·{
135
+ ············...Hero_character
136
+ ··········}
137
+ ········}
138
+
139
+ ··································
140
+
141
+ ········{
142
+ ··········reviews(episode:·NEWHOPE)·{
143
+ ············...ReviewList_reviews
144
+ ··········}
145
+ ········}
146
+
147
+ ······································
148
+ ······"
149
+ `);
95
150
  });
96
151
 
97
152
  it("works with parens", () => {
@@ -119,6 +174,101 @@ describe("extractGraphQLDocuments", () => {
119
174
  expect(documents?.length).toEqual(1);
120
175
  expect(documents?.[0].syntaxErrors.length).toBe(0);
121
176
  expect(documents?.[0].ast?.definitions.length).toBe(2);
177
+ expect(replaceWhitespaceWithDots(documents![0].source.body))
178
+ .toMatchInlineSnapshot(`
179
+ "
180
+ ········{
181
+ ··········hero·{
182
+ ············...Hero_character
183
+ ··········}
184
+ ········}
185
+
186
+ ··································
187
+
188
+ ········{
189
+ ··········reviews(episode:·NEWHOPE)·{
190
+ ············...ReviewList_reviews
191
+ ··········}
192
+ ········}
193
+
194
+ ····································
195
+ ····"
196
+ `);
197
+ });
198
+
199
+ test("fixtures", () => {
200
+ function loadFixture(name: string) {
201
+ const path = join(__dirname, "fixtures", "documents", name);
202
+ const body = readFileSync(path, "utf8");
203
+
204
+ return extractGraphQLDocuments(
205
+ TextDocument.create(`file://${path}.js`, "javascript", 1, body),
206
+ )!;
207
+ }
208
+ function documentName(document: GraphQLDocument) {
209
+ expect(document.syntaxErrors.length).toBe(0);
210
+ let first = document.ast?.definitions[0];
211
+ expect(first).toBeDefined();
212
+ expect(first!.kind).toBe("OperationDefinition");
213
+ first = first as OperationDefinitionNode;
214
+ return (first.name && first.name.value) || "Unnamed";
215
+ }
216
+
217
+ expect(loadFixture("commentWithTemplate.ts").map(documentName))
218
+ .toMatchInlineSnapshot(`
219
+ Array [
220
+ "Q1",
221
+ "Q2",
222
+ "Q3",
223
+ "Q4",
224
+ "Q6",
225
+ "Q8",
226
+ "Q9",
227
+ "Q10",
228
+ ]
229
+ `);
230
+ expect(loadFixture("functionCall.ts").map(documentName))
231
+ .toMatchInlineSnapshot(`
232
+ Array [
233
+ "Q2",
234
+ "Q3",
235
+ "Q4",
236
+ "Q5",
237
+ "Q6",
238
+ "Q7",
239
+ "Q9",
240
+ "Q10",
241
+ "Q11",
242
+ ]
243
+ `);
244
+ expect(loadFixture("taggedTemplate.ts").map(documentName))
245
+ .toMatchInlineSnapshot(`
246
+ Array [
247
+ "Foo",
248
+ "Q1",
249
+ "Q2",
250
+ "Q3",
251
+ "Q4",
252
+ "Q5",
253
+ "Q6",
254
+ "Q7",
255
+ "Q8",
256
+ "Q9",
257
+ "Q10",
258
+ "Q11",
259
+ ]
260
+ `);
261
+ expect(loadFixture("templateWithComment.ts").map(documentName))
262
+ .toMatchInlineSnapshot(`
263
+ Array [
264
+ "Q1",
265
+ "Q2",
266
+ "Q3",
267
+ "Q4",
268
+ "Q5",
269
+ "Q6",
270
+ ]
271
+ `);
122
272
  });
123
273
  });
124
274
 
@@ -185,3 +335,11 @@ describe("extractGraphQLDocuments", () => {
185
335
  });
186
336
  });
187
337
  });
338
+
339
+ /**
340
+ * When editing this file manually, prettier will remove long bouts of whitespace in template strings on save,
341
+ * which messes up inline snapshots. This function replaces spaces with dots to prevent that.
342
+ */
343
+ function replaceWhitespaceWithDots(str: string) {
344
+ return str.replace(/[ ]/g, "·");
345
+ }