From ff4a36b0dc05eb4554a3664a87e081eed2a3bb2e Mon Sep 17 00:00:00 2001 From: Chris Hua Date: Sun, 13 Aug 2023 13:35:01 -0400 Subject: [PATCH] fix: lint + ci --- RELEASE.md | 3 +++ strawberry/cli/commands/export_schema.py | 2 +- tests/cli/test_export_schema.py | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 RELEASE.md diff --git a/RELEASE.md b/RELEASE.md new file mode 100644 index 0000000000..2bd434b93d --- /dev/null +++ b/RELEASE.md @@ -0,0 +1,3 @@ +Release type: minor + +Adds a new flag to `export-schema` command, `--output`, which allows the user to specify the output file. If unset (current behavior), the command will continue to print to stdout. \ No newline at end of file diff --git a/strawberry/cli/commands/export_schema.py b/strawberry/cli/commands/export_schema.py index 7daaed8e9b..651542c067 100644 --- a/strawberry/cli/commands/export_schema.py +++ b/strawberry/cli/commands/export_schema.py @@ -30,7 +30,7 @@ def export_schema( schema_text = print_schema(schema_symbol) if output: - with open(output, "w") as file: + with Path.open(output, "w") as file: file.write(schema_text) typer.echo(f"Schema exported to {output}") else: diff --git a/tests/cli/test_export_schema.py b/tests/cli/test_export_schema.py index f12c14c4c4..418f0bd486 100644 --- a/tests/cli/test_export_schema.py +++ b/tests/cli/test_export_schema.py @@ -67,3 +67,20 @@ def test_invalid_schema_instance(cli_app: Typer, cli_runner: CliRunner): assert result.exit_code == 2 assert expected_error in result.stdout.replace("\n", "") + +def test_output_option(cli_app: Typer, cli_runner: CliRunner, tmp_path): + selector = "tests.fixtures.sample_package.sample_module:schema" + output = tmp_path / "schema.graphql" + result = cli_runner.invoke(cli_app, ["export-schema", selector, "--output", str(output)]) + + assert result.exit_code == 0 + assert output.read_text() == ( + "type Query {\n" + " user: User!\n" + "}\n" + "\n" + "type User {\n" + " name: String!\n" + " age: Int!\n" + "}" + ) \ No newline at end of file