26
loading...
This website collects cookies to deliver better user experience
fetch()
, to send GraphQL queries. However, for larger, more complex projects that have advanced requirements, a GraphQL client is needed.graphql-request
GitHub repository activity is healthy, with 3.7K stars at the time of writing. On npm, graphql-request
is downloaded more than 1.3 million times weekly at the time of writing, so you shouldn’t have any trouble finding help online!graphql-request
is simple to use, and there’s almost no learning curve:import { GraphQLClient, gql } from 'graphql-request'
const query = gql`{
hero {
name
}
}`
const client = new GraphQLClient('<graphql-endpoint>')
const data = await client.request(query)
const QUERY = `
query Test($id: ID!) {
getUser(id: $id) {
id
name
}
}
`;
const result = client.readQuery(QUERY, { id: 'test' });
useQuery
, useMutation
, and useSubscription
React Hooks for handling queries, mutations, and subscriptions, respectively. The official documentation includes a guide to migrate from Apollo Client.Community support | Learning curve | Size | TypeScript typings | Pagination, query caching, batching, and deduplication | Isomorphic support | Integrations with UI libraries and frameworks | |
---|---|---|---|---|---|---|---|
graphql-request |
Great | Low | 5.2 kB | Yes | No | Yes | No |
Apollo Client | Great | Medium | 33.9 kB | Yes | Yes | Client only | React, Next.js, Angular, Svelte, Ember, web components, and Vue |
urql | Fair | Low | 7.1 kB | Yes | Batching not supported | Yes | React, Svelte, and Vue |
Relay | Fair | High | 47.1 kB | No | Yes | Client only | React only |
graphql-hooks |
Low | Low | 3.6 kB | Yes | Batching and deduplication not supported | Client only | React only |
graphql-request
: server-side or frontend project with simple requirementsgraphql-hooks
: project is React-based and doesn’t require advanced features