Skip to content

Commit afd3c8e

Browse files
authored
Add ability to define schema download output path that doesn't exist yet (#1807)
* ability to define output path that don't exist yet * update changelog * update package-lock
1 parent e1bcf44 commit afd3c8e

6 files changed

Lines changed: 30 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
- `apollo`
66
- Update shortlinks to use go.apollo.dev instead of bitly [#1790](https://github.com/apollographql/apollo-tooling/pull/1790)
7-
- Support disabling literal stripping when extracting queries. [1703](https://github.com/apollographql/apollo-tooling/pull/1703)
87
- Fix rendering of unexpected composition errors throwing a table cell error [#1806](https://github.com/apollographql/apollo-tooling/pull/1806)
8+
- Support disabling literal stripping when extracting queries. [1703](https://github.com/apollographql/apollo-tooling/pull/1703)
9+
- Add ability to define schema download output path that doesn't exist yet [#1807](https://github.com/apollographql/apollo-tooling/pull/1807)
910
- `apollo-codegen-flow`
1011
- Add @generated comment
1112
- `apollo-codegen-scala`

package-lock.json

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"@types/lodash.pickby": "4.6.6",
7171
"@types/lodash.sortby": "4.7.6",
7272
"@types/minimatch": "3.0.3",
73+
"@types/mkdirp": "^1.0.0",
7374
"@types/nock": "10.0.3",
7475
"@types/node": "8.10.56",
7576
"@types/node-fetch": "2.5.4",

packages/apollo/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"listr": "0.14.3",
6060
"lodash.identity": "3.0.0",
6161
"lodash.pickby": "4.6.0",
62+
"mkdirp": "^1.0.3",
6263
"moment": "2.24.0",
6364
"strip-ansi": "5.2.0",
6465
"table": "5.4.6",

packages/apollo/src/commands/client/download-schema.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { flags } from "@oclif/command";
21
import { introspectionFromSchema, printSchema } from "graphql";
3-
import { writeFileSync } from "fs";
4-
52
import { ClientCommand } from "../../Command";
3+
import mkdirp from "mkdirp";
4+
import fs from "fs";
5+
import { dirname as getDirName } from "path";
66

77
export default class SchemaDownload extends ClientCommand {
88
static description =
@@ -23,8 +23,6 @@ export default class SchemaDownload extends ClientCommand {
2323
];
2424

2525
async run() {
26-
let result;
27-
let gitContext;
2826
await this.runTasks(({ args, project, flags }) => {
2927
const extension = args.output.split(".").pop();
3028
const isSDLFormat = ["graphql", "graphqls", "gql"].includes(extension);
@@ -36,7 +34,13 @@ export default class SchemaDownload extends ClientCommand {
3634
const formattedSchema = isSDLFormat
3735
? printSchema(schema)
3836
: JSON.stringify(introspectionFromSchema(schema), null, 2);
39-
writeFileSync(args.output, formattedSchema);
37+
38+
try {
39+
await mkdirp(getDirName(args.output));
40+
fs.writeFileSync(args.output, formattedSchema);
41+
} catch (err) {
42+
throw err;
43+
}
4044
}
4145
}
4246
];

packages/apollo/src/commands/service/download.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { flags } from "@oclif/command";
22
import { introspectionFromSchema } from "graphql";
3-
import { writeFileSync } from "fs";
43
import chalk from "chalk";
54
import { ProjectCommand } from "../../Command";
5+
import mkdirp from "mkdirp";
6+
import fs from "fs";
7+
import { dirname as getDirName } from "path";
68

79
export default class ServiceDownload extends ProjectCommand {
810
static aliases = ["schema:download"];
@@ -24,22 +26,22 @@ export default class ServiceDownload extends ProjectCommand {
2426
static args = [
2527
{
2628
name: "output",
27-
description: "Path to write the introspection result to",
29+
description:
30+
"Path to write the introspection result to. Supports .json output only.",
2831
required: true,
2932
default: "schema.json"
3033
}
3134
];
3235

3336
async run() {
34-
let result;
35-
let gitContext;
3637
await this.runTasks(({ args, project, flags }) => [
3738
{
3839
title: `Saving schema to ${args.output}`,
3940
task: async () => {
4041
try {
4142
const schema = await project.resolveSchema({ tag: flags.tag });
42-
writeFileSync(
43+
await mkdirp(getDirName(args.output));
44+
fs.writeFileSync(
4345
args.output,
4446
JSON.stringify(introspectionFromSchema(schema), null, 2)
4547
);

0 commit comments

Comments
 (0)