Wp-graphql: Handling custom post type

Created on 3 Jun 2017  路  5Comments  路  Source: wp-graphql/wp-graphql

Could a custom post type be registered in a similar fashion as @BE-Webdesign's wp-graphql plugin? https://edwincromley.gitbooks.io/wp-graphql/content/handling-custom-post-types.html

question

Most helpful comment

then you can also modify the post_type's schema (fields) via the "graphql_{$type}_fields" filter. So you can add stuff like custom post meta, etc

All 5 comments

Yes, it's very similar.

On the post_type registration you can pass:

show_in_graphql => Boolean
graphql_single_name => string
graphql_plural_name => string

You can see the core types setup here:

https://github.com/wp-graphql/wp-graphql/blob/master/wp-graphql.php#L222

That will add the post_type as a Type that can have its own schema, add it as a root query b(oth singular and plural root queries), it will also set it up to work as a node query, and set up connections between the post_type on connected taxonomies, comments (if the post_type supports it), featured image (if post_type supports it), etc.

We'll work on better docs soon!

then you can also modify the post_type's schema (fields) via the "graphql_{$type}_fields" filter. So you can add stuff like custom post meta, etc

Also important to note that that version is not being maintained and this version of the GraphQL API is much much further along!

Super...Thanks @jasonbahl!

@BE-Webdesign Thanks for the info. Might be helpful to leave a note pointing folks to this repo since yours still has a higher link juice than this one.

@nikosolihin, Been meaning to do that 馃槈.

Was this page helpful?
0 / 5 - 0 ratings