How To Auto-Generate a GraphQL Schema, Queries, Mutations, and Subscriptions from a GraphQL API Endpoint
1 min readOct 13, 2020
Generate GraphQL Schema From Endpoint. Generate GraphQL Queries,Mutations,Subscriptions from GraphQL Schema.
Lets cut to the chase, shall we?
a). How to download/fetch/print schema.graphql from GraphQL endpoint?
- Run get-graphql-schema remotely with npx. Replace the URL obviously 🤷🏿♂️
npx get-graphql-schema https://countries.trevorblades.com > schema.graphql
2. A file named schema.graphql is generated in your current working directory.
b). How to generate GraphQL Queries, Mutations, and Subscriptions from GraphQL Schema?
- Run gql-generator remotely with npx
npx gqlg --schemaFilePath schema.graphql --destDirPath ./queries-mutations_subscriptions --depthLimit 5
2. A folder named queries-mutations_subscriptions is created in your current working directory with queries,mutations, and subscriptions sub-folders inside
c). It’s Done!