From 2c8c7159cac43536aaa5bcfbb9a7e3f9ca1cb124 Mon Sep 17 00:00:00 2001 From: Trevor Scheer Date: Thu, 24 Jan 2019 15:24:13 -0800 Subject: [PATCH 1/5] Get extension back in a better state for monorepo setup * Cosmiconfig looks UP for configs from a provided config. This means that any package.json could send cosmiconfig to the parent - causing lots of dir weirdness. Filter out package.json files that don't contain an apollo config. Update apollo.config.js to point to engine@master * Incidentally found and fixed a bug related to providing the schema tag via the @. The @tag is no longer left behind when it's provided. --- .vscode/launch.json | 6 ++++++ apollo.config.js | 2 +- packages/apollo-language-server/src/config.ts | 6 +++++- .../apollo-language-server/src/workspace.ts | 17 ++++++++++++----- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 0a57c17056..c6d70f04e3 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -52,5 +52,11 @@ "port": 9002, "sourceMaps": true } + ], + "compounds": [ + { + "name": "Extension + Server", + "configurations": ["Launch VS Code Extension", "Attach to TS Server"] + } ] } diff --git a/apollo.config.js b/apollo.config.js index 7f3d63d554..0df86dd621 100644 --- a/apollo.config.js +++ b/apollo.config.js @@ -1,7 +1,7 @@ module.exports = { client: { name: "Apollo CLI", - service: "engine-api-prod", + service: "engine@master", includes: ["./packages/apollo-language-server/**/*.ts"] }, engine: { diff --git a/packages/apollo-language-server/src/config.ts b/packages/apollo-language-server/src/config.ts index 78ccd5d079..ce10b4d148 100644 --- a/packages/apollo-language-server/src/config.ts +++ b/packages/apollo-language-server/src/config.ts @@ -303,7 +303,7 @@ export const loadConfig = async ({ } } - const resolvedName = name || nameFromKey; + let resolvedName = name || nameFromKey; // The CLI passes in a type when loading config. The editor extension // does not. So we determine the type of the config here, and use it if @@ -313,6 +313,10 @@ export const loadConfig = async ({ resolvedType = type; } else if (loadedConfig && loadedConfig.config.client) { resolvedType = "client"; + resolvedName = + typeof loadedConfig.config.client.service === "string" + ? loadedConfig.config.client.service + : resolvedName; } else if (loadedConfig && loadedConfig.config.service) { resolvedType = "service"; } else { diff --git a/packages/apollo-language-server/src/workspace.ts b/packages/apollo-language-server/src/workspace.ts index 533a72fef5..dba9f2fcd1 100644 --- a/packages/apollo-language-server/src/workspace.ts +++ b/packages/apollo-language-server/src/workspace.ts @@ -103,11 +103,18 @@ export class GraphQLWorkspace { }); apolloConfigFiles.push( - ...fg.sync("**/package.json", { - cwd: URI.parse(folder.uri).fsPath, - absolute: true, - ignore: "**/node_modules/**" - }) + ...fg + .sync("**/package.json", { + cwd: URI.parse(folder.uri).fsPath, + absolute: true, + ignore: "**/node_modules/**" + }) + // Every package.json file _potentially_ has an apollo config, but we can filter out + // the ones that don't before we even call loadConfig and send cosmiconfig looking. + .filter(packageFile => { + const { apollo } = require(packageFile); + return Boolean(apollo); + }) ); // only have unique possible folders From 03a52d8832b0d8653bd0f403e450f3eb2cc06171 Mon Sep 17 00:00:00 2001 From: Trevor Scheer Date: Thu, 24 Jan 2019 17:10:38 -0800 Subject: [PATCH 2/5] Update CI configs to use master tag --- .circleci/config.yml | 2 +- azure-pipelines.yml | 2 +- packages/apollo-language-server/src/config.ts | 7 +++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index e225e439f7..b35aa6bd1e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -109,7 +109,7 @@ jobs: # This should cache the npm cache instead of node_modules, which is needed because # npm ci actually removes node_modules before installing to guarantee a clean slate. - ~/.npm - - run: ENGINE_API_KEY=$CHECKS_API_KEY ./packages/apollo/bin/run client:check + - run: ENGINE_API_KEY=$CHECKS_API_KEY ./packages/apollo/bin/run client:check --tag=master workflows: version: 2 diff --git a/azure-pipelines.yml b/azure-pipelines.yml index ff91ecd72e..8ea1648991 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -24,7 +24,7 @@ jobs: # displayName: "npm run lint" # - script: | - # ENGINE_API_KEY=$(CHECKS_API_KEY) ./packages/apollo/bin/run client:check + # ENGINE_API_KEY=$(CHECKS_API_KEY) ./packages/apollo/bin/run client:check --tag=master # displayName: "Query Check" # - job: Linux_Node10 diff --git a/packages/apollo-language-server/src/config.ts b/packages/apollo-language-server/src/config.ts index ce10b4d148..34437be294 100644 --- a/packages/apollo-language-server/src/config.ts +++ b/packages/apollo-language-server/src/config.ts @@ -311,6 +311,13 @@ export const loadConfig = async ({ let resolvedType: "client" | "service"; if (type) { resolvedType = type; + if ( + loadedConfig && + loadedConfig.config.client && + typeof loadedConfig.config.client.service === "string" + ) { + resolvedName = loadedConfig.config.client.service; + } } else if (loadedConfig && loadedConfig.config.client) { resolvedType = "client"; resolvedName = From c0d20ceace968ec7fcdc4a067237eaac543fb04a Mon Sep 17 00:00:00 2001 From: Trevor Scheer Date: Fri, 25 Jan 2019 11:40:36 -0800 Subject: [PATCH 3/5] Remove default "current" tag, but fallback to current when no tag is provided. Priority for choosing the tag name should be: flag -> config -> "current" With a default flag set, that default would always defeat the tag provided via config. --- packages/apollo/src/Command.ts | 2 +- packages/apollo/src/commands/client/check.ts | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/apollo/src/Command.ts b/packages/apollo/src/Command.ts index 1559ab307b..c69b062294 100644 --- a/packages/apollo/src/Command.ts +++ b/packages/apollo/src/Command.ts @@ -126,7 +126,7 @@ export abstract class ProjectCommand extends Command { type: this.type }); - if (flags.tag) config.tag = flags.tag; + config.tag = flags.tag || config.tag || "current"; // flag overides config.setDefaults({ engine: { diff --git a/packages/apollo/src/commands/client/check.ts b/packages/apollo/src/commands/client/check.ts index 92b2d3354e..76bb76fc82 100644 --- a/packages/apollo/src/commands/client/check.ts +++ b/packages/apollo/src/commands/client/check.ts @@ -12,8 +12,7 @@ export default class ClientCheck extends ClientCommand { ...ClientCommand.flags, tag: flags.string({ char: "t", - description: "The published tag to check this client against", - default: "current" + description: "The published tag to check this client against" }) }; @@ -35,7 +34,7 @@ export default class ClientCheck extends ClientCommand { const { changes } = await project.engine.checkOperations({ id: config.name, operations: ctx.operations, - tag: flags.tag, + tag: config.tag, gitContext: ctx.gitContext }); From cc9a2d2a5538052eddb95fcd3e624fa025be1bc2 Mon Sep 17 00:00:00 2001 From: Trevor Scheer Date: Fri, 25 Jan 2019 11:46:25 -0800 Subject: [PATCH 4/5] Remove unnecessary --tag flag (should be inferred by config service name via @) --- .circleci/config.yml | 2 +- azure-pipelines.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index b35aa6bd1e..e225e439f7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -109,7 +109,7 @@ jobs: # This should cache the npm cache instead of node_modules, which is needed because # npm ci actually removes node_modules before installing to guarantee a clean slate. - ~/.npm - - run: ENGINE_API_KEY=$CHECKS_API_KEY ./packages/apollo/bin/run client:check --tag=master + - run: ENGINE_API_KEY=$CHECKS_API_KEY ./packages/apollo/bin/run client:check workflows: version: 2 diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 8ea1648991..ff91ecd72e 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -24,7 +24,7 @@ jobs: # displayName: "npm run lint" # - script: | - # ENGINE_API_KEY=$(CHECKS_API_KEY) ./packages/apollo/bin/run client:check --tag=master + # ENGINE_API_KEY=$(CHECKS_API_KEY) ./packages/apollo/bin/run client:check # displayName: "Query Check" # - job: Linux_Node10 From 7050c9e4e64f5bac837e09e098d65ce7192dedad Mon Sep 17 00:00:00 2001 From: Trevor Scheer Date: Fri, 25 Jan 2019 12:07:29 -0800 Subject: [PATCH 5/5] Add changelog entry --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1483758400..bb606d6b4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,8 @@ ## Upcoming - +- `apollo` + - Fix configuration loading and schema tag support [#925](https://github.com/apollographql/apollo-tooling/pull/925) ## `apollo@2.3.1`