wp-graphql / wp-graphql-acf

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

WooCommerce relation #56

Closed tkorsback closed 11 months ago

tkorsback commented 5 years ago

Hi,

I have a test project with a few CPT relations. Everything is working as expected but when I try to relate a WooCommerce product (I have the WC extension installed) it doesn't show up in GraphiQL. Am I missing something or is the WC extension not supported for relationships?

[
    'key' => 'field_membership_product_relationship',
    'name' => 'product_relationship',
    'label' => __('Product', 'tp-cpt'),
    'type' => 'post_object',
    'post_type' => [
        'product'
    ],
    'show_in_graphql' => true,
],

The same code for a CPT is working like a charm.

jasonbahl commented 5 years ago

@tkorsback hey, how are you registering these relationships? Using a plugin like Posts 2 Posts or something?

tkorsback commented 5 years ago

@jasonbahl Yeah I use Posts 2 Posts for a few CPT relations and that works. The relation that doesn't work it a regular "post_object" relation with no other relation sharing it's name.

jasonbahl commented 5 years ago

Ya, to my knowledge, nobody has written any plugin that converts Post 2 Post relationships to the GraphQL Schema.

I think it would be a super valuable plugin though! But there's for sure work that would need to be done to use the Post 2 Post registry and map it to the WPGraphQL Schema.

tkorsback commented 5 years ago

@jasonbahl But the Posts 2 Posts relations work and shows up in GraphiQL. It's the acf relation to WooCommerce that doesn't show.

jasonbahl commented 5 years ago

πŸ€”I thought your issue above was a snippet of your posts 2 posts registry, and you're asking why it's not working?

I guess I'm not sure what you're asking then.

jasonbahl commented 5 years ago

Maybe provide more code snippets and screenshots of GraphiQL or something so I can understand better what you're after.

tkorsback commented 5 years ago

Sure!

CPT: Membership ACF relation to CPT Company (working):

[
    'key' => 'field_membership_company_relationship',
    'name' => 'company_membership',
    'label' => __('Company', 'tp-cpt'),
    'type' => 'post_object',
    'post_type' => [
        'tp_company'
    ],
    'show_in_graphql' => true,
]

ACF relation to WooCommerce product (not working)

[
    'key' => 'field_membership_product_relationship',
    'name' => 'product_membership',
    'label' => __('Product', 'tp-cpt'),
    'type' => 'post_object',
    'post_type' => [
        'product'
    ],
    'show_in_graphql' => true,
]

GraphiQL: Expanding Place nodes and then MembershipRelations I only see the Company relation, not the Product relation.

jasonbahl commented 5 years ago

Ahhh!

I thought this was Posts 2 Posts code, not ACF code πŸ€¦β€β™‚

Sorry for that confusion!

Yes, this is a known issue right now, because the WPGraphQL for WooCommerce registers the Product post type manually, instead of making use of registering it from the post type registry, so ACF doesn't know that Product is a post type registered to the GraphQL Schema.

@kidunot89 opened a PR over the weekend to address this.

I'm reviewing today and hopefully we can have this resolved here soon.

Sorry again for the confusion πŸ€¦β€β™‚

tkorsback commented 5 years ago

No worries πŸ™

Ah ok, I understand. Nice work! πŸ‘

Nessario commented 4 years ago

I'm experiencing the same issue here, though by upgrading into the v0.4.0 the fields now show up in GraphiQL. But, those won't return any result πŸ€”

jasonbahl commented 4 years ago

@Nessario can you provide more specific details about your scenario so I can replicate and debug?

Nessario commented 4 years ago

@jasonbahl Yeah sure, below is a screenshot of the query.

data

Tested these same fields with other post types, they work fine.

jasonbahl commented 4 years ago

@Nessario I believe @kidunot89 released a new version of WPGraphQL for WooCommerce to play nice with WPGraphQL for ACF v0.3.0. . .perhaps it's a version mis-match issue?

What version of WPGraphQL, WPGraphQL for ACF and WPGraphQL for WooCommerce are you on?

Nessario commented 4 years ago

@jasonbahl I just upgraded to the latest versions of all the mentioned plugins. Now, I'm noticing even the custom taxonomies, registered via CPT UI are missing (WPGraphQL CPT UI is also up to date). I'm experiencing this issue only with the Products post type of Woocommerce, the other post types work perfectly.

zamson commented 4 years ago

@kidunot89 did you ever get relationship field to work? I'm getting an internal server error notice when trying to query for ACF relationship fields with post type product. Pages and posts works fine but not WooCommerce products.

https://share.getcloudapp.com/xQugZEXB

I'm on version 0.4.4 of wp-graphql-woocommerce and 0.6.1 of wp-graphql

joshuaiz commented 4 years ago

Seeing this same issue. I have a CPT 'Artists' registered via custom plugin and have ACF Relationship field 'Release' that I use to choose what WooCommerce product the Artist is associated with.

(The CPT is artists and the ACF Field Group is also artists).

In GraphiQL, the fields show up but nothing is returned and it generates an error:

Query:

{
  artists { // CPT
    nodes {
      artists { // ACF Field Group
        release {
          ... on SimpleProduct {
            id
            name
          }
        }
      }
    }
  }
}

Result:

"errors": [
    {
      "message": "Internal server error",
      "category": "internal",
      "locations": [
        {
          "line": 5,
          "column": 9
        }
      ],
      "path": [
        "artists",
        "nodes",
        0,
        "artists",
        "release",
        0
      ]
    },
//...

I'll probably end up just using a Select field with all the releases in a drop-down as a workaround since I only really need the slug for the time being but it would be great if this worked.

pablo-tapia commented 3 years ago

Hello!

I'm using WPGraphQL 1.0.1, WPGraphQL for Advanced Custom Fields 0.3.4, and WooGraphQL 0.7.0 and it seems this still an issue. I have an ACF Block with a Relationship field that takes Products only and it always returns the message: value \" instance of WPGraphQL\\Model\\Post\", received \"Product\". Either type should provide a \"resolveType\" function or each possible type should provide an \"isTypeOf\" function.",.

Anyone has been able to make it work?

jasonbahl commented 11 months ago

πŸ‘‹πŸ» WPGraphQL for ACF has been re-built over here: https://github.com/wp-graphql/wpgraphql-acf and it has significant improvements to loading data.

I'd be curious to here if anyone that's using WooCommerce + ACF + WPGraphQL has had a chance to use the new version of WPGraphQL for ACF and what your experience has been.

I'm inclined to believe a lot of things are working better, but there's definitely likely edge cases when all the various plugins collide.

Nessario commented 11 months ago

@jasonbahl I've been working on a project with the latest WPGraphQL stack (ACF & WooGraphQL included) and it's been working pretty good so far πŸ‘ŒπŸΌπŸ€žπŸΌ

Thanks for all the work you and the others have put into this πŸ™ŒπŸΌ

jasonbahl commented 11 months ago

Based on how old this is and the report above that the latest WPGraphQL for ACF + WooCommerce + WooGraphQL are working together, I'm going to close this.

This repo will be archived in the not-too-distant future in favor of the re-architected version of the plugin: https://github.com/wp-graphql/wpgraphql-acf, so if you have any new issues after updating to the latest WPGraphQL for ACF, please report over there πŸ™πŸ»