In this lesson, we will expose a Custom Post Type to the graphQL layer. This would normally be done in the Custom Post Type Plugin UI but if you browse the options you'll notice that there is no setting for GraphQL. This means we will need to write a custom function that exposes our user-created post type.
We will use add_filter
in our headless.php
file to expose the chairs post type. The filter we'll use is register_post_type_args
. There are three fields that need to explicitly declared: show_in_graphql
, graphql_single_name
, graphql_plural_name
.
CPT UI is now provided with a field that allows the post to be shown in Graphql
CPT UI does indeed allow you to add to GraphQL within it's settings menu. Like in code, you have to make available and set the names (singular and plural).