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;