Skip to content

Commit 09d4f53

Browse files
committed
feat: custom file path for static schemas
1 parent fe5e89c commit 09d4f53

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

cli/wp-cli.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,36 @@ class WPGraphQL_CLI_Command extends WP_CLI_Command {
1212
* Defaults to creating a schema.graphql file in the IDL format at the root
1313
* of the plugin.
1414
*
15-
* @todo: Provide alternative formats (AST? INTROSPECTION JSON?) and options for output location/file-type?
15+
* [--output=<output>]
16+
* : The file path to save the schema to.
17+
*
18+
* @todo: Provide alternative formats (AST? INTROSPECTION JSON?) and options for output file-type?
1619
* @todo: Add Unit Tests
1720
*
1821
* ## EXAMPLE
1922
*
23+
* # Generate a static schema
2024
* $ wp graphql generate-static-schema
2125
*
26+
* # Generate a static schema and save it to a specific file
27+
* $ wp graphql generate-static-schema --output=/path/to/file.graphql
28+
*
2229
* @alias generate
2330
* @subcommand generate-static-schema
2431
*/
2532
public function generate_static_schema( $args, $assoc_args ) {
2633

27-
/**
28-
* Set the file path for where to save the static schema
29-
*/
30-
$file_path = get_temp_dir() . 'schema.graphql';
34+
// Check if the output flag is set
35+
if ( isset( $assoc_args['output'] ) ) {
36+
// Check if the output file path is writable and its parent directory exists
37+
if ( ! is_writable( dirname( $assoc_args['output'] ) ) ) {
38+
WP_CLI::error( 'The output file path is not writable or its parent directory does not exist.' );
39+
return;
40+
}
41+
$file_path = $assoc_args['output'];
42+
} else {
43+
$file_path = get_temp_dir() . 'schema.graphql';
44+
}
3145

3246
if ( ! defined( 'GRAPHQL_REQUEST' ) ) {
3347
define( 'GRAPHQL_REQUEST', true );

0 commit comments

Comments
 (0)