vscode-apollo 1.20.0 → 2.0.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.
- 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 +78 -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 +97 -221
- 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 +26 -153
- 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
|
@@ -1,19 +1,30 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
"
|
|
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
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
|
119
|
-
|
|
120
|
-
|
|
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
|
-
|
|
123
|
-
name: 'hello'
|
|
120
|
+
rover: {
|
|
124
121
|
}
|
|
125
122
|
}
|
|
126
123
|
`,
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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,16 @@ describe("loadConfig", () => {
|
|
|
169
153
|
|
|
170
154
|
it("loads config from a ts file", async () => {
|
|
171
155
|
writeFilesToDir(dir, {
|
|
172
|
-
"apollo.config.ts": `
|
|
156
|
+
"apollo.config.ts": `export default {"client": {"service": "hello"} }`,
|
|
173
157
|
});
|
|
174
158
|
const config = await loadConfig({ configPath: dirPath });
|
|
175
|
-
|
|
176
159
|
expect(config?.client?.service).toEqual("hello");
|
|
177
160
|
});
|
|
178
161
|
});
|
|
179
162
|
|
|
180
163
|
describe("errors", () => {
|
|
181
164
|
it("throws when config file is empty", async () => {
|
|
182
|
-
writeFilesToDir(dir, { "
|
|
165
|
+
writeFilesToDir(dir, { "apollo.config.js": `` });
|
|
183
166
|
|
|
184
167
|
const spy = jest.spyOn(console, "error");
|
|
185
168
|
// use this to keep the log quiet
|
|
@@ -187,33 +170,23 @@ describe("loadConfig", () => {
|
|
|
187
170
|
|
|
188
171
|
await loadConfig({
|
|
189
172
|
configPath: dirPath,
|
|
190
|
-
configFileName: "my.config.js",
|
|
191
173
|
});
|
|
192
174
|
|
|
193
175
|
expect(spy).toHaveBeenCalledWith(
|
|
194
|
-
expect.stringMatching(/config file failed to load/i)
|
|
176
|
+
expect.stringMatching(/config file failed to load/i),
|
|
195
177
|
);
|
|
196
178
|
|
|
197
179
|
spy.mockRestore();
|
|
198
180
|
});
|
|
199
181
|
|
|
200
182
|
it("throws when explorer.search fails", async () => {
|
|
201
|
-
writeFilesToDir(dir, { "
|
|
183
|
+
writeFilesToDir(dir, { "apollo.config.js": `* 98375^%*&^ its lit` });
|
|
202
184
|
|
|
203
|
-
const
|
|
204
|
-
// use this to keep the log quiet
|
|
205
|
-
spy.mockImplementation();
|
|
206
|
-
|
|
207
|
-
await loadConfig({
|
|
185
|
+
const error = await loadConfig({
|
|
208
186
|
configPath: dirPath,
|
|
209
|
-
|
|
210
|
-
});
|
|
187
|
+
}).catch((e: any) => e);
|
|
211
188
|
|
|
212
|
-
expect(
|
|
213
|
-
expect.stringMatching(/config file failed to load/i)
|
|
214
|
-
);
|
|
215
|
-
|
|
216
|
-
spy.mockRestore();
|
|
189
|
+
expect(error.message).toMatch(/config file failed to load/i);
|
|
217
190
|
});
|
|
218
191
|
|
|
219
192
|
it("issues a deprecation warning when loading config from package.json", async () => {
|
|
@@ -226,11 +199,10 @@ describe("loadConfig", () => {
|
|
|
226
199
|
|
|
227
200
|
await loadConfig({
|
|
228
201
|
configPath: dirPath,
|
|
229
|
-
configFileName: "package.json",
|
|
230
202
|
});
|
|
231
203
|
|
|
232
204
|
expect(spy).toHaveBeenCalledWith(
|
|
233
|
-
expect.stringMatching(/The "apollo" package.json configuration/i)
|
|
205
|
+
expect.stringMatching(/The "apollo" package.json configuration/i),
|
|
234
206
|
);
|
|
235
207
|
|
|
236
208
|
spy.mockRestore();
|
|
@@ -240,49 +212,43 @@ describe("loadConfig", () => {
|
|
|
240
212
|
const spy = jest.spyOn(console, "error");
|
|
241
213
|
spy.mockImplementation();
|
|
242
214
|
|
|
243
|
-
writeFilesToDir(dir, { "
|
|
215
|
+
writeFilesToDir(dir, { "foo.config.js": `module.exports = {}` });
|
|
244
216
|
|
|
245
217
|
await loadConfig({
|
|
246
|
-
|
|
218
|
+
configPath: dirPath,
|
|
247
219
|
requireConfig: true, // this is what we're testing
|
|
248
220
|
});
|
|
249
221
|
|
|
250
222
|
expect(spy).toHaveBeenCalledWith(
|
|
251
|
-
expect.stringMatching(/no apollo config/i)
|
|
223
|
+
expect.stringMatching(/no apollo config/i),
|
|
252
224
|
);
|
|
253
225
|
spy.mockRestore();
|
|
254
226
|
});
|
|
255
227
|
|
|
256
228
|
it("throws if project type cant be resolved", async () => {
|
|
257
|
-
const spy = jest.spyOn(console, "error");
|
|
258
|
-
spy.mockImplementation();
|
|
259
|
-
|
|
260
229
|
writeFilesToDir(dir, {
|
|
261
|
-
"
|
|
230
|
+
"apollo.config.js": `module.exports = {}`,
|
|
262
231
|
});
|
|
263
232
|
|
|
264
|
-
await loadConfig({
|
|
233
|
+
const error = await loadConfig({
|
|
265
234
|
configPath: dirPath,
|
|
266
|
-
|
|
267
|
-
});
|
|
235
|
+
}).catch((e: any) => e);
|
|
268
236
|
|
|
269
|
-
expect(
|
|
270
|
-
|
|
237
|
+
expect(error.message).toMatch(
|
|
238
|
+
/Config needs to contain a 'client' field./i,
|
|
271
239
|
);
|
|
272
|
-
spy.mockRestore();
|
|
273
240
|
});
|
|
274
241
|
});
|
|
275
242
|
|
|
276
243
|
describe("env loading", () => {
|
|
277
244
|
it("finds .env in config path & parses for key", async () => {
|
|
278
245
|
writeFilesToDir(dir, {
|
|
279
|
-
"
|
|
246
|
+
"apollo.config.js": `module.exports = { client: { name: 'hello' } }`,
|
|
280
247
|
".env": `APOLLO_KEY=service:harambe:54378950jn`,
|
|
281
248
|
});
|
|
282
249
|
|
|
283
250
|
const config = await loadConfig({
|
|
284
251
|
configPath: dirPath,
|
|
285
|
-
configFileName: "my.config.js",
|
|
286
252
|
});
|
|
287
253
|
|
|
288
254
|
expect(config?.client?.service).toEqual("harambe");
|
|
@@ -290,13 +256,12 @@ describe("loadConfig", () => {
|
|
|
290
256
|
|
|
291
257
|
it("finds .env.local in config path & parses for key", async () => {
|
|
292
258
|
writeFilesToDir(dir, {
|
|
293
|
-
"
|
|
259
|
+
"apollo.config.js": `module.exports = { client: { name: 'hello' } }`,
|
|
294
260
|
".env.local": `APOLLO_KEY=service:harambe:54378950jn`,
|
|
295
261
|
});
|
|
296
262
|
|
|
297
263
|
const config = await loadConfig({
|
|
298
264
|
configPath: dirPath,
|
|
299
|
-
configFileName: "my.config.js",
|
|
300
265
|
});
|
|
301
266
|
|
|
302
267
|
expect(config?.client?.service).toEqual("harambe");
|
|
@@ -304,66 +269,27 @@ describe("loadConfig", () => {
|
|
|
304
269
|
|
|
305
270
|
it("finds .env and .env.local in config path & parses for key, preferring .env.local", async () => {
|
|
306
271
|
writeFilesToDir(dir, {
|
|
307
|
-
"
|
|
272
|
+
"apollo.config.js": `module.exports = { client: { name: 'hello' } }`,
|
|
308
273
|
".env": `APOLLO_KEY=service:hamato:54378950jn`,
|
|
309
274
|
".env.local": `APOLLO_KEY=service:yoshi:65489061ko`,
|
|
310
275
|
});
|
|
311
276
|
|
|
312
277
|
const config = await loadConfig({
|
|
313
278
|
configPath: dirPath,
|
|
314
|
-
configFileName: "my.config.js",
|
|
315
279
|
});
|
|
316
280
|
|
|
317
281
|
expect(config?.client?.service).toEqual("yoshi");
|
|
318
282
|
});
|
|
319
283
|
|
|
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
284
|
// this doesn't work right now :)
|
|
358
|
-
|
|
285
|
+
it.skip("finds .env in cwd & parses for key", async () => {
|
|
359
286
|
writeFilesToDir(dir, {
|
|
360
|
-
"dir/
|
|
287
|
+
"dir/apollo.config.js": `module.exports = { client: { name: 'hello' } }`,
|
|
361
288
|
".env": `APOLLO_KEY=service:harambe:54378950jn`,
|
|
362
289
|
});
|
|
363
290
|
process.chdir(dir);
|
|
364
291
|
const config = await loadConfig({
|
|
365
292
|
configPath: "dir/",
|
|
366
|
-
configFileName: "my.config.js",
|
|
367
293
|
});
|
|
368
294
|
|
|
369
295
|
process.chdir("../");
|
|
@@ -372,73 +298,41 @@ describe("loadConfig", () => {
|
|
|
372
298
|
});
|
|
373
299
|
|
|
374
300
|
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
301
|
it("infers client projects from config", async () => {
|
|
390
302
|
writeFilesToDir(dir, {
|
|
391
|
-
"
|
|
303
|
+
"apollo.config.js": `module.exports = { client: { service: 'hello' } }`,
|
|
392
304
|
});
|
|
393
305
|
|
|
394
306
|
const config = await loadConfig({
|
|
395
307
|
configPath: dirPath,
|
|
396
|
-
configFileName: "my.config.js",
|
|
397
308
|
});
|
|
398
309
|
|
|
399
|
-
expect(config
|
|
310
|
+
expect(config).toBeInstanceOf(ClientConfig);
|
|
400
311
|
});
|
|
401
312
|
|
|
402
|
-
it("infers
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
313
|
+
it("infers rover projects from config", () =>
|
|
314
|
+
withFeatureFlags("rover", async () => {
|
|
315
|
+
writeFilesToDir(dir, {
|
|
316
|
+
"apollo.config.js": `module.exports = { rover: {} }`,
|
|
317
|
+
});
|
|
406
318
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
});
|
|
319
|
+
const config = await loadConfig({
|
|
320
|
+
configPath: dirPath,
|
|
321
|
+
});
|
|
411
322
|
|
|
412
|
-
|
|
413
|
-
|
|
323
|
+
expect(config).toBeInstanceOf(RoverConfig);
|
|
324
|
+
}));
|
|
414
325
|
});
|
|
415
326
|
|
|
416
327
|
describe("service name", () => {
|
|
417
328
|
it("lets config service name take precedence for client project", async () => {
|
|
418
329
|
writeFilesToDir(dir, {
|
|
419
|
-
"
|
|
330
|
+
"apollo.config.js": `module.exports = { client: { service: 'hello' } }`,
|
|
420
331
|
".env": `APOLLO_KEY=service:harambe:54378950jn`,
|
|
421
332
|
});
|
|
422
333
|
|
|
423
334
|
const config = await loadConfig({
|
|
424
335
|
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: { } }`,
|
|
435
|
-
".env": `APOLLO_KEY=service:harambe:54378950jn`,
|
|
436
|
-
});
|
|
437
|
-
|
|
438
|
-
const config = await loadConfig({
|
|
439
|
-
configPath: dirPath,
|
|
440
|
-
configFileName: "my.config.js",
|
|
441
|
-
name: "hello",
|
|
442
336
|
});
|
|
443
337
|
|
|
444
338
|
expect(config?.client?.service).toEqual("hello");
|
|
@@ -446,13 +340,12 @@ describe("loadConfig", () => {
|
|
|
446
340
|
|
|
447
341
|
it("uses env var to determine service name when no other options", async () => {
|
|
448
342
|
writeFilesToDir(dir, {
|
|
449
|
-
"
|
|
343
|
+
"apollo.config.js": `module.exports = { client: { } }`,
|
|
450
344
|
".env": `APOLLO_KEY=service:harambe:54378950jn`,
|
|
451
345
|
});
|
|
452
346
|
|
|
453
347
|
const config = await loadConfig({
|
|
454
348
|
configPath: dirPath,
|
|
455
|
-
configFileName: "my.config.js",
|
|
456
349
|
});
|
|
457
350
|
|
|
458
351
|
expect(config?.client?.service).toEqual("harambe");
|
|
@@ -462,46 +355,29 @@ describe("loadConfig", () => {
|
|
|
462
355
|
describe("default merging", () => {
|
|
463
356
|
it("merges service name and default config for client projects", async () => {
|
|
464
357
|
writeFilesToDir(dir, {
|
|
465
|
-
"
|
|
358
|
+
"apollo.config.js": `module.exports = { client: { service: 'hello' } }`,
|
|
466
359
|
});
|
|
467
360
|
|
|
468
361
|
const config = await loadConfig({
|
|
469
362
|
configPath: dirPath,
|
|
470
|
-
configFileName: "my.config.js",
|
|
471
363
|
});
|
|
472
364
|
|
|
473
|
-
expect(config?.rawConfig
|
|
474
|
-
|
|
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
|
-
);
|
|
365
|
+
expect((config?.rawConfig as any).client.includes).toEqual([
|
|
366
|
+
"src/**/*.{ts,tsx,js,jsx,graphql,gql}",
|
|
367
|
+
]);
|
|
491
368
|
});
|
|
492
369
|
|
|
493
370
|
it("merges engine config defaults", async () => {
|
|
494
371
|
writeFilesToDir(dir, {
|
|
495
|
-
"
|
|
372
|
+
"apollo.config.js": `module.exports = { client: { service: 'wow' } }`,
|
|
496
373
|
});
|
|
497
374
|
|
|
498
375
|
const config = await loadConfig({
|
|
499
376
|
configPath: dirPath,
|
|
500
|
-
configFileName: "my.config.js",
|
|
501
377
|
});
|
|
502
378
|
|
|
503
379
|
expect(config?.rawConfig?.engine?.endpoint).toEqual(
|
|
504
|
-
|
|
380
|
+
"https://graphql.api.apollographql.com/api/graphql",
|
|
505
381
|
);
|
|
506
382
|
});
|
|
507
383
|
});
|
|
@@ -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
|
-
|
|
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
|
|
38
|
-
client: { service: "my-service"
|
|
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
|
|
43
|
-
client: { service: "my-service@master"
|
|
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
|
|
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
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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 =
|
|
75
|
-
client: { service: "hello"
|
|
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");
|