[HN Gopher] Show HN: New GraphQL API for WordPress
___________________________________________________________________
Show HN: New GraphQL API for WordPress
Author : leoloso
Score : 51 points
Date : 2023-01-12 14:44 UTC (8 hours ago)
(HTM) web link (github.com)
(TXT) w3m dump (github.com)
| sakopov wrote:
| What's the purpose of throwing GraphQL in front of a single API?
| I always thought of it as an API Gateway of sorts which fits
| better in a microservice type architecture and aggregates
| requests across multiple microservices. At least that's how I
| have seen it used. What is the need for GraphQL in the WordPress
| scenario?
| jayd16 wrote:
| Presumably its still useful as a standard mechanism for
| response field selection and preventing n+1 queries when trying
| to join data across multiple types of entities.
| camsjams wrote:
| How does this compare to WPGraphQL https://www.wpgraphql.com
| that's been around for quite some time (https://github.com/wp-
| graphql/wp-graphql)
|
| Did you find shortcomings with that plugin?
| bastawhiz wrote:
| This is cool, but I'm curious to know what took 16k commits. The
| projects that I've been on with more then ten thousand commits
| had many dozens or hundreds of folks working full time. And to
| crank that out in 1.5 years! That's 22 commits per day, every
| day. That's a fairly meaty engineering org's cadence. Is there
| some complexity that needed to be overcome that the post doesn't
| get into?
| hansonkd wrote:
| A lot of one word typo fixes, commits to fix one blank line,
| and automated package rewrites. Each release is about 3-4
| commits of the same thing (bumping versions, etc) with 1-4
| releases a day. So to fix a one word typo ends up being about 3
| separate commits.
| rmccue wrote:
| For comparison, the WordPress REST API was about 4k commits
| over ~4 years or so (prior to us merging it into WordPress
| itself): https://github.com/WP-API/WP-API
|
| (That said, commit count is a pretty useless metric.)
| tofuahdude wrote:
| [flagged]
| dang wrote:
| Please don't break the rules like this.
|
| https://news.ycombinator.com/newsguidelines.html
|
| https://news.ycombinator.com/showhn.html
| plebian wrote:
| Why be like this
| dwwoelfel wrote:
| A few ideas to improve the schema based on looking at the
| examples:
|
| 1. Make `globalId` part of a "Node" interface that all of the
| types implement. This will work better with tooling like Relay
| (used for refetching and caching). It will also let you add a
| `node` field that can be used to fetch any node in the graph.
|
| 2. Make the sort input an enum so that you have `sort:
| TITLE_DESC` instead of `sort: {by: TITLE, order: DESC}`.
|
| 3. Implement the connection spec instead of returning a list of
| items: https://relay.dev/graphql/connections.htm. This will let
| you add pagination data to the field and other useful info like
| totalCount.
|
| 4. Spin up a postgraphile instance with the `@graphile-
| contrib/pg-simplify-inflector` and `postgraphile-plugin-
| connection-filter` plugins and copy everything they do.
| cinntaile wrote:
| Why is the years of development or the number of commits
| relevant? It feels like there is an unstated incentive at play
| here? Are you trying to get hired?
| xnx wrote:
| I think it's an attempt to convey the level of effort involved?
| Seems like an even worse measure than lines of code.
| contravariant wrote:
| It's the kind of metric I'd use if I wanted to convey how
| much time was wasted on something.
| [deleted]
| Kwpolska wrote:
| 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?
| dimmke wrote:
| 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.
| coding123 wrote:
| Using WP headed is a good way to become a 0-day.
| globalise83 wrote:
| 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?
| waffl wrote:
| An example could be plucking data from related posts of
| different types that are related via Advanced Custom Fields.
| tylermenezes wrote:
| 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 }}}}}})
___________________________________________________________________
(page generated 2023-01-12 23:01 UTC)