Registry / testing / typescript-graphql-request

typescript-graphql-request

JSON →
library4.4.6jsnpmunverified

A GraphQL Code Generator plugin that automatically generates a fully typed SDK from your GraphQL operations and schema. The generated SDK wraps graphql-request client with typed query/mutation functions, reducing boilerplate and eliminating runtime errors from mismatched variables. Current stable version 4.4.6 requires graphql-request ^3.4.0 or ^4.0.0. Released under the GraphQL Code Generator ecosystem with frequent updates. Key differentiator: it provides end-to-end type safety from schema to API calls, with zero runtime overhead compared to manually written graphql-request calls.

npm install typescript-graphql-request
INSTALL
IMPORT
SIG · TYPESCRIPT-GRAPHQL
T
typescript-graphql-request
testingjavascriptv4.4.6
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.

default
import { getSdk } from './generated/graphql';
import getSdk from './generated/graphql';
The generated SDK exports a named function 'getSdk', not a default export.
Sdk
import type { Sdk } from './generated/graphql';
import { Sdk } from './generated/graphql';
Sdk is a type-only export. Import it with 'import type' in TypeScript to avoid runtime import.
Require
const { getSdk } = require('./generated/graphql');
const getSdk = require('./generated/graphql');
In CommonJS, destructure the named export. Do not assign the whole module to getSdk.

Configures GraphQL Code Generator to produce a typed SDK, then uses it to make a typed query.

// codegen.yml schema: './schema.graphql' documents: './src/**/*.graphql' generates: ./src/generated/graphql.ts: plugins: - typescript - typescript-operations - typescript-graphql-request config: documentVariablePrefix: '' documentVariableSuffix: '' // After codegen, use the SDK import { GraphQLClient } from 'graphql-request'; import { getSdk } from './generated/graphql'; const client = new GraphQLClient(process.env.GRAPHQL_ENDPOINT ?? '', { headers: { Authorization: `Bearer ${process.env.AUTH_TOKEN ?? ''}` }, }); const sdk = getSdk(client); async function main() { const { user } = await sdk.getUser({ id: '123' }); console.log(user.name); }
Debug
Known issues
breakingRequires graphql-request v3.4.0+ or v4.0.0+. Using older versions will cause runtime errors.
fix
Upgrade graphql-request to ^3.4.0 or ^4.0.0.
affects: <3.4.0 || >=5.0.0
breakingDefault export removed in v3.0.0. Must use named export 'getSdk'.
fix
Change 'export default getSdk' to 'export const { getSdk }' in generated file or update imports.
affects: >=3.0.0
deprecatedGraphQL Code Generator v2 plugin syntax is deprecated in v3. Use the 'codegen.yml' format with 'plugins' array.
fix
Migrate from 'codegen.yaml' with 'generates...' to the new 'plugins' array syntax.
affects: >=3.0.0
gotchaGenerated query/mutation method names are based on operation names in your .graphql files. Duplicate operation names cause runtime errors.
fix
Ensure every GraphQL operation has a unique name.
affects: all
gotchaIf using 'documentMode: external', ensure the external document path is correctly configured.
fix
Set 'documentMode: string' in config to avoid path resolution issues.
affects: >=4.0.0
Errors
Common errors & fixes
Cannot find module 'graphql-request'
graphql-request is not installed or not in node_modules.
fix
npm install graphql-request
TypeError: graphqlClient.request is not a function
The generated SDK expects a graphql-request client instance but received something else.
fix
Ensure you pass a 'GraphQLClient' instance from 'graphql-request'.
Error: Unknown type "..."
The GraphQL schema is missing a type referenced in an operation.
fix
Update your schema to include the missing type.
Upgrade
Version history
4.4.6latest on npm
Audit
Dependencies
graphqlrequiredRuntime peer dependency for GraphQL language support
graphql-requestrequiredRuntime peer dependency; the generated SDK uses graphql-request client for HTTP requests
graphql-tagrequiredRuntime peer dependency for parsing GraphQL operation strings
Agent activity
13 hits · last 30 days
node
12
Resources
typescript-graphql-request — npm install typescript-graphql-request · libregistry