Skip to content

DX: Can't narrow down interface subtypes on an implementing object with register_graphql_field() #3096

@justlevine

Description

@justlevine

Description

When using register_graphql_field(), a DUPLICATE_FIELD error is thrown even if the field being registered is compatible with the existing one.

For example, let's say a NodeWithSeo interface registers the seo: SeoInterface field. I should be able to overwrite PostObject.seo to be type PostObjectSeo implements SeoInterface. However, because at this point in the lifecycle, the interface fields are already merged with the fields in WPObjectType, the blind key-check sees that seo already exists and bails.

Ideally, if the field already exists, the new object type would be compared to see if it is compatible with the interface instead of throwing an error. (However I'm unaware of any internal methods for getting a list of implementing interfaces for a GraphQL object name).

Steps to reproduce

  1. Register your custom interface, e.g. SeoInterface
  2. Register your custom object that implements that interface. e.g. PostObjectSeo.
  3. Create a new interface to add a seo: SeoInterface to all ContentNodes.
  4. Register a custom field on PostObject to override the type of your custom field: seo: PostObjectSeo.
  5. Enable GraphQL Debugging and run the query.

image

Additional context

  • The workaround is manually using the 'graphql_{$type_name}_fields' filter, but that's bad DX.
  • This affects the schema usability for both WPGraphQL for Gravity Forms and WPGraphQL for RankMath Seo.

WPGraphQL Version

1.22.1

WordPress Version

6.5.0

PHP Version

8.1.15

Additional environment details

Ubuntu 20.04 ( wsl2 + devilbox).

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have disabled ALL plugins except for WPGraphQL.

  • Yes
  • My issue is with compatibility with a specific WordPress plugin, and I have listed all my installed plugins (and version info) above.

Metadata

Metadata

Assignees

Labels

close candidateNeeds confirmation before closingneeds: author responseAdditional Pending information from the author has been requested from the authorneeds: discussionRequires a discussion to proceedscope: apiIssues related to access functions, actions, and filterstype: bugIssue that causes incorrect or unexpected behavior

Type

Projects

Status

📋 Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions