A GraphQL query builder v5.1.2 that replaces string-based `gql` queries or `.graphql` files with pure TypeScript code generation. It generates `TypedDocumentNode` objects compatible with Apollo Client, Urql, graphql-request, and any other library supporting `TypedDocumentNode`. Unlike code-first approaches like GraphQL Code Generator, this library provides a fully typed builder API that reduces boilerplate and catches errors at compile time. The generated API uses a functional, composable syntax with automatic variable type inference via the `$` and `$$` helpers. Released under MIT, updated frequently with breaking changes in major versions.
npm install typed-graphql-builderNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Generates a typed query from a GraphQL schema and uses it with Apollo Client's useQuery hook.
Upgrade Node.js to 18+ and regenerate the API with npx typed-graphql-builder.
Migrate to the builder pattern as shown in the documentation.
Use `$$('varName')` when the variable must be non-null.Regenerate API with v4 CLI and update imports to use `query` from './generated-api'.
Run `npx typed-graphql-builder --schema <schema> --output generated-api.ts` and ensure the output file is included in your project.
Use `import type { TypedDocumentNode } from '@graphql-typed-document-node/core'`.Check the schema fields and the builder signature: each selection must be inside a callback that returns an array of selected fields.
Use `$$('varName')` to enforce non-null or add a check at consumption.