Skip to content

Error when querying products that are ACF relationship field items #253

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

Closed
jholman101 opened this issue Apr 3, 2020 · 13 comments
Closed
Labels
bug Something isn't working
Milestone

Comments

@jholman101
Copy link

jholman101 commented Apr 3, 2020

The relationship field in ACF establishes connections to other Post Types. Product is a Post Type, but WooGraphQL resolves Products differently than WPGraphQL resolves any other type of Post Type, so fields like this that expect a Post model to be returned don't get a Post model returned, but instead a Product.

To Reproduce

  1. Have wp-graphql, wp-graphql-woocommerce, wp-graphql-acf and wp-graphiql installed.

  2. Add an ACF Field group to posts, example field group export below:
    [ { "key": "group_5e85643c0cc84", "title": "Testing Product Relationship issue", "fields": [ { "key": "field_5e85644be0a13", "label": "Post Products", "name": "post_products", "type": "relationship", "instructions": "", "required": 0, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "show_in_graphql": 1, "post_type": [ "product" ], "taxonomy": "", "filters": [ "search", "post_type", "taxonomy" ], "elements": "", "min": "", "max": "", "return_format": "object" } ], "location": [ [ { "param": "post_type", "operator": "==", "value": "post" } ] ], "menu_order": 0, "position": "normal", "style": "default", "label_placement": "top", "instruction_placement": "label", "hide_on_screen": "", "active": true, "description": "", "show_in_graphql": 1, "graphql_field_name": "TestingProductRelationshipIssue" } ]

  3. Run query in wp-graphiql. Sample query below:
    query SampleQuery { __typename posts(first: 10) { edges { node { title TestingProductRelationshipIssue { postProducts { ... on SimpleProduct { id name sku } } } } } } }

Expected behavior
Should return results without errors

Screenshots
https://slack-files.com/T3PDM1KRC-F0118V1GM0D-eab1d0676d

Additional context
Slack message thread about the issue:
https://wp-graphql.slack.com/archives/CCYJRDN4A/p1585794638031200

@kidunot89
Copy link
Collaborator

kidunot89 commented Apr 16, 2020

@jholman101 I have located this issue, but it will take some changes in both WPGraphQL ACF and WooGraphQL for it to be resolved.

I've opened a PR in WPGraphQL ACF with the changes needed there.

If they get merged quickly, I'll include the WooGraphQL changes in Release v0.5.1

@jholman101
Copy link
Author

That is awesome news @kidunot89. Thank you so much for all you're doing with these plugins. It is truly appreciated.

@kidunot89 kidunot89 added the bug Something isn't working label Apr 30, 2020
@kidunot89 kidunot89 added this to the v0.6.0 milestone Apr 30, 2020
@kidunot89 kidunot89 mentioned this issue Jul 29, 2020
5 tasks
@jacobarriola
Copy link
Contributor

Hey @kidunot89. Any update on this? Not sure if there's something I can do in the meantime that's filterable. Looks like @jasonbahl merged in some changes here: wp-graphql/wp-graphql#1391

I do see that there's a closed PR that didn't get merged in the ACF plugin here: wp-graphql/wp-graphql-acf#124

Thanks!

Here's my error message (flexible content field that references products)

{
  "errors": [
    {
      "debugMessage": "Abstract type Page_Mediamodule_MediaModules_ProductModule_Products must resolve to an Object type at runtime for field Page_Mediamodule_MediaModules_ProductModule.products with value \"instance of WPGraphQL\\Model\\Post\", received \"Product\". Either the Page_Mediamodule_MediaModules_ProductModule_Products type should provide a \"resolveType\" function or each possible type should provide an \"isTypeOf\" function.",
      "message": "Internal server error",
      "extensions": {
        "category": "internal"
      },
      "locations": [
        {
          "line": 7,
          "column": 13
        }
      ],
      "path": [
        "pages",
        "nodes",
        0,
        "mediaModule",
        "mediaModules",
        6,
        "products",
        0
      ]
    }
]

@kidunot89
Copy link
Collaborator

kidunot89 commented Sep 15, 2020

@jacobarriola Yea, but it's tied up in the v0.6.0 release right now. Try to get that out this week or beginning of next week.

@jacobarriola
Copy link
Contributor

All good, @kidunot89 👍🏽

I appreciate all of the work.

Ping me if you need testers. I'm knee-deep in a WooGraphQL project atm, so there's lots of stuff for me to test.

@pedropalau
Copy link

I'm having this problem too, does any of those PR were merged?

@alevgal
Copy link

alevgal commented Feb 5, 2021

The same problem. Is there a chance that it will be resolved?

@boxxroom
Copy link

boxxroom commented Feb 26, 2021

I have also just come across this problem when using a Product Relation on this occasion the Taxonomy is accommodation-booking (https://woocommerce.com/products/woocommerce-accommodation-bookings/)

Note: I have also tried the relationship with a standard simple taxonomy and get the same result.

ACF-Flexi-Content-Reviews
WP-GraphQL-Product-Relationship-Error

I followed the breadcrumb here wp-graphql/wp-graphql#1388 | wp-graphql/wp-graphql#1391 which looks to have been merge but doesn't seem to fix this bug.

Any ideas @jasonbahl @kidunot89

Thanks in advance.

@boxxroom
Copy link

boxxroom commented Mar 2, 2021

Really sorry to bump this up so soon after posting and I also appreciate this is OS and that it is a: as and when/if warrants scenario with importance or detriment to the plugin.

I understand this would most likely need further investigation before being able to comment or fix but in the interim is there anything as a workaround that could perhaps band-aid this issue?

I have attempted to use the Example Filter Use: filter shown here (wp-graphql/wp-graphql#1391) (also provided below) to intercept this model behaviour. On logging the filters args within side the if statement it never appears to be satisfied thus no logging.

add_filter( 'graphql_dataloader_pre_get_model', function( $model, $entry, $key, $this ) {

  if ( $entry instanceof \WP_Post && 'product' === $entry->post_type ) {
    return new \WPGraphQL\WooCommerce\Model\Product( $entry );
  }

  return $model;

}, 10, 4 );

Thanks in advance.

UPDATE

I have done some further debugging in to the WP-GraphQL plugin at the point this error is displayed.
wp-graphql/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php #1261 ensureValidRuntimeType()

When dumping out the get_class of the $runtimeType arg and Utils::printSafe($runtimeType) it returns a WPInterfaceType as opposed to WPObjectType which is the expected return.

string(42) "Page_Pagesections_Sections_PopularHolidays"
string(30) "WPGraphQL\Type\WPInterfaceType"
string(7) "Product"

@RodrigoTomeES
Copy link

RodrigoTomeES commented Apr 9, 2021

Hello, is there an update on this issue? I have the same problem

imagen

@boxxroom
Copy link

boxxroom commented Apr 9, 2021

Hi @RodrigoTomeES

Yes, there is an update on this issue here: #449 (comment)

@RodrigoTomeES
Copy link

Hi @RodrigoTomeES

Yes, there is an update on this issue here: #449 (comment)

Hi, yes I saw it, but I have the latest version of the plugins but the errors persists

@brianpereradap
Copy link

Having the same issue, any idea on how to get this resolved?
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

8 participants