Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ vscode-apollo-*.vsix
# files generated from tests
__tmp__*
.vscode-test

#idea folder
.idea/
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- `apollo`
- Shorten `client:check` and `service:check` output in CI [#1404](https://github.com/apollographql/apollo-tooling/pull/1404)
- Add `--target=format` flag to `client:download-schema` command to download schema in desired format i.e. SDL or JSON
- `apollo-codegen-core`
- <First `apollo-codegen-core` related entry goes here>
- `apollo-codegen-flow`
Expand Down
2 changes: 2 additions & 0 deletions packages/apollo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ OPTIONS

--tagName=tagName Name of the template literal tag used to identify template literals containing
GraphQL queries in Javascript/Typescript code

--target=format Format of schema to be downloaded. Currenlty supporting SDL & JSON
Comment thread
essaji marked this conversation as resolved.
Outdated
```

_See code: [src/commands/client/download-schema.ts](https://github.com/apollographql/apollo-tooling/blob/master/packages/apollo/src/commands/client/download-schema.ts)_
Expand Down
40 changes: 24 additions & 16 deletions packages/apollo/src/commands/client/download-schema.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { flags } from "@oclif/command";
import { introspectionFromSchema } from "graphql";
import { introspectionFromSchema, printSchema } from "graphql";
import { writeFileSync } from "fs";

import { ClientCommand } from "../../Command";
Expand All @@ -8,32 +8,40 @@ export default class SchemaDownload extends ClientCommand {
static description = "Download a schema from engine or a GraphQL endpoint.";

static flags = {
...ClientCommand.flags
...ClientCommand.flags,

target: flags.string({
description:
"Format of schema to be downloaded i.e. JSON or SDL. Default is JSON"
Comment thread
essaji marked this conversation as resolved.
Outdated
})
};

static args = [
{
name: "output",
description: "Path to write the introspection result to",
required: true,
default: "schema.json"
description: "Path to write the introspection result to"
}
];

async run() {
let result;
let gitContext;
await this.runTasks(({ args, project, flags }) => [
{
title: `Saving schema to ${args.output}`,
task: async () => {
const schema = await project.resolveSchema({ tag: flags.tag });
writeFileSync(
args.output,
JSON.stringify(introspectionFromSchema(schema), null, 2)
);
await this.runTasks(({ args, project, flags }) => {
const isSDLFormat = flags.target && flags.target.toUpperCase() === "SDL";
const output =
args.output || (isSDLFormat ? "schema.graphql" : "schema.json");
return [
{
title: `Saving schema to ${output}`,
task: async () => {
const schema = await project.resolveSchema({ tag: flags.tag });
const formattedSchema = isSDLFormat
? printSchema(schema)
: JSON.stringify(introspectionFromSchema(schema), null, 2);
writeFileSync(output, formattedSchema);
}
}
}
]);
];
});
}
}