Month: July 2019

  • 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.