graphql-client-fetch
v1.1.0
Published
Fetch-based GraphQL client for queries, mutations, custom headers, and batched requests.
Downloads
110
Maintainers
Readme
graphql-client-fetch
graphql-client-fetch is a minimal GraphQL SDK built on top of fetch. It is useful for services, scripts, edge runtimes, and frontend apps that want a lightweight query and mutation client without pulling in a full GraphQL framework.
Installation
npm install graphql-client-fetchFeatures
- query and mutation helpers
- custom default headers
- request timeout support
- injectable
fetchimplementation - batch execution for multiple operations
Usage
const GraphQLFetchClient = require('graphql-client-fetch');
const client = new GraphQLFetchClient({
endpoint: 'https://api.example.com/graphql',
headers: {
Authorization: `Bearer ${process.env.API_TOKEN}`,
},
});
const viewer = await client.query(
'query Viewer { viewer { id email } }'
);API
new GraphQLFetchClient(options)setHeader(name, value)removeHeader(name)query(query, variables?, options?)mutate(mutation, variables?, options?)rawRequest(body, options?)batch(operations)
License
MIT
