relay icon indicating copy to clipboard operation
relay copied to clipboard

Idea: Create a GraphQL Schema Introspector?

Open ianstormtaylor opened this issue 10 years ago • 6 comments

Part of the reason the Babel plugin setup was so complicated was also the need to write a separate script for saving the schema.json file yourself. I was confused at first as to how to obtain the schema to introspect it, but then realized that the current Relay example repo only works if you happen to be running the GraphQL server and your frontend from the same service (or have another way of sharing your schema as a package).

In my case, the server is a separate service from the frontend app, so sharing the code is inconvenient. And this seems like a good default case to optimize for, since even when the server isn't separate, people would still be able to introspect it over HTTP.

Since the __schema introspection is available to all GraphQL API implementations, it would be nice if there was a simple CLI that would fetch the introspection JSON for you, provided a url. Like so:

$ graphql-introspector http://localhost:3000/graphql > ./support/schema.json

That would make the 99% use case a lot simpler. Paired with the simpler Babel plugin setup, that whole step could be reduced to a few commands and adding a few lines to .babelrc. Which would make getting up and running with Relay a lot faster.

ianstormtaylor avatar Feb 10 '16 23:02 ianstormtaylor

I was looking for exactly same, since right now it is plain code duplication. You need to define schema in backend and frontend, if you use different languages for it.

dev-rkoshlyak avatar Feb 14 '16 20:02 dev-rkoshlyak

That's a very good idea. The GraphQL introspection query is available in all GraphQL packages as a global variable.

In the ruby package is available at GraphQL::Introspection::INTROSPECTION_QUERY

For the npm package is available at require('graphql/utilities').introspectionQuery. It should be straigth forward to build a CLI utility by making an http post with the introspection query as the query parameter.

guzart avatar Feb 15 '16 02:02 guzart

The difficulty here is that this tool would then have to work with http proxies, firewalls, etc. Rather than build and maintain a module just to make an HTTP request, perhaps GraphQL servers themselves should expose the results of the standard introspection query directly (via a configurable URL?)

Cc @leebyron

josephsavona avatar Feb 15 '16 03:02 josephsavona

@VolodymyrTkachuk

dev-rkoshlyak avatar Feb 16 '16 09:02 dev-rkoshlyak

@josephsavona I like the idea that the GraphQL server exposes the whole schema on an endpoint. Are there any possible downsides to this? I guess this could also be implemented by a external (express) library for now?

schickling avatar Feb 21 '16 11:02 schickling

Closing due to inactivity - as discussed above, it should be easy to create an endpoint that returns the results of the introspection query.

josephsavona avatar May 10 '16 16:05 josephsavona