I would like to build a script that generates an example query with all fields from a GraphQL endpoint.
I found some mechanisms to get the schema as a JSON structure and to adapt the schema files to a query. but nothing takes an endpoint and provides a suitable query for that endpoint.
Does someone have any experience in that?
How To Get The Schema — Introspection Queries. Some GraphQL servers don't provide a convenient GraphQL API explorer. Instead, to get the schema we need to send a HTTP request to the GraphQL server endpoint asking for the GraphQL schema. This type of HTTP request is called a GraphQL introspection query.
With express-graphql , you can just send an HTTP POST request to the endpoint you mounted your GraphQL server on, passing the GraphQL query as the query field in a JSON payload. You should see the output returned as JSON: {"data":{"hello":"Hello world!"}}
GraphQL APIs are organized in terms of types and fields, not endpoints.
Have same problems. The best approach that I know for now is to:
There was a tool that claimed to "generate queries from endpoint", but I wasn't able to make it working in my case, and now I can't even find it, but it was called "gql-test" and I still have it installed in npm.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With