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
Published 4 years ago
Updated 4 years ago

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.

egghead
egghead
~ 2 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today