Skip to main content
View plugin on GitHub
See starters using this

gatsby-plugin-apollo

This plugin will set up a Gatsby project for use with Apollo Client, in the most minimal way imaginable.

Note: This plugin accepts only a few of the options accepted by the ApolloClient constructor. If you need to use a more advanced Apollo Client configuration, try gatsby-theme-apollo instead.

Installation

To use this plugin, you’ll also need to install your own copy of @apollo/client. This is what you’ll use to make GraphQL queries in your React components.

$ npm install gatsby-plugin-apollo @apollo/client

Usage

Add the plugin to your Gatsby config, and supply the location of your desired GraphQL API to the uri option. There are more options available for slighty advanced configurations.

// gatsby-config.js
module.exports = {
  plugins: [
    {
      resolve: 'gatsby-plugin-apollo',
      options: {
        uri: 'https://example.com/graphql'
      }
    }
  ]
};

Options

Option Type Description
uri string A string representing your GraphQL server endpoint. Defaults to /graphql.
credentials string Is set to same-origin by default. This option can be used to indicate whether the user agent should send cookies with requests.
headers Object Header key/value pairs to pass along with the request.

License

MIT