🥳 The PoP API is now a GraphQL server!

— 16 minute read

After several months of work, I can announce that my project GraphQL API for PoP finally provides a spec-compliant implementation of a GraphQL server in PHP! Yay!!!!!

The missing part, which I finished adding today, was the GraphQL syntax parser. Until today, the PoP API relied on its own syntax (which is needed to support the engine's broader set of features compared to a standard GraphQL server, such as composable fields, composable directives, and others). However, I had the realization that this custom syntax is a superset of GraphQL's syntax and, as such, it would not be a problem to support it. After exploring all the existing GraphQL server implementations in PHP, I took the one implemented by Youshido and used their parser, and it works like magic!

🥳

Trying out the new GraphQL server in PHP permalink

Let's play with this brand-new implementation of GraphQL, to make sure it works as expected. For this, I have set-up this WordPress site, and installed in it the GraphQL API for PoP, available under this endpoint.

The GraphiQL clients below contain queries to demonstrate the GraphQL features. Click the round button (with alt text "Execute query (Ctrl-Enter)") to execute the query and see the results, and you can also edit the query and the variables and run it again.

Alternatively, you can access the website's own GraphiQL client here.

Note: there are no docs and no information hinting yet, because I still need to support field "__schema" (see section below).

Fields (Open in website's GraphiQL client)

Field arguments (Open in website's GraphiQL client)

Aliases (Open in website's GraphiQL client)

Fragments (Open in website's GraphiQL client)

Operation name (Open in website's GraphiQL client)

Variables (Open in website's GraphiQL client)

Variables inside fragments (Open in website's GraphiQL client)

Default variables (Open in website's GraphiQL client)

Directives (Open in website's GraphiQL client)

Fragments with directives (Open in website's GraphiQL client)

Inline fragments (Open in website's GraphiQL client)

Adding 100% compliance to the GraphQL spec permalink

100% compliance of the GraphQL spec is almost there. The remaining items to implement are:

  1. Satisfying the "__schema" field
  2. Adding support for mutations

I'm already working on the first item, I expect it to be finished in a few days. Concerning the second item, I have already started work on it, depending on my time availability I may be able to finish it in a couple of months.

Support for REST too permalink

Bonus feature: From a unique source code, the API also supports REST! Check out these example links:

Are you using WordPress? Do you need a good API? Try this one out! permalink

Currently, WordPress users have two API alternatives:

  1. REST, through the WP REST API which is already included in core
  2. GraphQL, through WPGraphQL

Now, I want to add a third alternative:

  1. Both GraphQL and REST, through GraphQL API for PoP

Please check it out, it will make your life easier. I promise. And let me know how it goes.