Describe the bug
Currently, the Product Type is registered to the Schema without respect to post_type registry.
Since Products in WooCommerce are Post Types, we should use the Post Type registry to set the post_type to show_in_graphql instead of registering the Product type without connection to the Post Type it represents.
By extending the Post Type registry, other plugins can know what Post Types are exposed to GraphQL.
For example, the WPGraphQL for ACF plugin checks for all post types that are set to show_in_graphql using the following:
get_post_types( 'show_in_graphql' => true ) and the product post type isn't included because the Post Type registry has no knowledge that the Product post_type is exposed to GraphQL.
We should make use of the internal WordPress registries as much as possible and extend them so that other tools in the ecosystem can benefit as much as possible.
Solving to this issue will require changes in both WPGraphQL and WooGraphQL.
I bought the WPGraphQL ACF plugin and was disappointed it didnt work with WooCommerce. This snippet worked for me in most places I needed it. https://gist.github.com/jake-101/5c930e5af129ecd9f003cac9c7f13273
<?php
add_action( 'graphql_register_types', function() {
register_graphql_field( 'Product', 'tech_specs', [
'type' => 'String',
'description' => __( 'tech specs', 'wp-graphql' ),
'resolve' => function( $post ) {
$id = $post->ID;
$specs = get_field( "tech_specs",$id);
$enc = strip_tags($specs,"<p>,<br>,<ul>,<li>");
return $enc;
}
] );
} );
?>