Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Product post_type should be set to show_in_graphql #85

Closed
jasonbahl opened this issue Jun 10, 2019 · 2 comments
Closed

Product post_type should be set to show_in_graphql #85

jasonbahl opened this issue Jun 10, 2019 · 2 comments
Assignees
Labels
bug Something isn't working design notes Blueprint and notes for coming feature enhancement New feature or request failing integration Issue concerns a failing/broken integration with another WPGraphQL extension
Milestone

Comments

@jasonbahl
Copy link
Collaborator

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.

@jasonbahl jasonbahl added bug Something isn't working enhancement New feature or request labels Jun 10, 2019
@kidunot89 kidunot89 added this to the v0.1.2 milestone Jun 15, 2019
@kidunot89 kidunot89 self-assigned this Jun 15, 2019
@kidunot89 kidunot89 mentioned this issue Jun 15, 2019
8 tasks
@kidunot89 kidunot89 added the failing integration Issue concerns a failing/broken integration with another WPGraphQL extension label Jun 16, 2019
@kidunot89
Copy link
Member

kidunot89 commented Jun 23, 2019

Solving to this issue will require changes in both WPGraphQL and WooGraphQL.

WPGraphQL

  • A filter needs to be added here to allow for opting out of the WPGraphQL's default WP_Post schema definition.

WooGraphQL

  • A filter must be add here to add product, product_variation, shop_coupon, shop_order, and shop_order_refund to the allow_post_types.
  • A post field for resolving the WP_Post object must be added to the Coupon, Order, Product, ProductVariation, and Refund models.

@kidunot89 kidunot89 added the design notes Blueprint and notes for coming feature label Jun 23, 2019
@kidunot89 kidunot89 removed this from the v0.1.2 milestone Jun 24, 2019
@jake-101
Copy link

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;
     }
  ] );
} );
?>

@kidunot89 kidunot89 pinned this issue Sep 25, 2019
@kidunot89 kidunot89 added this to the v0.2.2 milestone Sep 28, 2019
@kidunot89 kidunot89 modified the milestones: v0.2.2, v0.3.0 Oct 23, 2019
@kidunot89 kidunot89 unpinned this issue Oct 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working design notes Blueprint and notes for coming feature enhancement New feature or request failing integration Issue concerns a failing/broken integration with another WPGraphQL extension
Projects
None yet
Development

No branches or pull requests

3 participants