Registry /
testing / typescript-graphql-request
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.fixUpgrade 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'.fixChange '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.fixMigrate 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.fixEnsure every GraphQL operation has a unique name.
affects: all
gotchaIf using 'documentMode: external', ensure the external document path is correctly configured.fixSet '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.
fixnpm install graphql-request
TypeError: graphqlClient.request is not a function
The generated SDK expects a graphql-request client instance but received something else.
fixEnsure you pass a 'GraphQLClient' instance from 'graphql-request'.
Error: Unknown type "..."
The GraphQL schema is missing a type referenced in an operation.
fixUpdate your schema to include the missing type.
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