Repository: apollographql/apollo-tooling
Pull request #1893 (2020-04-13 16:18:05)

Don't error when ENGINE_API_KEY and APOLLO_KEY are found
`apollo-server` still uses the `ENGINE_API_KEY`, so we can't truly move to the newer key. We have to be able to support both keys for now, so this removes the error and replaces it with a warning that explicitly states which key tooling is using.

TODO:

- [ ] Update CHANGELOG.md\* with your change (include reference to issue & this PR)
- [ ] Make sure all of the significant new logic is covered by tests
- [ ] Rebase your changes on master so that they can be merged easily
- [ ] Make sure all tests and linter rules pass

\*Make sure changelog entries note which project(s) has been affected. See older entries for examples on what this looks like.



Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8e1cb816..3ff5c21e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,6 +19,7 @@
 - `apollo-graphql`
   - <First `apollo-graphql` related entry goes here>
 - `apollo-language-server`
+  - Remove error from the case with old and new api keys present [#1893](https://github.com/apollographql/apollo-tooling/pull/1893)
   - Add Elixir support for vscode [#1971](https://github.com/apollographql/apollo-tooling/pull/1971)
 - `apollo-tools`
   - <First `apollo-tools` related entry goes here>
diff --git a/packages/apollo-language-server/src/config/loadConfig.ts b/packages/apollo-language-server/src/config/loadConfig.ts
index 1fc2420a..bf69f2fc 100644
--- a/packages/apollo-language-server/src/config/loadConfig.ts
+++ b/packages/apollo-language-server/src/config/loadConfig.ts
@@ -129,8 +129,8 @@ export async function loadConfig({
       const legacyKey = env[legacyKeyEnvVar];
       const key = env[keyEnvVar];
       if (legacyKey && key) {
-        throw new Error(
-          `Cannot set both ${legacyKeyEnvVar} and ${keyEnvVar}. Please only set ${keyEnvVar}`
+        Debug.warning(
+          `Both ${legacyKeyEnvVar} and ${keyEnvVar} were found. ${keyEnvVar} will take precedence.`
         );
       }
       if (legacyKey) {


Test patch:
diff --git a/packages/apollo-language-server/src/config/__tests__/loadConfig.ts b/packages/apollo-language-server/src/config/__tests__/loadConfig.ts
index 222cce99..a084e05f 100644
--- a/packages/apollo-language-server/src/config/__tests__/loadConfig.ts
+++ b/packages/apollo-language-server/src/config/__tests__/loadConfig.ts
@@ -339,18 +339,22 @@ describe("loadConfig", () => {
       );
     });
 
-    it("Throws when .env defined legacy and new key", async () => {
+    it("Uses new key when .env defined both legacy and new key", async () => {
       writeFilesToDir(dir, {
         "my.config.js": `module.exports = { client: { name: 'hello' } }`,
         ".env.local": `ENGINE_API_KEY=service:yoshi:65489061ko\nAPOLLO_KEY=service:yoshi:65489061ko`
       });
+      const spy = jest.spyOn(Debug, "warning");
 
-      const loadConfigPromise = loadConfig({
+      const config = await loadConfig({
         configPath: dirPath,
         configFileName: "my.config.js"
       });
 
-      await expect(loadConfigPromise).rejects.toThrow(/Cannot set both/);
+      expect(config.engine.apiKey).toEqual("service:yoshi:65489061ko");
+      expect(spy).toHaveBeenCalledWith(
+        expect.stringMatching(/Both ENGINE_API_KEY and APOLLO_KEY were found/i)
+      );
     });
 
     // this doesn't work right now :)