get-graphql-schema
get-graphql-schema copied to clipboard
Allow reading schema from .json or .graphql file
This enables schema format conversions (.json <==> .graphql) without needing HTTP, which is useful if you already have the schema locally, but in the wrong format.
To convert a JSON schema to IDL format;
get-graphql-schema file:./local-schema.json
To convert a IDL schema to JSON format;
get-graphql-schema file:./local-schema.graphql --json
It's pointless to run on JSON schema with --json as this effectively just does JSON.stringify(JSON.parse(data)). To run on an IDL schema without --json, runs the introspection query on the IDL schema, and then converts that back to IDL, which is also rather pointless.
Note that relative paths in the file: protocol are non-standard, but are allowed by url.parse as long as the double slashes after the colon are also omitted. Properly formatted file:-urls also work fine;
get-graphql-schema file://$PWD/local-schema.graphql --json
As a side note, the --schema argument to relay-compiler can now take a schema in json format, but does expect the top level "data" node to be present.
This looks really useful!
Whilst this seems useful, perhaps it'd be better to have a convert-graphql-schema tool instead, which works purely on local files?