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.
Files changed (109) hide show
  1. package/.circleci/config.yml +27 -18
  2. package/.git-blame-ignore-revs +2 -0
  3. package/.nvmrc +1 -1
  4. package/.vscode/launch.json +9 -4
  5. package/.vscode/tasks.json +58 -16
  6. package/.vscodeignore +12 -1
  7. package/CHANGELOG.md +84 -0
  8. package/CODEOWNERS +4 -0
  9. package/README.md +97 -48
  10. package/graphql.configuration.json +5 -1
  11. package/images/marketplace/apollo-wordmark.png +0 -0
  12. package/jest.config.ts +14 -4
  13. package/jest.e2e.config.js +17 -0
  14. package/package.json +67 -68
  15. package/renovate.json +7 -0
  16. package/sampleWorkspace/clientSchema/apollo.config.cjs +10 -0
  17. package/sampleWorkspace/clientSchema/src/clientSchema.js +16 -0
  18. package/sampleWorkspace/clientSchema/src/test.js +18 -0
  19. package/sampleWorkspace/fixtures/starwarsSchema.graphql +299 -0
  20. package/sampleWorkspace/httpSchema/apollo.config.ts +8 -0
  21. package/sampleWorkspace/httpSchema/src/test.js +9 -0
  22. package/sampleWorkspace/localSchema/apollo.config.js +8 -0
  23. package/sampleWorkspace/localSchema/src/test.js +8 -0
  24. package/sampleWorkspace/localSchemaArray/apollo.config.js +12 -0
  25. package/sampleWorkspace/localSchemaArray/planets.graphql +20 -0
  26. package/sampleWorkspace/localSchemaArray/src/test.js +12 -0
  27. package/sampleWorkspace/sampleWorkspace.code-workspace +20 -0
  28. package/sampleWorkspace/spotifyGraph/apollo.config.mjs +5 -0
  29. package/sampleWorkspace/spotifyGraph/src/test.js +11 -0
  30. package/src/__e2e__/mockServer.js +117 -0
  31. package/src/__e2e__/mocks.js +13094 -0
  32. package/src/__e2e__/run.js +23 -0
  33. package/src/__e2e__/runTests.js +44 -0
  34. package/src/__e2e__/setup.js +1 -0
  35. package/src/__e2e__/vscode-environment.js +16 -0
  36. package/src/__e2e__/vscode.js +1 -0
  37. package/src/build.js +57 -0
  38. package/src/env/index.ts +0 -3
  39. package/src/extension.ts +251 -225
  40. package/src/language-server/__e2e__/clientSchema.e2e.ts +147 -0
  41. package/src/language-server/__e2e__/httpSchema.e2e.ts +21 -0
  42. package/src/language-server/__e2e__/localSchema.e2e.ts +25 -0
  43. package/src/language-server/__e2e__/localSchemaArray.e2e.ts +31 -0
  44. package/src/language-server/__e2e__/studioGraph.e2e.ts +65 -0
  45. package/src/language-server/__e2e__/utils.ts +151 -0
  46. package/src/language-server/__tests__/diagnostics.test.ts +8 -8
  47. package/src/language-server/__tests__/fileSet.test.ts +1 -1
  48. package/src/language-server/__tests__/fixtures/starwarsSchema.ts +2 -2
  49. package/src/language-server/config/__tests__/config.ts +22 -96
  50. package/src/language-server/config/__tests__/loadConfig.ts +120 -220
  51. package/src/language-server/config/__tests__/utils.ts +22 -29
  52. package/src/language-server/config/config.ts +221 -156
  53. package/src/language-server/config/loadConfig.ts +32 -153
  54. package/src/language-server/config/loadTsConfig.ts +70 -0
  55. package/src/language-server/config/utils.ts +5 -16
  56. package/src/language-server/diagnostics.ts +17 -8
  57. package/src/language-server/document.ts +16 -16
  58. package/src/language-server/engine/index.ts +57 -39
  59. package/src/language-server/engine/operations/frontendUrlRoot.ts +9 -1
  60. package/src/language-server/engine/operations/schemaTagsAndFieldStats.ts +9 -1
  61. package/src/language-server/errors/__tests__/NoMissingClientDirectives.test.ts +10 -5
  62. package/src/language-server/errors/logger.ts +1 -1
  63. package/src/language-server/errors/validation.ts +20 -23
  64. package/src/language-server/fileSet.ts +10 -12
  65. package/src/language-server/format.ts +1 -1
  66. package/src/language-server/graphqlTypes.ts +13020 -3455
  67. package/src/language-server/index.ts +0 -1
  68. package/src/language-server/languageProvider.ts +29 -32
  69. package/src/language-server/loadingHandler.ts +10 -27
  70. package/src/language-server/project/base.ts +32 -25
  71. package/src/language-server/project/client.ts +80 -114
  72. package/src/language-server/project/defaultClientSchema.ts +29 -4
  73. package/src/language-server/providers/schema/__tests__/file.ts +60 -19
  74. package/src/language-server/providers/schema/base.ts +2 -2
  75. package/src/language-server/providers/schema/endpoint.ts +15 -34
  76. package/src/language-server/providers/schema/engine.ts +25 -18
  77. package/src/language-server/providers/schema/file.ts +41 -32
  78. package/src/language-server/providers/schema/index.ts +5 -21
  79. package/src/language-server/server.ts +72 -50
  80. package/src/language-server/typings/graphql.d.ts +3 -3
  81. package/src/language-server/utilities/__tests__/graphql.test.ts +42 -54
  82. package/src/language-server/utilities/debouncer.ts +1 -1
  83. package/src/language-server/utilities/debug.ts +6 -5
  84. package/src/language-server/utilities/graphql.ts +17 -16
  85. package/src/language-server/utilities/source.ts +16 -16
  86. package/src/language-server/utilities/uri.ts +2 -2
  87. package/src/language-server/workspace.ts +29 -37
  88. package/src/languageServerClient.ts +4 -4
  89. package/src/messages.ts +38 -47
  90. package/src/tools/__tests__/buildServiceDefinition.test.ts +2 -2
  91. package/src/tools/buildServiceDefinition.ts +11 -11
  92. package/src/tools/schema/resolveObject.ts +1 -1
  93. package/src/tools/utilities/predicates.ts +1 -1
  94. package/src/utils.ts +7 -6
  95. package/syntaxes/graphql.dart.json +2 -4
  96. package/syntaxes/graphql.ex.json +1 -4
  97. package/tsconfig.build.json +8 -1
  98. package/tsconfig.json +5 -3
  99. package/src/env/fetch/fetch.ts +0 -32
  100. package/src/env/fetch/global.ts +0 -30
  101. package/src/env/fetch/index.d.ts +0 -2
  102. package/src/env/fetch/index.ts +0 -2
  103. package/src/env/fetch/url.ts +0 -9
  104. package/src/env/polyfills/array.ts +0 -17
  105. package/src/env/polyfills/index.ts +0 -2
  106. package/src/env/polyfills/object.ts +0 -7
  107. package/src/language-server/engine/GraphQLDataSource.ts +0 -124
  108. package/src/language-server/project/service.ts +0 -48
  109. package/src/language-server/typings/codemirror.d.ts +0 -4
