Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

What real-life use-cases do you envison for a GraphQL API for WordPress? What does it solve that the existing REST APIs cannot? Why would you make a GraphQL API out of a CMS for (primarily, out of the box) blogs?


GraphQL supports schema stitching, so you can have one API endpoint request lots of different information from different services, and combine information seamlessly server-side. (e.g. Wordpress author -> user service -> posts on a different service)

Here's how we're using Wordpress and other GraphQL services at a smallish nonprofit: https://blog.codeday.org/how-graphql-helps-us-showcase-coded...

That page is powered by Wordpress over GraphQL, and you can try it yourself at https://graph.codeday.org/ (here's a sample query - query { blog { posts { nodes { title author { discordInformation { username discriminator }}}}}})


I think you missed a }


WordPress serves as kind of an ad hoc CMS for many different kinds of backends. Because it’s easy to extend and a lot of people are familiar with it.

When I worked at the CDC, the entire backend of cdc.gov was a heavily HEAVILY customized version of WordPress that did static publishing. I’d guess it’s still that way.

It’s why WooCommerce was so popular. Role your own eCommerce.

GraphQL is good because using WP headless is popular these days.


Using WP headed is a good way to become a 0-day.


One use-case could be to use Wordpress just for an e-commerce backend (WooCommerce API) and then use alternative services for headless CMS etc, stitching them together for frontends to use via this product?


The easy use case is to fetch data from a WordPress backend, and render your site using some JS library (React, Vue, Next.js).

But it can do much more than that (indeed, I like to think of GraphQL as the single tool to deal with any content-related task). These are some interesting use cases:

- Use a WordPress backend as an upstream server to manage all your data, and feed it to downstream servers/applications/websites

- Use GraphQL to extract information from 1 or more sources (such as users from the WordPress sites and the newsletter contact data from Mailchimp) and combine the data (and analyze it all together as a single dataset)

- Execute operations using GraphQL to adapt the content on your site, either as a one-off when installing a new site, or regularly. Eg: replace all "https://myoldsite.com" to "https://mynewsite.com" in the content after changing the domain or doing a migration, and execute queries to replace any "http://" to "https://" when a writer publishes a new blog post

- ETL (Extract, Transform, Load) of anything that involves content, whether stored in WordPress or external sources

- Interact with 3rd party services. Eg: Use GraphQL to connect to the Google Translate API and translate all the blog posts to a different language, or send a tweet after a blog post is published

- Send notifications (by email, Slack, etc) after something happened (a new post, comment, etc)

It can also be used with pipelines, and it can complement WP-CLI whenever it falls short of being able to do something. An example of this:

I myself use GraphQL via my plugin to connect to the GitHub API and fetch data from my releases, which can then be downloaded automatically and installed on my testing sites before running integration tests. I tried using WP-CLI directly for this and it fails, because the GraphQL API gives the .zip download file URL via a header, and this data needs to be extracted first. So I extract the header via GraphQL, and then inject it into WP-CLI, and the whole process is automated.

Many of these tasks, you can do them with dedicated plugins (such as for content migration). The beauty of GraphQL is that it's like a Swiss-army knife: you can write your own GraphQL query to execute many of these tasks, customizing it for your own needs, and avoiding to buy other plugins.


An example could be plucking data from related posts of different types that are related via Advanced Custom Fields.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: