Faster GraphQL codegen for TypeScript projects
npm install @graphql-recodegen/clinpm install -g @graphql-recodegen/clirecodegen -config=recodegen.jsonnpm install --save-dev @graphql-recodegen/cli./node_modules/.bin/recodegen -config=recodegen.jsongit clone git@github.com:poul-kg/recodegen.gitcd recodegencd cmd/recodegengo build - you'll see a binary file createdgo install - to install recodegen and be able to run it from any directory. For this to work make sure your PATH contains output from go env GOPATH command./recodegen - reads recodegen.json and tries to generate types./recodegen -config=codegen.json - can specify custom JSON file@graphql-codegen/cli JSON config formatplugins: ['typescript'] - will generate schema typesplugins: ['typescript-operations'] - will generate operationsplugins: ['typescript', 'typescript-operations']documents: like documents: "dir/.ts" it should be documents: ["dir/*.ts"]schema/backend.graphql filegenerated/schema.generated.ts file with all schema types.ts files in ./backend directory and try to extract GraphQL queries, which should be defined as``TypeScript
// backend/my-service.ts
const query = gql
query findUser($id: uuid!) {
first_name
last_name
}
;`generated/operations.ts
* Writes operations into operations.ts
will import schema types like import as Types from "./schema.generated";
recodegen.json`JSON`
{
"overwrite": true,
"schema": "schema/backend.graphql",
"generates": {
"generated/schema.generated.ts": {
"plugins": [
"typescript"
]
},
"generated/operations.ts": {
"preset": "import-types",
"presetConfig": {
"typesPath": "./schema.generated"
},
"plugins": [
"typescript-operations"
],
"documents": ["backend/*/.ts"]
}
}
}recodegen.json$3
`JSON`
{
"overwrite": true,
"schema": "schema/backend.graphql",
"generates": {
"generated/schema.generated.ts": {
"plugins": [
"typescript", "typescript-operations"
],
"documents": ["backend/*/.ts"]
}
}
}./recodegen
* - to build schema file and operations file