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

Duplicate field notice of seo and isPrimary fields #167

Open
okansahin opened this issue Jan 10, 2024 · 1 comment
Open

Duplicate field notice of seo and isPrimary fields #167

okansahin opened this issue Jan 10, 2024 · 1 comment

Comments

@okansahin
Copy link

I am getting these notices when I use this plugin:

    "type": "DUPLICATE_FIELD",
    "message": "You cannot register duplicate fields on the same Type. The field 'seo' already exists on the type 'Product'. Make sure to give the field a unique name.",
    "field_name": "seo",
    "type_name": "Product"

And for each taxonomies:

    "type": "DUPLICATE_FIELD",
    "message": "You cannot register duplicate fields on the same Type. The field 'isPrimary' already exists on the type 'ProductToProductCategoryConnectionEdge'. Make sure to give the field a unique name.",
    "field_name": "isPrimary",
    "type_name": "ProductToProductCategoryConnectionEdge",

After I for quick lookup I see that

$post_types = \WPGraphQL::get_allowed_post_types();

line is already contains 'product' item. So we don't need to add it manually

array_push($post_types, 'product');

And also for 'Product' type

// if woocommerce is active, add seo to product
if (class_exists('WooCommerce')) {
register_graphql_field('Product', 'seo', [
'type' => 'PostTypeSEO',
'description' => __('The Yoast SEO data of the ContentNode', 'wp-graphql-yoast-seo'),
'resolve' => function ($post, array $args, AppContext $context) {
return wp_gql_seo_get_post_type_graphql_fields($post, $args, $context);
},
]);
}

after I comment out these lines, the notices has gone and the functionality still works as expected.

I didn't examine the repo in detail, as I said, I just did a quick debug to get rid of the problem. Can the repo authors comment on this?

I can also create a PR for this.
And I think #40 is also related with

Thank you

@ashhitch
Copy link
Owner

@okansahin a PR would be very welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants