Skip to content

Commit abedfb2

Browse files
authored
Don't error when ENGINE_API_KEY and APOLLO_KEY are found (#1893)
1 parent b9f9182 commit abedfb2

3 files changed

Lines changed: 10 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- `apollo-graphql`
2020
- <First `apollo-graphql` related entry goes here>
2121
- `apollo-language-server`
22+
- Remove error from the case with old and new api keys present [#1893](https://github.com/apollographql/apollo-tooling/pull/1893)
2223
- Add Elixir support for vscode [#1971](https://github.com/apollographql/apollo-tooling/pull/1971)
2324
- `apollo-tools`
2425
- <First `apollo-tools` related entry goes here>

packages/apollo-language-server/src/config/__tests__/loadConfig.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,18 +339,22 @@ describe("loadConfig", () => {
339339
);
340340
});
341341

342-
it("Throws when .env defined legacy and new key", async () => {
342+
it("Uses new key when .env defined both legacy and new key", async () => {
343343
writeFilesToDir(dir, {
344344
"my.config.js": `module.exports = { client: { name: 'hello' } }`,
345345
".env.local": `ENGINE_API_KEY=service:yoshi:65489061ko\nAPOLLO_KEY=service:yoshi:65489061ko`
346346
});
347+
const spy = jest.spyOn(Debug, "warning");
347348

348-
const loadConfigPromise = loadConfig({
349+
const config = await loadConfig({
349350
configPath: dirPath,
350351
configFileName: "my.config.js"
351352
});
352353

353-
await expect(loadConfigPromise).rejects.toThrow(/Cannot set both/);
354+
expect(config.engine.apiKey).toEqual("service:yoshi:65489061ko");
355+
expect(spy).toHaveBeenCalledWith(
356+
expect.stringMatching(/Both ENGINE_API_KEY and APOLLO_KEY were found/i)
357+
);
354358
});
355359

356360
// this doesn't work right now :)

packages/apollo-language-server/src/config/loadConfig.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ export async function loadConfig({
129129
const legacyKey = env[legacyKeyEnvVar];
130130
const key = env[keyEnvVar];
131131
if (legacyKey && key) {
132-
throw new Error(
133-
`Cannot set both ${legacyKeyEnvVar} and ${keyEnvVar}. Please only set ${keyEnvVar}`
132+
Debug.warning(
133+
`Both ${legacyKeyEnvVar} and ${keyEnvVar} were found. ${keyEnvVar} will take precedence.`
134134
);
135135
}
136136
if (legacyKey) {

0 commit comments

Comments
 (0)