FieldEntityReference resolver loads invalid translations.

Created on 4 February 2025, 3 months ago

Problem/Motivation

We have a site with default language of ES-ES. We have a multi-value entity reference field on nodes that reference taxonomy terms. We have a fragment for the entity reference that uses the 'name' of the term and we keep getting an error on requests for certain field values: Cannot return null for non-nullable field "TermTag.name"

We have discovered that one of the terms that the node is referencing was not created in the site default language. The error goes away if we create the missing translation but there is still a problem with graphql because it should fallback to the current entity rather than trying to load a translation that doesn't exist. Note, that this error ONLY happens on requests as its unable to fulfill the 'name' property for the fragment since the proper entity is not actually being returned. I've found that the underlying problem is in the data producer which is using this function from graphql module: https://git.drupalcode.org/project/graphql_compose/-/blob/2.3.x/src/Plug.... That function is incorrectly returning the wrong object with the current language logic.

Steps to reproduce

  1. Create a site with multiple languages.
  2. Create a taxonomy (e.g. tags) with a few terms in it with default language.
  3. Add another term with language NOT using the default language and do not add any other translations.
  4. Add multi-value entity reference field on node (e.g. the default article type will work) referencing the tags taxonomy.
  5. Add a node in default language referencing some terms (in particular include the one that does NOT have translation in default site language).
  6. On the frontend, query for the node using a fragment on the taxonomy field.
  7. This is where the query fails and returns the above error

Proposed resolution

Since the getTranslated() method is borrowed from graphql module, I propose bypass even using it as we are already looping over the referenced entities and can compare the language passed to producer with the language for the referenced entity and add some additional logic that ensures we're not trying to call getTranslation when we shouldn't.

Remaining tasks

Create a patch that resolves the referenced entity to the correct language.

πŸ› Bug report
Status

Active

Version

2.3

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States apmsooner

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024