Registry / api / graphql-client

graphql-client

JSON →
library2.0.1jsnpmunverified

A lightweight HTTP client for GraphQL APIs built on the fetch API with isomorphic-fetch for cross-environment support. Current stable version is 2.0.1, with no recent release activity (last updated years ago). It provides a simple promise-based interface for executing queries and mutations, with built-in error handling that includes query location highlighting. Simpler than Apollo or Relay, but lacks subscriptions, caching, and active maintenance. Suitable for minimal integrations in Node.js or browsers where a full-fledged client is overkill.

npm install graphql-client
INSTALL
IMPORT
SIG · GRAPHQL-CLIENT
G
graphql-client
apijavascriptv2.0.1
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 export
import client from 'graphql-client'
import { client } from 'graphql-client'
The module exports a factory function as default. Named imports will not work.
require
const client = require('graphql-client')
const { client } = require('graphql-client')
CommonJS usage requires the entire module export.
TypeScript types
import type { ClientOptions, Client } from 'graphql-client'
import { ClientOptions } from 'graphql-client'
If using TypeScript, use import type for types to avoid runtime errors. The package does not ship its own types; this assumes you have @types/graphql-client or a local declaration.

Demonstrates creating a client with URL and headers, then executing a query with variables.

import client from 'graphql-client'; const { query, mutate } = client({ url: process.env.GRAPHQL_URL ?? 'https://api.example.com/graphql', headers: { Authorization: `Bearer ${process.env.AUTH_TOKEN ?? ''}` } }); query(` query getUser($id: ID!) { user(id: $id) { name email } } `, { id: '123' }) .then(data => console.log(data)) .catch(err => console.error(err.message));
Debug
Known issues
deprecatedisomorphic-fetch is outdated; consider using cross-fetch or native fetch in Node.js 18+.
fix
Replace isomorphic-fetch with cross-fetch or remove polyfill if using Node 18+.
affects: >=2.0.0
gotchaErrors are thrown with a message and query highlight string; catch them to prevent unhandled rejections.
fix
Always attach a .catch() handler or use async/await with try/catch.
affects: >=1.0.0
gotchaThe client factory returns an object with query and mutate functions, not a class instance.
fix
Destructure { query, mutate } from the factory call.
affects: >=2.0.0
deprecatedThe package has not been updated in years; there may be unfixed security issues in dependencies.
fix
Consider using a maintained alternative like graphql-request or Apollo Client.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: client is not a function
Importing named exports instead of default; or using ES6 import incorrectly.
fix
Use 'import client from 'graphql-client'' or 'const client = require('graphql-client')'.
Unhandled Promise Rejection: GraphQLError
Missing catch handler on query/mutate call.
fix
Add .catch(err => console.error(err.message)) or wrap in try/catch.
fetch is not defined
Running in an environment without fetch (e.g., older Node.js) and isomorphic-fetch not installed.
fix
Install isomorphic-fetch or cross-fetch and import it before graphql-client.
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies
isomorphic-fetchoptionalfetch polyfill for Node.js and older browsers
Agent activity
65 hits · last 30 days
node
58
Resources
graphql-client — npm install graphql-client · libregistry