diff --git a/packages/apollo/src/Command.ts b/packages/apollo/src/Command.ts index 0481c875e6..42a4b00aa4 100644 --- a/packages/apollo/src/Command.ts +++ b/packages/apollo/src/Command.ts @@ -26,8 +26,19 @@ export interface ProjectContext { args: Args; } +export interface Flags { + config?: string; + header?: string[]; + endpoint?: string; + localSchemaFile?: string; + key?: string; + engine?: string; + frontend?: string; + tag?: string; +} + const headersArrayToObject = ( - arr: string[] + arr?: string[] ): Record | undefined => { if (!arr) return; return arr @@ -96,7 +107,7 @@ export abstract class ProjectCommand extends Command { }); } - protected async createConfig(flags: any) { + protected async createConfig(flags: Flags) { let service; if (process.env.ENGINE_API_KEY) service = getServiceFromKey(process.env.ENGINE_API_KEY); @@ -128,6 +139,24 @@ export abstract class ProjectCommand extends Command { }); } + if (flags.localSchemaFile) { + if (isClientConfig(config)) { + config.setDefaults({ + client: { + service: { + localSchemaFile: flags.localSchemaFile + } + } + }); + } else if (isServiceConfig(config)) { + config.setDefaults({ + service: { + localSchemaFile: flags.localSchemaFile + } + }); + } + } + // load per command type defaults; if (this.configMap) { const defaults = this.configMap(flags); @@ -137,7 +166,11 @@ export abstract class ProjectCommand extends Command { return { config, filepath, isEmpty }; } - protected createService(config: ApolloConfig, filepath: string, flags: any) { + protected createService( + config: ApolloConfig, + filepath: string, + flags: Flags + ) { const loadingHandler = new OclifLoadingHandler(this); const rootURI = `file://${parse(filepath).dir}`; const clientIdentity = { diff --git a/packages/apollo/src/commands/client/codegen.ts b/packages/apollo/src/commands/client/codegen.ts index 304f51855f..5ccfefbab5 100644 --- a/packages/apollo/src/commands/client/codegen.ts +++ b/packages/apollo/src/commands/client/codegen.ts @@ -44,6 +44,10 @@ export default class Generate extends ClientCommand { "Type of code generator to use (swift | typescript | flow | scala), inferred from output", required: true }), + localSchemaFile: flags.string({ + description: + "Path to your local GraphQL schema file (introspection result or SDL)" + }), addTypename: flags.boolean({ description: "Automatically add __typename to your queries", default: true diff --git a/packages/apollo/src/commands/client/extract.ts b/packages/apollo/src/commands/client/extract.ts index f90b8c3e42..9851d56d02 100644 --- a/packages/apollo/src/commands/client/extract.ts +++ b/packages/apollo/src/commands/client/extract.ts @@ -22,8 +22,8 @@ const engineSignature = (_TODO_operationAST: DocumentNode): string => { return engineDefaultSignature(_TODO_operationAST, "TODO"); }; -export default class ServicePush extends ClientCommand { - static description = "Push a service to Engine"; +export default class ClientExtract extends ClientCommand { + static description = "Extract queries from a client"; static flags = { ...ClientCommand.flags }; diff --git a/packages/apollo/src/commands/service/push.ts b/packages/apollo/src/commands/service/push.ts index 3239200132..0d1fa336c5 100644 --- a/packages/apollo/src/commands/service/push.ts +++ b/packages/apollo/src/commands/service/push.ts @@ -12,8 +12,12 @@ export default class ServicePush extends ProjectCommand { ...ProjectCommand.flags, tag: flags.string({ char: "t", - description: "The published tag to check this service against", + description: "The tag to publish this service to", default: "current" + }), + localSchemaFile: flags.string({ + description: + "Path to your local GraphQL schema file (introspection result or SDL)" }) }; @@ -27,6 +31,7 @@ export default class ServicePush extends ProjectCommand { if (!config.name) { throw new Error("No service found to link to Engine"); } + const schema = await project.resolveSchema({ tag: flags.tag }); gitContext = await gitInfo();