WPGraphQL v0.4.1

Today we released WPGraphQL v0.4.1. This is a non-breaking change release. You can view the release here: https://github.com/wp-graphql/wp-graphql/releases/tag/v0.4.1

Release Summary

  • Update composer dependencies
  • Update filter on WPGraphQL::get_allowed_taxonomies()
  • Update to Docs for WPGraphQL for ACF – Thanks @henrikwirth!
  • Update to Install and Activate Docs – Thanks @jacobarriola!
  • Update to Docs sidebar styles – Thanks @TylerBarnes!
  • Add Router::is_graphql_request() method – Thanks @esamattis!
  • Fix issue with PostObjectMutation not respecting term inputs if graphql_plural_name was capitalized in the registration
  • Prevent execution of connections if the source Post is null
  • Fix PostObjectCursor issue with meta_value_num compares – Thanks @kidunot89!
  • Fix UserLoader for orphaned users – Kellen
  • Adjustments to Comment Model – Ryan
  • Add Interface inheritance for Types implementing Interfaces – Thanks @kidunot89!
  • Fix PHP warning in InstrumentSchema.php
  • Add tests for Interfaces
  • add Page.isFrontPage field to the Schema – Thanks @zgordon!

WPGraphQL at the Desert GraphQL Meetup

Last night I had the pleasure of remotely presenting for the Desert GraphQL Meetup in Phoenix, Arizona.

TL;DR, Here’s the video

Video recording of the GraphQL for WordPress meetup presentation

Here’s the slides:

https://slides.com/jasonbahl-1/desert-graphql-oct-2019#/

Summary of the presentation

In the presentation I covered the history of WPGraphQL, why the plugin exists, and why it makes sense to continue building for the wider WordPress community.

We look at some of the frustrations with the WordPress REST API that lead to the creation of WPGraphQL.

I quickly reviewed what WordPress looks like, as in what the WordPress Dashboard looks like and what it enables out of the box.

Next, I show how activating WPGraphQL activates a GraphQL API for your WordPress and the WPGraphiQL Plugin adds the GraphiQL IDE to your WordPress dashboard.

We then look at what WordPress looks like, visually, as an Application Data Graph and how to use GraphQL Queries to pick trees out of that graph.

Next we looked at various live examples of GraphQL Queries and explored features of the GraphQL Query Language, such as querying multiple resources in a single request, using variables, arguments, fragments, aliases and directives.

We then compare how to build the same slice of UI using PHP, REST and GraphQL to show how much lower effort it is to use GraphQL compared to alternatives.

I finish up talking about some things I’ve learned while building WPGraphQL, and what’s next now that I am part of the GatsbyJS team.

WPGraphiQL IDE v1.0.0 with GraphQL Explorer

The GraphiQL IDE is an incredibly helpful tool when using GraphQL. WPGraphiQL has been the go-to GraphiQL IDE for use with WPGraphQL, and today we’ve released v1.0.0 of the WPGraphiQL IDE, now with the AMAZING GraphQL Explorer feature, courtesy of the fine folks at OneGraph.com.

Re-introducing WPGraphQL for ACF

TL;DR

Starting today, WPGraphQL for Advanced Custom Fields is FREE!

Some Context

In April 2019, I released the WPGraphQL for Advanced Custom Fields plugin as a paid plugin in an attempt to generate enough revenue to one day be able to work on WPGraphQL full-time.

I want to thank everyone that purchased a license and helped me grow the community. The purchases proved that this is an important plugin with an audience, and the revenue from the purchases have allowed me to spend time working on additional features, bug fixes, and interact with users in Slack, Twitter and other communication channels over the past few months. It’s clear that a big part of the future of WordPress headless, and WPGraphQL is a big part of that future.

New Opportunity

As you may have heard on Syntax.fm or WPTavern, I have been blessed with the opportunity to join the Gatsby team, where I get to spend my time working on WPGraphQL and its immediate ecosystem, including plugins like WPGraphQL for Advanced Custom Fields.

Now that I have the opportunity to work on the WPGraphQL ecosystem full-time, the Gatsby team and I believe it’s best for the community to make the WPGraphQL for Advanced Custom Fields FREE, starting today.

The plugin is now freely available on Github: https://github.com/wp-graphql/wp-graphql-acf. The plugin will also be submitted to packagist.org which will allow the plugin to be more easily included in projects using Composer.

Support and Updates

WPGraphQL for Advanced Custom Fields will continue to get the same care and support I’ve provided since launch, but even better as I now have more time to focus on the WPGraphQL ecosystem. 

  • Github: If you run into issues or have ideas for feature requests, I kindly ask that you open issues on the Github repository.
  • Slack: If you have general questions, the WPGraphQL Slack workspace is a great place to seek support. If you’re not in the Slack workspace already, you can join here
  • Spectrum: WPGraphqL has an online community on Spectrum, which allows publicly visible and indexable async communication. You can visit the WPGraphQL Spectrum community here.

