Registry / api / graphql-ts-client-api

graphql-ts-client-api

JSON →
library3.1.17jsnpmunverified

Graphql-ts-client-api (v3.1.17) provides a strongly typed, code-first approach for GraphQL clients in TypeScript/JavaScript. Automatically generates TypeScript types from GraphQL schema, enabling compile-time safety for queries, mutations, and subscriptions. Released regularly via npm, it supports both ESM and CJS, and integrates with popular HTTP clients like fetch and axios. Key differentiators: type-safe query building, zero runtime overhead, and seamless integration with graphql-ts-client-compiler for code generation.

npm install graphql-ts-client-api
INSTALL
IMPORT
SIG · GRAPHQL-TS-CLIENT-
G
graphql-ts-client-api
apijavascriptv3.1.17
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.

createFetcher
✓ import { createFetcher } from 'graphql-ts-client-api';
✗ const { createFetcher } = require('graphql-ts-client-api');
ESM-only since v3; use ESM import for type safety.
RequestHeaders
✓ import type { RequestHeaders } from 'graphql-ts-client-api';
✗ import { RequestHeaders } from 'graphql-ts-client-api';
Type import recommended to avoid runtime overhead.
default as client
✓ import client from 'graphql-ts-client-api';
✗ import client from 'graphql-ts-client-api'; // Wrong when using named exports for types
Default export provides a pre-configured client; custom configurations require named imports.
GraphQLRequest
✓ import type { GraphQLRequest } from 'graphql-ts-client-api';
✗ import { GraphQLRequest } from 'graphql-ts-client-api';
Use type-only import for interfaces to avoid bundling issues.

Shows creating a fetcher with custom URL, auth headers, and executing a GraphQL query with variables.

import { createFetcher } from 'graphql-ts-client-api'; import fetch from 'node-fetch'; // or global fetch in modern Node/Deno const fetcher = createFetcher({ url: 'https://api.example.com/graphql', headers: { Authorization: `Bearer ${process.env.API_KEY ?? ''}`, }, fetch: fetch, }); async function runQuery() { const data = await fetcher({ query: ` query GetUser($id: ID!) { user(id: $id) { name email } } `, variables: { id: '123' }, }); console.log(data); } runQuery();
Debug
Known issues
breakingIn v3.x, the default export no longer works; you must use named exports like createFetcher.
fix
Replace import client from 'graphql-ts-client-api' with import { createFetcher } from 'graphql-ts-client-api'.
affects: >=3.0.0
deprecatedThe function createClient is deprecated since v3. Use createFetcher instead.
fix
Replace createClient with createFetcher in your code.
affects: >=3.0.0
gotchaWhen using TypeScript, always import types with `import type` to avoid bundling the entire library.
fix
Use `import type { RequestHeaders } from 'graphql-ts-client-api'` instead of value import.
affects: *
gotchaThe package expects `fetch` to be globally available or explicitly provided. In older Node.js versions, you must pass a fetch polyfill.
fix
Install node-fetch or use global fetch in Node 18+, and pass it to createFetcher via the `fetch` option.
affects: *
gotchaGraphQL documents must be string literals; using template literals with expressions may cause runtime errors due to parsing.
fix
Always use static string literals for queries, or use a .graphql file loader.
affects: *
breakingIn v2.x, the package bundled its own fetch; in v3.x, the fetch implementation is externalized.
fix
Provide a fetch implementation explicitly when calling createFetcher.
affects: >=3.0.0
Errors
Common errors & fixes
TypeError: fetcher is not a function
Using default export incorrectly in v3+.
fix
Use named export: import { createFetcher } from 'graphql-ts-client-api'; then call createFetcher(...).
Error: fetch is not defined
No global fetch available in Node.js < 18.
fix
Install node-fetch and pass it: createFetcher({ url: '...', fetch: require('node-fetch') })
TypeError: Cannot read properties of undefined (reading 'query')
Passing an object with missing query field to fetcher.
fix
Ensure the object has a `query` string property: fetcher({ query: '...', variables: { ... } })
Module not found: Can't resolve 'graphql-ts-client-api'
Package not installed or wrong import path in CJS project.
fix
Run `npm install graphql-ts-client-api` and use `const { createFetcher } = require('graphql-ts-client-api');`
Upgrade
Version history
3.1.17latest on npm
Audit
Dependencies
graphqlrequiredRuntime dependency for parsing and validating GraphQL documents.
Agent activity
40 hits · last 30 days
node
36
OpenAI (training)
1
Resources
graphql-ts-client-api — npm install graphql-ts-client-api · libregistry