How To Auto-Generate a GraphQL Schema, Queries, Mutations, and Subscriptions from a GraphQL API Endpoint

Banner image with GraphQL Logo and written “GraphQL”

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?

  1. 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?

  1. 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!

--

--

--

A student of the world ; My brain has too many tabs open ; 🇰🇪; www.muguku.co.ke

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

The Inflexible Agile

10 Ways to Power-up Your Design System with Diez

Content Providers for Interview

How to Scale While Avoiding CI Pitfalls

Run unpublished Spark notebooks in Azure Synapse

Cover image

Industry use cases of Kubernetes

Understanding OOPS with real life examples

Top 5 Visual Studio Code Extensions for Azure

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Macharia Muguku

Macharia Muguku

A student of the world ; My brain has too many tabs open ; 🇰🇪; www.muguku.co.ke

More from Medium

Reasons To Use Web Security For Quality Protection

eb Security For Quality Protection

How we developed the secretary service to resolve tasks from hommie to business

How to manage Translations for 50+ languages?

Implementing the Indexes Element for Your Quick App