Adding a custom post type to the schema

If the Custom Post Type (CPT) has a type that has been mapped to the schema, we can add it to the CustomPostType union.

Otherwise, we can support retrieving the CPT data via the GenericCustomPost type.

Let's see how to configure both alternatives.

1. CPTs mapped to the schema permalink

The CustomPostUnion type is used whenever an entity may return entities from different CPT types (such as Post, Page, etc):

`CustomPostUnion` type

The different CPT modules can make their type be part of CustomPostUnion through their Settings.

For instance, type Page is added to CustomPostUnion under the Settings for Schema Pages:

Settings for Schema Pages
Settings for Schema Pages

Resolving CustomPostUnion to a single type instead permalink

If there is only one type added to CustomPostUnion, we can then have the fields that resolve to CustomPostUnion be instead resolved to that unique type instead:

Settings for Custom Posts
Settings for Custom Posts

For instance, if Post is the only type, field customPosts from type Root resolves to it directly:

 field resolves to  type
`customPosts` field resolves to `Post` type

2. CPTs not mapped to the schema permalink

Tab "Schema Generic Custom Posts" in the Settings has input Included custom post types, listing down all the Custom Post Types registered in the WordPress site.

From the list, select those CPTs that need to be queried through GraphQL (more than one can be selected by pressing the ctrl or shift keys), and field genericCustomPosts will fetch their entries:

Settings for Generic Custom Post
Settings for Generic Custom Post