@@ -1,19 +1,30 @@
1
- import { loadConfig } from "../";
1
+ let { loadConfig } = require("../");
2
+ let { ClientConfig, RoverConfig } = require("../config");
2
3
  import * as path from "path";
3
4
  import * as fs from "fs";
4
- import {
5
- DefaultClientConfig,
6
- DefaultServiceConfig,
7
- DefaultEngineConfig,
8
- } from "../config";
9
- import { Debug } from "../../utilities";
5
+
6
+ async function withFeatureFlags(flags: string, fn: () => void) {
7
+ const FF = process.env.APOLLO_FEATURE_FLAGS;
8
+ try {
9
+ process.env.APOLLO_FEATURE_FLAGS = flags;
10
+ jest.resetModules();
11
+ ({ loadConfig } = require("../"));
12
+ ({ ClientConfig, RoverConfig } = require("../config"));
13
+ return await fn();
14
+ } finally {
15
+ process.env.APOLLO_FEATURE_FLAGS = FF;
16
+ jest.resetModules();
17
+ ({ loadConfig } = require("../"));
18
+ ({ ClientConfig, RoverConfig } = require("../config"));
19
+ }
20
+ }
10
21
 
11
22
  const makeNestedDir = (dir: string) => {
12
23
  if (fs.existsSync(dir)) return;
13
24
 
14
25
  try {
15
26
  fs.mkdirSync(dir);
16
- } catch (err) {
27
+ } catch (err: any) {
17
28
  if (err.code == "ENOENT") {
18
29
  makeNestedDir(path.dirname(dir)); //create parent dir
19
30
  makeNestedDir(dir); //create dir
@@ -69,7 +80,7 @@ describe("loadConfig", () => {
69
80
  describe("finding files", () => {
70
81
  it("loads with client defaults from different dir", async () => {
71
82
  writeFilesToDir(dir, {
72
- "my.config.js": `
83
+ "apollo.config.js": `
73
84
  module.exports = {
74
85
  client: {
75
86
  service: 'hello'
@@ -80,77 +91,50 @@ describe("loadConfig", () => {
80
91
 
81
92
  const config = await loadConfig({
82
93
  configPath: dirPath,
83
- configFileName: "my.config.js",
84
94
  });
85
95
  expect(config?.rawConfig).toMatchInlineSnapshot(`
86
- Object {
87
- "client": Object {
88
- "addTypename": true,
89
- "clientOnlyDirectives": Array [
90
- "connection",
91
- "type",
92
- ],
93
- "clientSchemaDirectives": Array [
94
- "client",
95
- "rest",
96
- ],
97
- "excludes": Array [
98
- "**/node_modules",
99
- "**/__tests__",
100
- ],
101
- "includes": Array [
102
- "src/**/*.{ts,tsx,js,jsx,graphql,gql}",
103
- ],
104
- "service": "hello",
105
- "statsWindow": Object {
106
- "from": -86400,
107
- "to": -0,
108
- },
109
- "tagName": "gql",
110
- },
111
- "engine": Object {
112
- "endpoint": "https://graphql.api.apollographql.com/api/graphql",
113
- },
114
- }
115
- `);
96
+ Object {
97
+ "client": Object {
98
+ "excludes": Array [
99
+ "**/node_modules",
100
+ "**/__tests__",
101
+ ],
102
+ "includes": Array [
103
+ "src/**/*.{ts,tsx,js,jsx,graphql,gql}",
104
+ ],
105
+ "service": "hello",
106
+ "tagName": "gql",
107
+ },
108
+ "engine": Object {
109
+ "endpoint": "https://graphql.api.apollographql.com/api/graphql",
110
+ },
111
+ }
112
+ `);
116
113
  });
117
114
 
118
- it("loads with service defaults from different dir", async () => {
119
- writeFilesToDir(dir, {
120
- "my.config.js": `
115
+ it("loads with rover defaults from different dir", () =>
116
+ withFeatureFlags("rover", async () => {
117
+ writeFilesToDir(dir, {
118
+ "apollo.config.js": `
121
119
  module.exports = {
122
- service: {
123
- name: 'hello'
120
+ rover: {
124
121
  }
125
122
  }
126
123
  `,
127
- });
128
-
129
- const config = await loadConfig({
130
- configPath: dirPath,
131
- configFileName: "my.config.js",
132
- });
133
- expect(config?.rawConfig).toMatchInlineSnapshot(`
134
- Object {
135
- "engine": Object {
136
- "endpoint": "https://graphql.api.apollographql.com/api/graphql",
137
- },
138
- "service": Object {
139
- "endpoint": Object {
140
- "url": "http://localhost:4000/graphql",
141
- },
142
- "excludes": Array [
143
- "**/node_modules",
144
- "**/__tests__",
145
- ],
146
- "includes": Array [
147
- "src/**/*.{ts,tsx,js,jsx,graphql,gql}",
148
- ],
149
- "name": "hello",
150
- },
151
- }
152
- `);
153
- });
124
+ });
125
+
126
+ const config = await loadConfig({
127
+ configPath: dirPath,
128
+ });
129
+ expect(config?.rawConfig).toMatchInlineSnapshot(`
130
+ Object {
131
+ "engine": Object {
132
+ "endpoint": "https://graphql.api.apollographql.com/api/graphql",
133
+ },
134
+ "rover": Object {},
135
+ }
136
+ `);
137
+ }));
154
138
 
155
139
  it("[deprecated] loads config from package.json", async () => {
156
140
  writeFilesToDir(dir, {
@@ -169,17 +153,40 @@ describe("loadConfig", () => {
169
153
 
170
154
  it("loads config from a ts file", async () => {
171
155
  writeFilesToDir(dir, {
172
- "apollo.config.ts": `module.exports = {"client": {"service": "hello"}`,
156
+ "apollo.config.ts": `export default {"client": {"service": "hello"} }`,
173
157
  });
174
158
  const config = await loadConfig({ configPath: dirPath });
159
+ expect(config?.client?.service).toEqual("hello");
160
+ });
175
161
 
162
+ it("loads config from a ts file with CommonJs", async () => {
163
+ writeFilesToDir(dir, {
164
+ "apollo.config.ts": `module.exports = {"client": {"service": "hello"} }`,
165
+ });
166
+ const config = await loadConfig({ configPath: dirPath });
167
+ expect(config?.client?.service).toEqual("hello");
168
+ });
169
+
170
+ it("loads config from a cjs file", async () => {
171
+ writeFilesToDir(dir, {
172
+ "apollo.config.cjs": `module.exports = {"client": {"service": "hello"} }`,
173
+ });
174
+ const config = await loadConfig({ configPath: dirPath });
175
+ expect(config?.client?.service).toEqual("hello");
176
+ });
177
+
178
+ it("loads config from a mjs file", async () => {
179
+ writeFilesToDir(dir, {
180
+ "apollo.config.mjs": `export default {"client": {"service": "hello"} }`,
181
+ });
182
+ const config = await loadConfig({ configPath: dirPath });
176
183
  expect(config?.client?.service).toEqual("hello");
177
184
  });
178
185
  });
179
186
 
180
187
  describe("errors", () => {
181
188
  it("throws when config file is empty", async () => {
182
- writeFilesToDir(dir, { "my.config.js": `` });
189
+ writeFilesToDir(dir, { "apollo.config.js": `` });
183
190
 
184
191
  const spy = jest.spyOn(console, "error");
185
192
  // use this to keep the log quiet
@@ -187,33 +194,23 @@ describe("loadConfig", () => {
187
194
 
188
195
  await loadConfig({
189
196
  configPath: dirPath,
190
- configFileName: "my.config.js",
191
197
  });
192
198
 
193
199
  expect(spy).toHaveBeenCalledWith(
194
- expect.stringMatching(/config file failed to load/i)
200
+ expect.stringMatching(/config file failed to load/i),
195
201
  );
196
202
 
197
203
  spy.mockRestore();
198
204
  });
199
205
 
200
206
  it("throws when explorer.search fails", async () => {
201
- writeFilesToDir(dir, { "my.config.js": `* 98375^%*&^ its lit` });
207
+ writeFilesToDir(dir, { "apollo.config.js": `* 98375^%*&^ its lit` });
202
208
 
203
- const spy = jest.spyOn(console, "error");
204
- // use this to keep the log quiet
205
- spy.mockImplementation();
206
-
207
- await loadConfig({
209
+ const error = await loadConfig({
208
210
  configPath: dirPath,
209
- configFileName: "my.config.js",
210
- });
211
+ }).catch((e: any) => e);
211
212
 
212
- expect(spy).toHaveBeenCalledWith(
213
- expect.stringMatching(/config file failed to load/i)
214
- );
215
-
216
- spy.mockRestore();
213
+ expect(error.message).toMatch(/config file failed to load/i);
217
214
  });
218
215
 
219
216
  it("issues a deprecation warning when loading config from package.json", async () => {
@@ -226,11 +223,10 @@ describe("loadConfig", () => {
226
223
 
227
224
  await loadConfig({
228
225
  configPath: dirPath,
229
- configFileName: "package.json",
230
226
  });
231
227
 
232
228
  expect(spy).toHaveBeenCalledWith(
233
- expect.stringMatching(/The "apollo" package.json configuration/i)
229
+ expect.stringMatching(/The "apollo" package.json configuration/i),
234
230
  );
235
231
 
236
232
  spy.mockRestore();
@@ -240,49 +236,43 @@ describe("loadConfig", () => {
240
236
  const spy = jest.spyOn(console, "error");
241
237
  spy.mockImplementation();
242
238
 
243
- writeFilesToDir(dir, { "my.config.js": `module.exports = {}` });
239
+ writeFilesToDir(dir, { "foo.config.js": `module.exports = {}` });
244
240
 
245
241
  await loadConfig({
246
- configFileName: "my.TYPO.js",
242
+ configPath: dirPath,
247
243
  requireConfig: true, // this is what we're testing
248
244
  });
249
245
 
250
246
  expect(spy).toHaveBeenCalledWith(
251
- expect.stringMatching(/no apollo config/i)
247
+ expect.stringMatching(/no apollo config/i),
252
248
  );
253
249
  spy.mockRestore();
254
250
  });
255
251
 
256
252
  it("throws if project type cant be resolved", async () => {
257
- const spy = jest.spyOn(console, "error");
258
- spy.mockImplementation();
259
-
260
253
  writeFilesToDir(dir, {
261
- "my.config.js": `module.exports = {}`,
254
+ "apollo.config.js": `module.exports = {}`,
262
255
  });
263
256
 
264
- await loadConfig({
257
+ const error = await loadConfig({
265
258
  configPath: dirPath,
266
- configFileName: "my.config.js",
267
- });
259
+ }).catch((e: any) => e);
268
260
 
269
- expect(spy).toHaveBeenCalledWith(
270
- expect.stringMatching(/unable to resolve/i)
261
+ expect(error.message).toMatch(
262
+ /Config needs to contain a 'client' field./i,
271
263
  );
272
- spy.mockRestore();
273
264
  });
274
265
  });
275
266
 
276
267
  describe("env loading", () => {
277
268
  it("finds .env in config path & parses for key", async () => {
278
269
  writeFilesToDir(dir, {
279
- "my.config.js": `module.exports = { client: { name: 'hello' } }`,
270
+ "apollo.config.js": `module.exports = { client: { name: 'hello' } }`,
280
271
  ".env": `APOLLO_KEY=service:harambe:54378950jn`,
281
272
  });
282
273
 
283
274
  const config = await loadConfig({
284
275
  configPath: dirPath,
285
- configFileName: "my.config.js",
286
276
  });
287
277
 
288
278
  expect(config?.client?.service).toEqual("harambe");
@@ -290,13 +280,12 @@ describe("loadConfig", () => {
290
280
 
291
281
  it("finds .env.local in config path & parses for key", async () => {
292
282
  writeFilesToDir(dir, {
293
- "my.config.js": `module.exports = { client: { name: 'hello' } }`,
283
+ "apollo.config.js": `module.exports = { client: { name: 'hello' } }`,
294
284
  ".env.local": `APOLLO_KEY=service:harambe:54378950jn`,
295
285
  });
296
286
 
297
287
  const config = await loadConfig({
298
288
  configPath: dirPath,
299
- configFileName: "my.config.js",
300
289
  });
301
290
 
302
291
  expect(config?.client?.service).toEqual("harambe");
@@ -304,66 +293,27 @@ describe("loadConfig", () => {
304
293
 
305
294
  it("finds .env and .env.local in config path & parses for key, preferring .env.local", async () => {
306
295
  writeFilesToDir(dir, {
307
- "my.config.js": `module.exports = { client: { name: 'hello' } }`,
296
+ "apollo.config.js": `module.exports = { client: { name: 'hello' } }`,
308
297
  ".env": `APOLLO_KEY=service:hamato:54378950jn`,
309
298
  ".env.local": `APOLLO_KEY=service:yoshi:65489061ko`,
310
299
  });
311
300
 
312
301
  const config = await loadConfig({
313
302
  configPath: dirPath,
314
- configFileName: "my.config.js",
315
303
  });
316
304
 
317
305
  expect(config?.client?.service).toEqual("yoshi");
318
306
  });
319
307
 
320
- it("Allows setting ENGINE_API_KEY with a deprecation warning", async () => {
321
- writeFilesToDir(dir, {
322
- "my.config.js": `module.exports = { client: { name: 'hello' } }`,
323
- ".env.local": `ENGINE_API_KEY=service:yoshi:65489061ko`,
324
- });
325
-
326
- const spy = jest.spyOn(Debug, "warning");
327
-
328
- const config = await loadConfig({
329
- configPath: dirPath,
330
- configFileName: "my.config.js",
331
- });
332
-
333
- expect(config?.client?.service).toEqual("yoshi");
334
- expect(spy).toHaveBeenCalledWith(
335
- expect.stringMatching(/Deprecation warning/i)
336
- );
337
- });
338
-
339
- it("Uses new key when .env defined both legacy and new key", async () => {
340
- writeFilesToDir(dir, {
341
- "my.config.js": `module.exports = { client: { name: 'hello' } }`,
342
- ".env.local": `ENGINE_API_KEY=service:yoshi:65489061ko\nAPOLLO_KEY=service:yoshi:65489061ko`,
343
- });
344
- const spy = jest.spyOn(Debug, "warning");
345
-
346
- const config = await loadConfig({
347
- configPath: dirPath,
348
- configFileName: "my.config.js",
349
- });
350
-
351
- expect(config?.engine.apiKey).toEqual("service:yoshi:65489061ko");
352
- expect(spy).toHaveBeenCalledWith(
353
- expect.stringMatching(/Both ENGINE_API_KEY and APOLLO_KEY were found/i)
354
- );
355
- });
356
-
357
308
  // this doesn't work right now :)
358
- xit("finds .env in cwd & parses for key", async () => {
309
+ it.skip("finds .env in cwd & parses for key", async () => {
359
310
  writeFilesToDir(dir, {
360
- "dir/my.config.js": `module.exports = { client: { name: 'hello' } }`,
311
+ "dir/apollo.config.js": `module.exports = { client: { name: 'hello' } }`,
361
312
  ".env": `APOLLO_KEY=service:harambe:54378950jn`,
362
313
  });
363
314
  process.chdir(dir);
364
315
  const config = await loadConfig({
365
316
  configPath: "dir/",
366
- configFileName: "my.config.js",
367
317
  });
368
318
 
369
319
  process.chdir("../");
@@ -372,73 +322,41 @@ describe("loadConfig", () => {
372
322
  });
373
323
 
374
324
  describe("project type", () => {
375
- it("uses passed in type when config doesnt have client/service", async () => {
376
- writeFilesToDir(dir, {
377
- "my.config.js": `module.exports = { engine: { endpoint: 'http://a.a' } }`,
378
- });
379
-
380
- const config = await loadConfig({
381
- configPath: dirPath,
382
- configFileName: "my.config.js",
383
- type: "client",
384
- });
385
-
386
- expect(config?.isClient).toEqual(true);
387
- });
388
-
389
325
  it("infers client projects from config", async () => {
390
326
  writeFilesToDir(dir, {
391
- "my.config.js": `module.exports = { client: { service: 'hello' } }`,
327
+ "apollo.config.js": `module.exports = { client: { service: 'hello' } }`,
392
328
  });
393
329
 
394
330
  const config = await loadConfig({
395
331
  configPath: dirPath,
396
- configFileName: "my.config.js",
397
332
  });
398
333
 
399
- expect(config?.isClient).toEqual(true);
334
+ expect(config).toBeInstanceOf(ClientConfig);
400
335
  });
401
336
 
402
- it("infers service projects from config", async () => {
403
- writeFilesToDir(dir, {
404
- "my.config.js": `module.exports = { service: 'wow' }`,
405
- });
337
+ it("infers rover projects from config", () =>
338
+ withFeatureFlags("rover", async () => {
339
+ writeFilesToDir(dir, {
340
+ "apollo.config.js": `module.exports = { rover: {} }`,
341
+ });
406
342
 
407
- const config = await loadConfig({
408
- configPath: dirPath,
409
- configFileName: "my.config.js",
410
- });
343
+ const config = await loadConfig({
344
+ configPath: dirPath,
345
+ });
411
346
 
412
- expect(config?.isService).toEqual(true);
413
- });
347
+ expect(config).toBeInstanceOf(RoverConfig);
348
+ }));
414
349
  });
415
350
 
416
351
  describe("service name", () => {
417
352
  it("lets config service name take precedence for client project", async () => {
418
353
  writeFilesToDir(dir, {
419
- "my.config.js": `module.exports = { client: { service: 'hello' } }`,
420
- ".env": `APOLLO_KEY=service:harambe:54378950jn`,
421
- });
422
-
423
- const config = await loadConfig({
424
- configPath: dirPath,
425
- configFileName: "my.config.js",
426
- name: "not-it",
427
- });
428
-
429
- expect(config?.client?.service).toEqual("hello");
430
- });
431
-
432
- it("lets name passed in take precedence over env var", async () => {
433
- writeFilesToDir(dir, {
434
- "my.config.js": `module.exports = { client: { } }`,
354
+ "apollo.config.js": `module.exports = { client: { service: 'hello' } }`,
435
355
  ".env": `APOLLO_KEY=service:harambe:54378950jn`,
436
356
  });
437
357
 
438
358
  const config = await loadConfig({
439
359
  configPath: dirPath,
440
- configFileName: "my.config.js",
441
- name: "hello",
442
360
  });
443
361
 
444
362
  expect(config?.client?.service).toEqual("hello");
@@ -446,13 +364,12 @@ describe("loadConfig", () => {
446
364
 
447
365
  it("uses env var to determine service name when no other options", async () => {
448
366
  writeFilesToDir(dir, {
449
- "my.config.js": `module.exports = { client: { } }`,
367
+ "apollo.config.js": `module.exports = { client: { } }`,
450
368
  ".env": `APOLLO_KEY=service:harambe:54378950jn`,
451
369
  });
452
370
 
453
371
  const config = await loadConfig({
454
372
  configPath: dirPath,
455
- configFileName: "my.config.js",
456
373
  });
457
374
 
458
375
  expect(config?.client?.service).toEqual("harambe");
@@ -462,46 +379,29 @@ describe("loadConfig", () => {
462
379
  describe("default merging", () => {
463
380
  it("merges service name and default config for client projects", async () => {
464
381
  writeFilesToDir(dir, {
465
- "my.config.js": `module.exports = { client: { service: 'hello' } }`,
382
+ "apollo.config.js": `module.exports = { client: { service: 'hello' } }`,
466
383
  });
467
384
 
468
385
  const config = await loadConfig({
469
386
  configPath: dirPath,
470
- configFileName: "my.config.js",
471
387
  });
472
388
 
473
- expect(config?.rawConfig?.client?.includes).toEqual(
474
- DefaultClientConfig.includes
475
- );
476
- });
477
-
478
- it("merges service name and default config for service projects", async () => {
479
- writeFilesToDir(dir, {
480
- "my.config.js": `module.exports = { service: { name: 'wow' } }`,
481
- });
482
-
483
- const config = await loadConfig({
484
- configPath: dirPath,
485
- configFileName: "my.config.js",
486
- });
487
-
488
- expect(config?.rawConfig?.service?.includes).toEqual(
489
- DefaultServiceConfig.includes
490
- );
389
+ expect((config?.rawConfig as any).client.includes).toEqual([
390
+ "src/**/*.{ts,tsx,js,jsx,graphql,gql}",
391
+ ]);
491
392
  });
492
393
 
493
394
  it("merges engine config defaults", async () => {
494
395
  writeFilesToDir(dir, {
495
- "my.config.js": `module.exports = { client: { service: 'wow' } }`,
396
+ "apollo.config.js": `module.exports = { client: { service: 'wow' } }`,
496
397
  });
497
398
 
498
399
  const config = await loadConfig({
499
400
  configPath: dirPath,
500
- configFileName: "my.config.js",
501
401
  });
502
402
 
503
403
  expect(config?.rawConfig?.engine?.endpoint).toEqual(
504
- DefaultEngineConfig.endpoint
404
+ "https://graphql.api.apollographql.com/api/graphql",
505
405
  );
506
406
  });
507
407
  });
@@ -1,13 +1,11 @@
1
1
  import {
2
- ApolloConfig,
3
- ApolloConfigFormat,
4
2
  getServiceFromKey,
5
3
  getGraphIdFromConfig,
6
4
  isClientConfig,
7
5
  isLocalServiceConfig,
8
- isServiceConfig,
9
6
  parseServiceSpecifier,
10
- DefaultConfigBase,
7
+ parseApolloConfig,
8
+ configSchema,
11
9
  } from "../";
12
10
 
13
11
  describe("getServiceFromKey", () => {
@@ -34,36 +32,38 @@ describe("getServiceFromKey", () => {
34
32
  describe("getServiceName", () => {
35
33
  describe("client config", () => {
36
34
  it("finds service name when client.service is a string", () => {
37
- const rawConfig: ApolloConfigFormat = {
38
- client: { service: "my-service", ...DefaultConfigBase },
39
- };
35
+ const rawConfig = configSchema.parse({
36
+ client: { service: "my-service" },
37
+ });
40
38
  expect(getGraphIdFromConfig(rawConfig)).toEqual("my-service");
41
39
 
42
- const rawConfigWithTag: ApolloConfigFormat = {
43
- client: { service: "my-service@master", ...DefaultConfigBase },
44
- };
40
+ const rawConfigWithTag = configSchema.parse({
41
+ client: { service: "my-service@master" },
42
+ });
45
43
  expect(getGraphIdFromConfig(rawConfigWithTag)).toEqual("my-service");
46
44
  });
47
45
 
48
46
  it("finds service name when client.service is an object", () => {
49
- const rawConfig: ApolloConfigFormat = {
47
+ const rawConfig = configSchema.parse({
50
48
  client: {
51
49
  service: { name: "my-service", localSchemaFile: "./someFile" },
52
- ...DefaultConfigBase,
53
50
  },
54
- };
51
+ });
55
52
  expect(getGraphIdFromConfig(rawConfig)).toEqual("my-service");
56
53
  });
57
54
  });
58
55
  describe("service config", () => {
59
56
  it("finds service name from raw service config", () => {
60
- const rawConfig: ApolloConfigFormat = {
61
- service: {
62
- name: "my-service",
63
- localSchemaFile: "./someFile",
64
- ...DefaultConfigBase,
57
+ const rawConfig = configSchema.parse({
58
+ client: {
59
+ service: {
60
+ name: "my-service",
61
+ localSchemaFile: "./someFile",
62
+ },
63
+ includes: [],
64
+ excludes: [],
65
65
  },
66
- };
66
+ });
67
67
  expect(getGraphIdFromConfig(rawConfig)).toEqual("my-service");
68
68
  });
69
69
  });
@@ -71,10 +71,10 @@ describe("getServiceName", () => {
71
71
 
72
72
  describe("isClientConfig", () => {
73
73
  it("identifies client config properly", () => {
74
- const config = new ApolloConfig({
75
- client: { service: "hello", ...DefaultConfigBase },
74
+ const config = parseApolloConfig({
75
+ client: { service: "hello" },
76
76
  });
77
- expect(isClientConfig(config)).toBeTruthy();
77
+ expect(isClientConfig(config!)).toBeTruthy();
78
78
  });
79
79
  });
80
80
 
@@ -85,13 +85,6 @@ describe("isLocalServiceConfig", () => {
85
85
  });
86
86
  });
87
87
 
88
- describe("isServiceConfig", () => {
89
- it("identifies service config properly", () => {
90
- const config = new ApolloConfig({ service: { ...DefaultConfigBase } });
91
- expect(isServiceConfig(config)).toBeTruthy();
92
- });
93
- });
94
-
95
88
  describe("parseServiceSpecifier", () => {
96
89
  it("parses service identifier for service id and tag properly", () => {
97
90
  const [id, tag] = parseServiceSpecifier("my-service@master");