We use cookies to help our site work and to understand how it is used. By continuing to browse the site you're agreeing to our use of cookies.
Menu
Query batching

We just enabled query batching support to our GraphQL Content Delivery API.

This means you can combine multiple GraphQL operations into a single HTTP request, reducing HTTP overheads. If you use Apollo Client, you can enable batch queries with the apollo-link-batch-http package:

import { ApolloClient } from 'apollo-client';
import { setContext } from 'apollo-link-context';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { BatchHttpLink } from 'apollo-link-batch-http';

const httpLink = new BatchHttpLink({
  uri: 'https://graphql.datocms.com/',
});

const authLink = setContext((_, { headers }) => {
  return {
    headers: {
      ...headers,
      'Authorization': `Bearer ${process.env.DATO_API_TOKEN}`,
    }
  }
});

const client = new ApolloClient({
  link: authLink.concat(httpLink),
  cache: new InMemoryCache(),
});

export default client;