Registry / devops / graphql-typed-client

graphql-typed-client

JSON →
library1.7.4jsnpmunverified

A code generation tool that produces a strongly typed GraphQL client library for any endpoint. Version 1.7.4 is the latest stable release. It enables writing GraphQL queries as plain JavaScript objects with full TypeScript type safety, auto-completion, custom scalar mapping, and type guards. The client supports chain request syntax and raw request syntax, generating standard GraphQL queries from idiomatic JS. Unlike generic GraphQL clients (e.g., graphql-request), this package generates a tailored client per schema, offering superior developer experience for TypeScript projects. Maintenance appears low, with the last release in 2020.

npm install graphql-typed-client
INSTALL
IMPORT
SIG · GRAPHQL-TYPED-CLIE
G
graphql-typed-client
devopsjavascriptv1.7.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

generateClient
import { generateClient } from 'graphql-typed-client'
const { generateClient } = require('graphql-typed-client')
The library supports both ESM and CJS via the 'require' call shown.
default export (generated client instance)
import client from './generated/client'
const client = require('./generated/client').default
The generated client file exports a default instance. With CJS, you need to access .default.
types (Query, Mutation, etc.)
import { Query, Mutation } from './generated/client'
import { Query, Mutation } from 'graphql-typed-client'
Types are auto-generated and reside in the output directory, not the library itself.
Debug
Known issues
breakingThe generated client is ESM-only. If your project uses CommonJS, you may need to configure transpilation.
fix
Use TypeScript's moduleResolution: 'node' or add a bundler that handles ESM.
affects: >=1.0.0
deprecatedThe CLI tool 'generate-graphql-client' is deprecated in favor of using the programmatic API via generateClient()
fix
Use the function export directly in a script instead of the CLI command.
affects: >=1.0.0
gotchaIf using 'fetcher' option, the function must return a Promise resolving to the introspection result; otherwise the generation may fail silently.
fix
Ensure your fetcher returns a Promise and logs errors on failure.
affects: >=1.0.0
gotchaCustom scalar types must be mapped in the config file; by default they are treated as 'any'.
fix
Define scalarTypeMap in the config to map scalars to actual types.
affects: >=1.0.0
breakingThe generated client uses 'qs' for query string parameters; if not available, introspection requests may fail.
fix
Install 'qs' as a dependency or provide a custom fetcher that handles query string manually.
affects: >=1.0.0
deprecatedThe 'schema' option as a glob pattern may not work on Windows due to path separator issues.
fix
Use forward slashes or an array of file paths via a config file.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'graphql-typed-client'
The package is not installed globally or locally for the generation step.
fix
Run 'npm install -g graphql-typed-client' for CLI, or 'npm install graphql-typed-client' in your project.
TypeError: generateClient is not a function
Using CommonJS require in an ESM-only context or incorrect import path.
fix
Use 'const { generateClient } = require('graphql-typed-client')' for CommonJS, or import { generateClient } from 'graphql-typed-client' for ESM.
Error: introspection query failed: Unexpected token < in JSON
The endpoint URL returned HTML (e.g., authentication redirect) instead of JSON.
fix
Check the endpoint URL and authentication; use a custom fetcher with proper headers.
TypeError: qs is not a function
The 'qs' module is not installed or not passed correctly to the fetcher.
fix
Install 'qs' or use a custom fetcher that doesn't rely on it.
Error: No valid clients to generate
The config file is empty or malformed.
fix
Ensure the config exports an array of client objects or a single valid object.
Upgrade
Version history
1.7.4latest on npm
Audit
Dependencies
graphqlrequiredPeer dependency for schema parsing and query generation
Agent activity
6 hits · last 30 days
node
6
Resources