Querying Node directly doesn't return correct translation of Link url field

Created on 8 May 2024, 7 months ago
Updated 14 May 2024, 6 months ago

Problem/Motivation

When querying a node by id and a non-source language, all fields return fine, except the "url" value inside a "Link" field.

But, if in the same main query, we also add a nodePage (my content type is of name "Page"), and just call __typename, the previous query returns the correct values.

Steps to reproduce

Context: Content-Type "Pages", and languages "English" ("en", source), and "Portuguese" ("pt")

Error query:

Query variables:
{"langcode": "pt", "nodeId": "[here_the_uuid_of_the_node]"}

query MyPage($langcode: String!, $nodeId: ID! ) {
    node(id: $nodeId, langcode: $langcode) {
    ... on NodePage {
      id
      title
      linkTest {
        title # this is correctly translated
        url # this always returns the source-language url of this field
      }
    }
  }
}

However, if we add to the query a reference to "nodePages" (my custom content type "Pages"), it suddenly resolves correctly.

query MyPage($langcode: String!, $nodeId: ID! ) {
    node(id: $nodeId, langcode: $langcode) {
    ... on NodePage {
      id
      title
      linkTest {
        title  # this is correctly translated
        url  #this now returns the current translated url of this field
      }
    }
  }
  nodePages(last: 1, langcode: $langcode) {
    __typename
  }
}

Proposed resolution

There should be no need to query a reference to receive the correct translation of the "url" value in the "Link" field.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Fixed

Version

2.1

Component

Code

Created by

🇵🇹Portugal bmateus

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

Merge Requests

Comments & Activities

  • Issue created by @bmateus
  • First commit to issue fork.
  • Status changed to Needs review 7 months ago
  • 🇦🇺Australia almunnings Melbourne, 🇦🇺

    Thanks for the bug hunt

    The behaviour explanation could be:

    Edge connections (menus and routes) when using a langcode changes the context of the response using the language_context producer. EG:

    # EdgesSchemaExtension
    $builder->produce('language_context')->map('language', $builder->fromArgument('langcode')),
    

    Which basically tells Drupal "I expect everything and all subsequent results in this language" - Which avoids prop drilling the langcode, at the expense of modifying the entire query (which sometimes sucks if you're batching queries in alternating languages)

    Fundamentally: Without the 'language context', when generating a url, it thinks it's the site default.

    Simple fix: Slam the field's language into the url after generation. Bingo!

  • Status changed to Fixed 6 months ago
  • 🇦🇺Australia almunnings Melbourne, 🇦🇺
  • Status changed to Fixed 6 months ago
  • 🇦🇺Australia almunnings Melbourne, 🇦🇺
  • 🇵🇹Portugal bmateus

    Excellent!

    Thank you, working like a charm.

Production build 0.71.5 2024