wp-graphql-woocommerce
wp-graphql-woocommerce copied to clipboard
Query products by status not working properly
Describe the bug When trying to query products by status (draft, trash...), I'm only receiving products that I'm the author of. Considering I'm testing as an admin, all products with this status should be returned. I'm using the last versions of wpgraphql and wpgraphql-woo
To Reproduce Steps to reproduce the behavior:
- Logged as admin, go to GraphQL IDE
- Put the code below
query GetProducts {
products(where: {status: "DRAFT"}) {
nodes {
databaseId
status
}
}
}
Expected behavior It will only return the products that you're author of.
Possible solution
I studied the code and found an incompatibility between wp-graphql
and wp-graphql-woocommerce
. Product and all Woocommerce post types have the 'skip_graphql_type_registry' option. This way, all Woocommerce post types are being ignored and are seen as "private" instead of "public" on this line
What I made to fix it: used this filter to return false. That way the code will follow the native flow and check whether or not the user is able to see.