| name | graphql-codegen |
| description | Generate TypeScript types and React hooks from GraphQL schemas |
| sasmp_version | 1.3.0 |
| bonded_agent | 07-graphql-codegen |
| bond_type | PRIMARY_BOND |
| version | 2.0.0 |
| complexity | intermediate |
| estimated_time | 2-4 hours |
| prerequisites | ["graphql-fundamentals"] |
GraphQL Code Generator Skill
Type-safe GraphQL with automatic code generation
Overview
Learn to use GraphQL Code Generator to automatically generate TypeScript types, React hooks, and more from your GraphQL schema and operations.
Quick Reference
| Plugin | Generates | Use Case |
|---|
typescript | Base types | All projects |
typescript-operations | Query/mutation types | All projects |
typescript-react-apollo | React hooks | React + Apollo |
typescript-urql | URQL hooks | React + URQL |
introspection | Schema JSON | Apollo Client |
Setup
1. Installation
npm install -D @graphql-codegen/cli \
@graphql-codegen/typescript \
@graphql-codegen/typescript-operations \
@graphql-codegen/typescript-react-apollo \
@parcel/watcher
2. Configuration
import type { CodegenConfig } from '@graphql-codegen/cli';
const config: CodegenConfig = {
schema: 'http://localhost:4000/graphql',
documents: ['src/**/*.graphql', 'src/**/*.tsx'],
generates: {
'./src/generated/graphql.ts': {
plugins: [
'typescript',
'typescript-operations',
,
],
: {
: {
: ,
: ,
},
: ,
: ,
},
},
},
};
config;