prisma-labs / get-graphql-schema

Fetch and print the GraphQL schema from a GraphQL HTTP endpoint. (Can be used for Relay Modern.)
669 stars 62 forks source link

Allow reading schema from .json or .graphql file #15

Open marhel opened 7 years ago

marhel commented 7 years ago

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
marhel commented 7 years ago

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.

fbartho commented 6 years ago

This looks really useful!

ThisIsMissEm commented 6 years ago

Whilst this seems useful, perhaps it'd be better to have a convert-graphql-schema tool instead, which works purely on local files?