Using GraphQL Plugin with Pods Framework

So, I started to experiment with a GraphQL plugin for WP, and was wondering how it'd work with Pods.

I came across a question on that plugin's GitHub that's pretty much the same thought I had. The maintainers supplied an answer:

Each Custom Post Type and Custom Taxonomy you want to add to the Schema should have the following fields set:

  • show_in_graphql (bool)

  • graphql_single_name (string)

  • graphql_plural_name (string)

I think I know how to do it with directly creating a custom post type register_post_type() in PHP, but not sure how I'd do it in Pods.

Topic pods-framework open-graph custom-post-types Wordpress

Category Web


You can definitely add filters for pods_register_post_type_{your_pod} and pods_register_taxonomy_{your_pod}. I'd love to build in support for GraphQL into Pods itself at some point. Just a matter of adding the checks if GraphQL is available and showing the options in the UI, similar to how we do our REST API options in the UI.

<?php
add_filter( 'pods_register_post_type_mycpt', 'add_pods_graphql_support' );
add_filter( 'pods_register_taxonomy_mytax', 'add_pods_graphql_support' );

function add_pods_graphql_support( $options ) {

    $options['show_in_graphql'] = true;
    $options['graphql_single_name'] = $options['labels']['name'];
    $options['graphql_plural_name'] = $options['labels']['singular_name'];

    return $options;

}

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.