Post Type schema settings implemented#1486
Post Type schema settings implemented#1486kidunot89 wants to merge 3 commits intowp-graphql:developfrom
Conversation
|
Deploy request for wpgraphql-docs pending review. Review with commit 3c49760 |
Codecov Report
@@ Coverage Diff @@
## develop #1486 +/- ##
===========================================
- Coverage 59.04% 58.93% -0.11%
===========================================
Files 192 192
Lines 11270 11299 +29
===========================================
+ Hits 6654 6659 +5
- Misses 4616 4640 +24
Continue to review full report at Codecov.
|
| * Register Connections from all existing PostObject Types to Comments | ||
| */ | ||
| $allowed_post_types = \WPGraphQL::get_allowed_post_types(); | ||
| $allowed_post_types = \WPGraphQL::get_allowed_post_types( [ 'connect_to_comments' => true ] ); |
There was a problem hiding this comment.
How is this different than what we're already doing here:
wp-graphql/src/Connection/Comments.php
Line 80 in 2a349fd
What if you set connect_to_comments => true but the post type doesn't register support for comments?
Seems kinda like an akward rule when we already have: show_in_graphql and supports => [ 'comments' ]
There was a problem hiding this comment.
@jasonbahl Not necessarily, currently I manual register the comments connection for the Product type in WooGraphQL so I can add the product comment (review) meta rating as an edge field. Although, I plan to change this in the near future, so that one won't be necessary for long, but I can see a need this when you want to defer to an alternate source for comments like Disqus 🤔
There was a problem hiding this comment.
The Disqus use case is interesting. 🤔
You would want the post_type to support comments in general, but would want to be able to disable the connection in GraphQL because the actual comments are handled outside of WordPress. 🤔
There was a problem hiding this comment.
that or in a custom table that might use a custom query class or unique $wpdb functions.
| public static function add_post_type_settings( $args, $post_type ) { | ||
| global $wp_post_types; | ||
|
|
||
| $post_type_settings = [ |
There was a problem hiding this comment.
I think we should nest these rules under a graphql key.
like:
'graphql' => [
'use_post_object_loader' => true,
...other args
]
| 'supports_post_object_union' => true, | ||
| 'supports_menu_item_object_union' => true, | ||
| 'resolve_from_uri' => true, | ||
| 'use_post_object_loader' => true, |
There was a problem hiding this comment.
I wonder if instead of a true/false here it should just be the name of the loader to use?
There was a problem hiding this comment.
Good idea 👍 I'll see what I can wire up.
| 'supports_content_node' => true, | ||
| 'supports_post_object_union' => true, | ||
| 'supports_menu_item_object_union' => true, | ||
| 'resolve_from_uri' => true, |
There was a problem hiding this comment.
WordPress already has rules for when objects can/cannot resolve from a URI. If it's a public post type and the post object is published or in some other publicly visible state, it has a URI. The goal is to be able to use queries like nodeByUri( $uri: '/same-url-you-could-use-in-browser )` and be able to get the same node the browser would return.
There was a problem hiding this comment.
So this should be determined by if the post-type's public property is set to true?
| 'connect_to_taxonomies' => true, | ||
| 'supports_content_node' => true, | ||
| 'supports_post_object_union' => true, | ||
| 'supports_menu_item_object_union' => true, |
There was a problem hiding this comment.
WordPress also has rules for this.
show_in_nav_menus: https://developer.wordpress.org/reference/functions/register_post_type/#show_in_nav_menus
If a CPT is set to show in Nav Menus, WPGraphQL should support Nav Menu Items returning that type.
There was a problem hiding this comment.
I know, but this is just determine if it's displayed that way in the schema tree.
| 'connect_to_comments' => true, | ||
| 'connect_to_taxonomies' => true, | ||
| 'supports_content_node' => true, | ||
| 'supports_post_object_union' => true, |
There was a problem hiding this comment.
Hmm. If you use register_post_type() and show_in_graphql your post type is already agreeing to this. 🤔
There was a problem hiding this comment.
Not necessarily, I'm forced to inject the PostObjectUnion using the graphql_union_resolve_type filter just to make it work with Product child types, if this is toggled to true.
| 'register_root_query' => true, | ||
| 'register_root_connection' => true, | ||
| 'connect_to_comments' => true, | ||
| 'connect_to_taxonomies' => true, |
There was a problem hiding this comment.
This case is already handled by registering a post type and taxonomy to be connected to each other and having both set to show_in_graphql. If you set one or the other, or both to not show_in_graphql that decision is respected.
| 'register_schema_type' => true, | ||
| 'register_root_query' => true, | ||
| 'register_root_connection' => true, | ||
| 'connect_to_comments' => true, |
There was a problem hiding this comment.
| 'graphql_plural_name' => str_replace( '_', '', ucwords( strtolower( $post_type ), '_' ) ) . 's', | ||
| 'register_schema_type' => true, | ||
| 'register_root_query' => true, | ||
| 'register_root_connection' => true, |
There was a problem hiding this comment.
what's the use case for this so I can understand more?
There was a problem hiding this comment.
Same thing as the register_root_query. Most of WooGraphQL connections resolve using custom AbstractConnectionResolver classes and not the PostObjectConnectionResolver class. This is due to the fact that they use a WooCommerce Query class and not WP_Query
| 'show_in_graphql' => true, | ||
| 'graphql_single_name' => str_replace( '_', '', ucwords( strtolower( $post_type ), '_' ) ), | ||
| 'graphql_plural_name' => str_replace( '_', '', ucwords( strtolower( $post_type ), '_' ) ) . 's', | ||
| 'register_schema_type' => true, |
There was a problem hiding this comment.
what's the use case for this so I can understand more?
There was a problem hiding this comment.
This would replace the primary use of the skip-post-type-registry WooGraphQL has been using to opt out of using the core PostObject types definition for WooCommerce post-type so it can roll it's own.
There was a problem hiding this comment.
See the example in the PR summary above to see how it will be use for Products in WooGraphQL. ☝️
| 'graphql_single_name' => str_replace( '_', '', ucwords( strtolower( $post_type ), '_' ) ), | ||
| 'graphql_plural_name' => str_replace( '_', '', ucwords( strtolower( $post_type ), '_' ) ) . 's', | ||
| 'register_schema_type' => true, | ||
| 'register_root_query' => true, |
There was a problem hiding this comment.
what's the use case for this so I can understand more?
There was a problem hiding this comment.
The root queries in WooGraphQL are actually rolled for the time being actually 😅.
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
|
This issue has been automatically closed because it has not had recent activity. If you believe this issue is still valid, please open a new issue and mark this as a related issue. |
|
superseded by #2399 |
Your checklist for this pull request
Thanks for sending a pull request! Please make sure you click the link above to view the contribution guidelines, then fill out the blanks below.
🚨Please review the guidelines for contributing to this repository.
What does this implement/fix? Explain your changes.
Adds more Post-type settings related to WPGraphQL and using them to allows post-types to opt-in or out of special points of registration in the GraphQL tree. See the example below to see how this works with the
Producttype of WooGraphQL.Does this close any currently open issues?
Closes #1443
Any relevant logs, error output, GraphiQL screenshots, etc?
(If it’s long, please paste to https://ghostbin.com/ and insert the link here.)
Any other comments?
…
Where has this been tested?
Operating System: …
WordPress Version: …