Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate graphql query from endpoint

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?

like image 671
Ruth Avatar asked Nov 30 '18 14:11

Ruth


People also ask

How do I get schema from GraphQL endpoint?

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.

How do you send a query in GraphQL?

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!"}}

Does GraphQL have endpoint?

GraphQL APIs are organized in terms of types and fields, not endpoints.


1 Answers

Have same problems. The best approach that I know for now is to:

  1. generate schema.graphql from endpoint using get-graphql-schema : https://github.com/prisma/get-graphql-schema
  2. generate queries and mutations from schema.graphql using gql-generator : https://github.com/modelo/gql-generator

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.

like image 151
Murdokai Avatar answered Oct 19 '22 18:10

Murdokai