wp-graphql / wp-graphql-acf

WPGraphQL for Advanced Custom Fields
https://wpgraphql.com/acf
627 stars 123 forks source link

Multiple Post Object Products not pulling through #356

Closed Steppio closed 1 year ago

Steppio commented 1 year ago

Full error message

_Abstract type Collection_Collectionsdata_SingleProduct must resolve to an Object type at runtime for field Collection_Collectionsdata.singleProduct with value \"instance of WPGraphQL\Model\Post\", received \"Product\". Either the Collection_CollectionsdataSingleProduct type should provide a \"resolveType\" function or each possible type should provide an \"isTypeOf\" function.

Issue

I am able to create a Post Object / Relationship field (‘Featured Product’ for example) and attach this to a custom taxonomy (‘Collections’ for example).

I can then go into the custom Collections taxonomy and save a Featured Product belonging to this collection.

This works well and pulls through on the Wordpress GraphQL IDE

Screenshot 2023-05-01 at 17 24 02 Screenshot 2023-05-01 at 17 27 07

However the issue occurs when I try to change this Post Object field to accept multiple values (using the ‘Select multiple values’ switch). I make this change, save the changes in ACF and then add an additional product to the Featured Product field, and run the same query again:

Screenshot 2023-05-01 at 17 32 45 Screenshot 2023-05-01 at 17 31 50

If I change the ‘Filter by Post Type’ to Post it works with multiple values, however I cannot seem to attach multiple Products to the post type. It always returns that same error

_Abstract type Collection_Collectionsdata_SingleProduct must resolve to an Object type at runtime for field Collection_Collectionsdata.singleProduct with value \"instance of WPGraphQL\Model\Post\", received \"Product\". Either the Collection_CollectionsdataSingleProduct type should provide a \"resolveType\" function or each possible type should provide an \"isTypeOf\" function.

Absolutely any help would be appreciated as this has become quite a big issue now.

Steps to replicate

I’ve created a blank WP instance, installed WooCommerce (v7.6.1) and created two dummy products.

I install the following Gatsby-related / GraphQL plugins:

Name Version
WP Gatsby 2.3.3
WPGraphQL 1.14.3
WPGraphQL for ACF 0.6.1
WooGraphQL 0.12.0 (later versions create app.js errors)

I install Advanced Custom Fields (v6.1.4) and Custom Post Type UI (v1.13.5)

I create a taxonomy called Collections, attach it to the Product Post type and enable it in GraphQL

Screenshot 2023-05-01 at 17 55 55 Screenshot 2023-05-01 at 18 01 44

I then create a single ACF Post Object field group called ‘Featured Product’ and attach it to the taxonomy and filter by Post Type of ‘Product’:

Screenshot 2023-05-01 at 18 03 17 Screenshot 2023-05-01 at 18 03 23 Screenshot 2023-05-01 at 18 08 00

I then go into my Taxonomy and create a new Collection and add a single Featured Product and save it.

Screenshot 2023-05-01 at 18 11 50 Screenshot 2023-05-01 at 18 11 27

I now change this ACF Post Object to ‘Select multiple values’ and add an additional product to the taxonomy Featured Product:

Screenshot 2023-05-01 at 18 13 06

And this produces the exact same error:

Screenshot 2023-05-01 at 18 15 11

Expected Result

I hoped for WpGraphQL to pull through

Things I’ve tried

I’ve tried changing the PHP version from 8 to 7.4 (this has fixed something else regarding mediaItems query issues for me in the past)

I’ve tried using different versions of the WPGatsby / WpGraphQL / WooGraphQL plugins - it seems to be the same whatever I try

I’ve tried using a Relationship field instead - same issue

I’m at a bit of a loss here so any help would be greatly appreciated!

Steppio commented 1 year ago

Due to time constraints I've had to think of a workaround this using Algolia

Any help in the future in regard to this would be greatly appreciated as it costs alot of extra money to use the Algolia method

jasonbahl commented 1 year ago

Hello, this version of WPGraphQL for ACF has many known conflicts with WPGraphQL for WooCommerce.

We believe many of those conflicts have been resolved in the new version of WPGraphQL for ACF being worked on over here: https://github.com/wp-graphql/wpgraphql-acf.

The new version is what we'll be supporting going forward and this repo will be archived in the not-too-distant future.

If you find the same issue exists in the new version, please open a new issue on that repo with steps to reproduce.

From what I can tell, this IS supported in the new version.

Following your steps to reproduce, I was able to query the data:

CleanShot 2023-07-07 at 16 17 33

Attached is the Field Group export that I used:

acf-export-2023-07-07 (2).json.zip

And the plugin versions I'm running: