Was this page helpful?

Getting started with GraphQL

GraphQL Content API

GraphQL is a flexible data query language that allows you to define API call responses to match your use case and technical needs (and much more). If you are new to the technology, here are some great educational resources to get you up to speed:

The GraphQL Content API supports both our Content Delivery API (CDA) and our Content Preview API (CPA). It offers a fully functional equivalent to the REST implementation of the two APIs. Every Contentful space comes with a GraphQL schema based on its content types. GraphQL endpoint filtering capabilities, schema generation process, and error codes are explained in the Reference guide.

Disclaimer: GraphQL Content API is available on all spaces for customers on current pricing plans. If you are on a legacy plan, contact Customer Support to upgrade.

Log Request ID

When submitting support tickets, include the request ID along with other logs. Providing the request ID ensures faster and more effective responses to your inquiries. You can find it in the response header under x-contentful-request-id.

Get request ID from Apollo Client

Use the following code snippet to access response headers (request ID) from Apollo Client.

import {
    ApolloLink
} from 'apollo-link';
import {
    createHttpLink
} from 'apollo-link-http';

const httpLink = createHttpLink({
    uri: 'http://localhost:3001/graphql'
});

const afterwareLink = new ApolloLink((operation, forward) => {
    return forward(operation).map(response => {
        const context = operation.getContext();
        const {
            response: {
                headers
            }
        } = context;

        if (headers) {
            const requestId = headers.get("X-Contentful-Request-Id");

            if (requestId) {
                console.log("requestId", requestId);
            }

        }
        return response;
    });
});

// use with apollo-client
const link = afterwareLink.concat(httpLink);

Demo content

To help you explore the capabilities of the GraphQL API, a demo space populated with a sample content model and a complementary example application is set up:

You can query the demo space and examine its schema interactively, using the GraphiQL client embedded below (or working with it in a new tab).

Learn GraphQL with Contentful in a video course

To provide an easy starting point for your own projects, have a look at our GraphQL course "What's your query?". You will learn GraphQL core principles using React.

Preview of the first episode of the GraphQL course

Next steps

Now that you have covered the basics, learn how to implement GraphQL queries into your application by following language-specific starter guides:

For GraphQL API documentation and troubleshooting, please consult the reference guide:

To share your thoughts, ideas, and feedback use the feedback button or connect with us on Slack.

Give feedback