GraphQL Code Generator is a plugin-based tool that helps you get the best out of your GraphQL stack. From back-end to front-end, GraphQL Code Generator automates the generation of typed Queries, Mutations and, Subscriptions for React, Vue, Angular, Next.js, Svelte, whether you are using Apollo Client, URQL or, React Query.
GraphQL Code Generator is a plugin-based tool that helps you get the best out of your GraphQL stack.
From back-end to front-end, GraphQL Code Generator automates the generation of:
Typed Queries, Mutations and, Subscriptions for React, Vue, Angular, Next.js, Svelte, whether you are using Apollo Client, URQL or, React Query.
Typed GraphQL resolvers, for any Node.js (GraphQL Yoga, GraphQL Modules, TypeGraphQL or Apollo) or Java GraphQL server.
Fully-typed Node.js SDKs, Apollo Android support, and more!
The perfect GraphQL Developer Experience
To illustrate how GraphQL Code Generator improves your developer experience, let’s take a look at the front-end and back-end usage of the following schema:
<script lang="ts">
import { query } from 'svelte-apollo'
const postsQueryDocument = gql`
query Posts {
posts {
id
title
author {
id
firstName
lastName
}
}
}
`
const posts = query(postsQueryDocument)
</script>
<ul>
<!-- UI … -->
</ul>
Manually maintaining the GraphQL operation types or the complete absence of types can lead to many issues:
outdated typing (regarding the current Schema)
typos
partial typing of data (not all Schema’s fields has a corresponding type)
The strength of your frontend application types is based on your data types.
Any mistake on your manually maintained data types ripples in many of your components.
For this reason, automating and generating the typing of your GraphQL operations will both improve the developer
experience and stability of your stack.
After installing GraphQL Code Generator:
npm i graphqlnpm i -D typescript @graphql-codegen/cli
import { UsersModule } from './generated-types/module-types'export const resolvers: UsersModule.Resolvers = { // Here, you can implement only the types and fields defined in your module!}
What’s next?
After unstanding the basic concepts of GraphQL Code Generator, you can start setting it up within your project.
If your stack is not listed below, please refer to our plugin overview.
Client-Side GraphQL
Choose your existing setup or preference to get started.