Gathering detailed insights and metrics for graphql-request
Gathering detailed insights and metrics for graphql-request
Gathering detailed insights and metrics for graphql-request
Gathering detailed insights and metrics for graphql-request
@golevelup/nestjs-graphql-request
Badass utilities for integrating graphql-request and NestJS
@testmail.app/graphql-request
Clone of graphql-request (minimal GraphQL client) with improvements like built-in retries
@graphql-codegen/typescript-graphql-request
GraphQL Code Generator plugin for generating a ready-to-use SDK based on graphql-request and GraphQL operations
@nitra/graphql-request
Graphql Request helper
Simple GraphQL Client for JavaScript. Minimal. Extensible. Type Safe. Runs everywhere.
npm install graphql-request
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
5,886 Stars
990 Commits
310 Forks
34 Watching
3 Branches
82 Contributors
Updated on 26 Nov 2024
TypeScript (99.15%)
CSS (0.42%)
JavaScript (0.37%)
Shell (0.04%)
Vue (0.03%)
Cumulative downloads
Total Downloads
Last day
-3.5%
843,629
Compared to previous day
Last week
3.7%
4,435,660
Compared to previous week
Last month
11.5%
18,401,696
Compared to previous month
Last year
23.9%
197,667,409
Compared to previous year
1
1
36
[!IMPORTANT] The next version (
8
) ofgraphql-request
is being renamed tograffle
. It has the same base simplicity but with many fixes, enhancements, and major new type safe features. It is not released yet but will be in the coming weeks/months and is already usable. Learn more about it here. You can see the in progress website at https://graffle.js.org.The following README is still for
graphql-request@7.x.x
Minimal GraphQL client supporting Node and browsers for scripts or simple apps.
async
/ await
)TypedDocumentNode
1npm add graffle graphql
This package uses package.exports
. Therefore if you are a TypeScript user you must:
tsconfig.json
moduleResolution
set to "bundler"
or "node16"
/"nodenext"
.package.json
type
set to "module"
.Send a GraphQL document using a static request function:
1import { gql, request } from 'graffle' 2 3const document = gql` 4 { 5 company { 6 ceo 7 } 8 } 9` 10await request('https://api.spacex.land/graphql/', document)
The function can be passed a configuration object for more complex cases:
1await request({ 2 url, 3 document, 4 variables, 5 requestHeaders, 6})
A class is available for constructing your own instances:
1import { gql, GraphQLClient } from 'graffle' 2 3const document = gql` 4 { 5 company { 6 ceo 7 } 8 } 9` 10const endpoint = 'https://api.spacex.land/graphql/' 11const client = new GraphQLClient(endpoint) 12await client.request(document)
We only (officially) support versions of Nodejs of the following status:
So for example on Oct 24 2023 that would mean these versions: 18, 20, 21.
Any issue that exists solely for an unsupported version of Nodejs will be rejected (not worked on).
⚠️ This reference is incomplete. Check out the examples for more reference material.
By default GraphQLClient will throw when an error is received. However, sometimes you still want to resolve the (partial) data you received.
You can define errorPolicy
in the GraphQLClient
constructor.
1const client = new GraphQLClient(endpoint, { errorPolicy: 'all' })
Allow no errors at all. If you receive a GraphQL error the client will throw.
Ignore incoming errors and resolve like no errors occurred
Return both the errors and data, only works with rawRequest
.
OperationName has been introduced to address issues reported here Support operation name, However, on certain occasions this information may not be needed in requests. In such cases, you might consider ignoring operationName to avoid the extraction steps currently performed by a parsing operation when the document is provided in string format.
By default the GraphQLClient tries to extract the operationName from the document.
You can define excludeOperationName
in the constructor of GraphQLClient to avoid the extraction process if it is not needed. This can be useful if you don't use operationName and want to optimise queries by reducing the amount of computation as much as possible, especially if we are in a context where we are using documents in string format to reduce bundle size.
1// example where the operation name is not ignored
2const client = new GraphQLClient(endpoint, {
3 method: 'POST',
4})
5// example in which the operation name is ignored
6const client = new GraphQLClient(endpoint, {
7 method: 'POST',
8 excludeOperationName: true,
9})
In this issue we decided to make this library more stable and maintainable. In principal the feature is still in scope of this library and will make a return when we find time to do the feature right.
graphql
?graffle
uses methods exposed by the graphql
package to handle some internal logic. On top of that, for TypeScript users, some types are used from the graphql
package to provide better typings.
gql
template exported by graffle
?No. It is there for convenience so that you can get the tooling support like automatic formatting and syntax highlighting. You can use gql
from graphql-tag
if you need it for some reason too.
graffle
apart from other clients like Apollo, Relay, etc.?graffle
is the most minimal and simplest to use GraphQL client. It's perfect for small scripts or simple apps.
Compared to GraphQL clients like Apollo or Relay, graffle
doesn't have a built-in cache and has no integrations for frontend frameworks. The goal is to keep the package and API as minimal as possible.
No vulnerabilities found.
No security vulnerabilities found.