GraphQL and WordPress — Why They’re Better Together

Using GraphQL with WordPress

It took a great deal of effort and time to get the REST API into WordPress core and I assure you it will take even more to have GraphQL support into it as well. But it is possible to use it today, thanks to plugins available.

GraphQL and APLM

In the Gartner Top Strategic Technology Trends for 2021 report, Gartner outlines several trend strategies for this year. Some of those trends include AI Engineering, Automation, etc. Almost all the trends and strategies will certainly rely heavily on APIs to better share information/data and insights. Since GraphQL is improving the APLM (API Lifecycle Management) space, there is a lot to be gained in using it. Let’s take a brief look at the APLM phases and how GraphQL is improving them.

Design

There are many benefits to using the REST API, but a few of its problems are the “strictness” of its fields, or shape/schema, provided. The promise of getting all the data, in the exact shape one needs in a single request is too hard to resist.

Development

This is another area where a lot can be gained, since to author a GraphQL API you only need a one-time effort. Of course you can add new fields and types later, but if, for example, you are building a news site and you need to create a columnists page, you don’t need to build another REST API endpoint for that. Your GraphQL API schema would already provide that for you.

Retiring / Deprecating

Another stark difference between REST API and GraphQL comes when needing to retire APIs or endpoint information. In REST, API versioning is the current standard. You create v1, v2, v3, etc, even if you need to make drastic changes, including deprecating it.

Cons

Before diving into how to use GraphQL with WordPress, I’d like to mention that GraphQL is not a substitute for REST per se. There are some cons that you should understand before migrating completely into it.

  • There are some rough-edges like caching.
  • Access-control: especially field control, is possible but not as easy as one might think.

Increasing Velocity and Improving Productivity

When used with WordPress, GraphQL opens up a huge amount of new options and potential. By limiting the amount of code that needs to be updated when an API changes, and by providing only what a developer — and an application — needs, you can save time when creating your application and make it much easier for others to understand. Overall, we expect that GraphQL will allow many to create more exciting and useful pieces in less time, as it gets further adopted into the WordPress ecosystem.

--

--

We are strategists, researchers, designers, and developers who craft digital experiences for publishers, nonprofit institutions, museums, and brands. alley.co

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store