{"id":47961,"library":"graphql-ts-client-api","title":"graphql-ts-client-api","description":"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.","status":"active","version":"3.1.17","language":"javascript","source_language":"en","source_url":"https://github.com/babyfish-ct/graphql-ts-client","tags":["javascript","typescript"],"install":[{"cmd":"npm install graphql-ts-client-api","lang":"bash","label":"npm"},{"cmd":"yarn add graphql-ts-client-api","lang":"bash","label":"yarn"},{"cmd":"pnpm add graphql-ts-client-api","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Runtime dependency for parsing and validating GraphQL documents.","package":"graphql","optional":false}],"imports":[{"note":"ESM-only since v3; use ESM import for type safety.","wrong":"const { createFetcher } = require('graphql-ts-client-api');","symbol":"createFetcher","correct":"import { createFetcher } from 'graphql-ts-client-api';"},{"note":"Type import recommended to avoid runtime overhead.","wrong":"import { RequestHeaders } from 'graphql-ts-client-api';","symbol":"RequestHeaders","correct":"import type { RequestHeaders } from 'graphql-ts-client-api';"},{"note":"Default export provides a pre-configured client; custom configurations require named imports.","wrong":"import client from 'graphql-ts-client-api';\n// Wrong when using named exports for types","symbol":"default as client","correct":"import client from 'graphql-ts-client-api';"},{"note":"Use type-only import for interfaces to avoid bundling issues.","wrong":"import { GraphQLRequest } from 'graphql-ts-client-api';","symbol":"GraphQLRequest","correct":"import type { GraphQLRequest } from 'graphql-ts-client-api';"}],"quickstart":{"code":"import { createFetcher } from 'graphql-ts-client-api';\nimport fetch from 'node-fetch'; // or global fetch in modern Node/Deno\n\nconst fetcher = createFetcher({\n    url: 'https://api.example.com/graphql',\n    headers: {\n        Authorization: `Bearer ${process.env.API_KEY ?? ''}`,\n    },\n    fetch: fetch,\n});\n\nasync function runQuery() {\n    const data = await fetcher({\n        query: `\n            query GetUser($id: ID!) {\n                user(id: $id) {\n                    name\n                    email\n                }\n            }\n        `,\n        variables: { id: '123' },\n    });\n    console.log(data);\n}\n\nrunQuery();","lang":"typescript","description":"Shows creating a fetcher with custom URL, auth headers, and executing a GraphQL query with variables."},"warnings":[{"fix":"Replace import client from 'graphql-ts-client-api' with import { createFetcher } from 'graphql-ts-client-api'.","message":"In v3.x, the default export no longer works; you must use named exports like createFetcher.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Replace createClient with createFetcher in your code.","message":"The function createClient is deprecated since v3. Use createFetcher instead.","severity":"deprecated","affected_versions":">=3.0.0"},{"fix":"Use `import type { RequestHeaders } from 'graphql-ts-client-api'` instead of value import.","message":"When using TypeScript, always import types with `import type` to avoid bundling the entire library.","severity":"gotcha","affected_versions":"*"},{"fix":"Install node-fetch or use global fetch in Node 18+, and pass it to createFetcher via the `fetch` option.","message":"The package expects `fetch` to be globally available or explicitly provided. In older Node.js versions, you must pass a fetch polyfill.","severity":"gotcha","affected_versions":"*"},{"fix":"Always use static string literals for queries, or use a .graphql file loader.","message":"GraphQL documents must be string literals; using template literals with expressions may cause runtime errors due to parsing.","severity":"gotcha","affected_versions":"*"},{"fix":"Provide a fetch implementation explicitly when calling createFetcher.","message":"In v2.x, the package bundled its own fetch; in v3.x, the fetch implementation is externalized.","severity":"breaking","affected_versions":">=3.0.0"}],"env_vars":null,"search_vec":"'api':5,10 'approach':19 'automat':25 'axio':61 'build':68 'cjs':51 'client':4,9,22,57,79 'code':17,82 'code-first':16 'compil':34,80 'compile-tim':33 'differenti':63 'enabl':32 'esm':49 'fetch':59 'first':18 'generat':26,83 'graphql':2,7,21,30,77 'graphql-ts-client-api':1,6 'graphql-ts-client-compil':76 'http':56 'integr':53,74 'javascript':84 'key':62 'like':58 'mutat':39 'npm':45 'overhead':71 'popular':55 'provid':12 'queri':38,67 'regular':43 'releas':42 'runtim':70 'safe':66 'safeti':36 'schema':31 'seamless':73 'strong':14 'subscript':41 'support':47 'time':35 'ts':3,8,78 'type':15,28,65 'type-saf':64 'typescript':27,85 'typescript/javascript':24 'v3.1.17':11 'via':44 'zero':69","created_at":"2026-06-07T16:54:12.882143+00:00","updated_at":"2026-06-07T16:54:12.882143+00:00","problems":[{"fix":"Use named export: import { createFetcher } from 'graphql-ts-client-api'; then call createFetcher(...).","cause":"Using default export incorrectly in v3+.","error":"TypeError: fetcher is not a function"},{"fix":"Install node-fetch and pass it: createFetcher({ url: '...', fetch: require('node-fetch') })","cause":"No global fetch available in Node.js < 18.","error":"Error: fetch is not defined"},{"fix":"Ensure the object has a `query` string property: fetcher({ query: '...', variables: { ... } })","cause":"Passing an object with missing query field to fetcher.","error":"TypeError: Cannot read properties of undefined (reading 'query')"},{"fix":"Run `npm install graphql-ts-client-api` and use `const { createFetcher } = require('graphql-ts-client-api');`","cause":"Package not installed or wrong import path in CJS project.","error":"Module not found: Can't resolve 'graphql-ts-client-api'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/babyfish-ct/graphql-ts-client","github":"https://github.com/babyfish-ct/graphql-ts-client","docs":null,"changelog":null,"pypi":null,"npm":"graphql-ts-client-api","openapi_spec":null,"status_page":null,"smithery":null,"categories":["api"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}