Convert your WordPress REST API into a GraphQL API by installing the WPGraphQL plugin

Kyle Gill
InstructorKyle Gill
Share this video with your friends

Social Share Links

Send Tweet

You can automatically add a GraphQL API to any WordPress site by installing the free, open-source WPGraphQL plugin into WordPress. The plugin adds a GraphiQL with an explorer for interactively building out your own queries of data, or mutations to update data. In many ways, it's easier to reason with and understand than the WordPress REST API because of the built in autocompletion and documentation that comes with GraphQL.

By installing the plugin in a default WordPress site (which this lesson demonstrates), you get queries and mutations already set up for all the native WordPress data types.

Additional resources

Kyle Gill: [0:00] In a WordPress site, I'm using a fresh install of default WordPress. Go to the Plugins section in the sidebar and select Add New. From the Plugin search, look for WPGraphQL. Install it by pressing the Install Now button and then click Activate to make sure the plugin is running.

[0:23] The page will refresh, and you'll see the GraphQL IDE added to the header and the GraphQL section added to the sidebar. The GraphQL IDE is an interactive query runner for GraphQL APIs. Click on it, and you can build your first query by clicking on the data types from the left sidebar of GraphQL, like posts, their nodes with their date, slug, and title.

[0:48] Clicking the Play button will run the query, showing you exactly how the API would respond. You can compare this to the WordPress REST API by navigating to wp-json/wp/v2/posts, which returns a list of posts.

[1:06] You'll notice I get a lot more data in included fields than MyQuery and GraphQL. Demonstrating one of the key values of GraphQL, only returning the data you ask for.