Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support localSchemaFile flag to push to a service from local schema #710

Merged
merged 4 commits into from
Nov 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 36 additions & 3 deletions packages/apollo/src/Command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,19 @@ export interface ProjectContext<Flags = any, Args = any> {
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<string, string> | undefined => {
if (!arr) return;
return arr
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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 = {
Expand Down
4 changes: 4 additions & 0 deletions packages/apollo/src/commands/client/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/apollo/src/commands/client/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down
7 changes: 6 additions & 1 deletion packages/apollo/src/commands/service/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
})
};

Expand All @@ -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();

Expand Down