WPGraphQL and Gatsby

The Gatsby team and I are excited to invest more time into adding more features to WPGraphQL to benefit the entire headless WordPress & modern Javascript communities. 

Whether you’re using React or Vue, Next or Nuxt, Create React App or Gatsby, or anything else, we want WPGraphQL to be a great experience for all.

Of course, we believe in many cases there will be benefits of using WPGraphQL with Gatsby, and we’d love it if you gave Gatsby a try, but ultimately we want you to build great experience for your users using the tools you enjoy.

Thank you for your support and I’m looking forward to a bright future for GraphQL and WordPress.

Thanks!

Jason Bahl
Creator / Maintainer, WPGraphQL

WPGraphQL for FacetWP

I am pleased to announce the beta release of my FacetWP integration plugin for WPGraphQL. 

The main functionality was written quickly in late 2018 to fill a need to provide client-side access to FacetWP’s index and filtering functionality via WPGraphQL. As a proof-of-concept it worked exactly as needed. It was a lot less effort to create this plugin than it would have been to roll my own facet indexing module. 

Recently, I have had some down time between changing jobs and have been able to refactor and clean up the original code into something more usable by the larger WordPress and WPGraphQL community. If you have the need to expose the functionality of FacetWP via the GraphQL schema, I hope you find this plugin helpful!

Usage

To register WP Post Type(s) to be added to the schema, simply use the facet query registration function register_graphql_facet_type() as follows: 

// Register facet for Posts 
register_graphql_facet_type( 'post' ); // replace post with your CPT name as necessary 

Prerequisites: To use the plugin users must have already configured at least one facet in FacetWP and configured WPGraphQL.

Input

The plugin uses reflection to expose all configured facets are available for querying. Each facet is added as an input argument to the query. 

Different facet types have unique inputs (eg a Slider has a min and max while Checkboxes is a simple array of strings). 

Given the post registration above the query variables might look something like this: 

const variables = { 
    after: '', // Use endCursor for paging 
    query: { 
        // example facet filtered on post ID 
        facet_name: [1, 2, 3], 
        // sample facet filtered on taxonomy term 
        term_facet_name: ['category-1', 'category-3'], 
    }, 
    orderBy: { 
        field: 'DATE', 
        order: 'DESC', 
    }, 
} 

Payload

Registering a facet type will result in a new field on the Root Query. The field name is determined by the type to be queried. 

The payload of the new facet field includes: 

  • facets: The returned facet information
  • type connection: A WPGraphQL connection to the post type query 

Given the post registration earlier, the query and response payload might look like this: 

postFacet(where: {status: PUBLISH, query: $query}) { 
  facets { 
    selected 
    name 
    label 
    choices { 
      value 
      label 
      count 
    } 
  } 
  posts(first: 10, after: $after, where: {search: $search, orderby: $orderBy}) { 
    pageInfo { 
      hasNextPage 
      endCursor 
    } 
    nodes { 
      title 
      excerpt 
    } 
  } 
} 

Facets

This payload includes all information relating to the queried facets and input variables. Available choices (including available count), settings and other relevant information are exposed in this field. 

Connection

This payload is a connection to the configured post type. It accepts all the pertinent GraphQL arguments (paging, sorting etc). 

This connection only returns posts that match the facet filter. 

Conclusion 

This plugin provides users of WPGraphQL with access to an established and popular WordPress plugin for server-side filtering; FacetWP. I hope the WordPress community finds it helpful. It certainly was a great time saver for our project. 

Disclaimer and limitations: I have thoroughly tested Checkbox, fSelect and Radio facet types, as these are used in my app. There is provisional support for all other facet types, however these are not fully tested. As with any open source project, a detailed issue (or better yet a pull request) would be appreciated. 

Please see GitHub for further documentation and commentary.

WPGraphQL featured on Syntax.fm

Today, I had the pleasure of being featured on the Syntax.fm podcast with hosts Wes Bos and Scott Tolinsky.

In this episode we discussed how to use GraphQL with WordPress using the WPGraphQL plugin. I also announced that I’ve joined the Gatsby team to work on WPGraphQL an its immediate ecosystem full-tiime.

Below is the recording of the podcast.

WPGraphQL for ACF is here!

Many folks using WPGraphQL have asked about how to use GraphQL with their ACF data. The answer has typically been to manually map their ACF fields to the GraphQL schema using functions like register_graphql_field and register_graphql_object_type. For a few fields, this isn’t much of an issue, but when you have dozens of fields, this gets very tedious.

Today, we’ve released WPGraphQL for Advanced Custom Fields, which automatically adds your Advanced Custom Fields to your WPGraphQL Schema.

You can learn more about the plugin here: https://content.wpgraphql.com/acf

Very excited to see what the community builds with this. If you have any questions, please contact us.