Gatsby & WordPress - 2.3. - WPGraphQL

by Jack Pritchard

Hey! This post's a little over two years old now, so some of what's here might be out of date. Still worth a read, but if anything really matters to you, it's worth double-checking against a newer source too.

WPGraphQL

After installing the WPGraphQL plugin from Github, and installing it, we will now have access to a new endpoint in our WordPress environment. The endpoint is the name of your site with

/graphql
at the end of the URL.

When you first access this endpoint you'll be met with a confusing error which says that you need to provide at least a query or queryId.

This is because GraphQL is a very explicit querying language and required you to be specific with what data you want to be returned before it returns any payloads.

To get an understanding of the schema we do have available to us, we'll be using the WPGraphiQL plugin within our WordPress admin dashboard.

With the plugin, we'll query the posts available on our website and return the ID, date, slug, and title of each post using GraphQL and getting a JSON payload response.

WPGraphQL has moved through many major versions since this was recorded in 2019 — the schema and admin tooling shown here may differ from what you see in a current install.