0

Gentics Mesh Version : v1.5.1

Intro:

Let suppose we have schema A with a field of type: list and list type: node and allowed schemas: B. (see (1)).

  • An instance of B node has been created (b1-EN) in language en and (b1-DE) in de.
  • An instance of B node has been created (b2-EN) in languages en.
  • An instance of A node has been created (a1-DE) in language de and b1-DE and b2-EN are added in the node list (Bs) of a1.

As result, when selecting de language in the Gentics Mesh CMS, Node a1-DE (de) has a list of 2 nodes b1-DE, b2-EN.

When the following GraphQL query is applied :

{
  node(path: "/a1-DE") {
      ... on A {
        path
        uuid
        availableLanguages
        fields {
          Bs {
            ... on B {
              path
              fields {
                id
              }
            }
          }
       }
    }
  }
}

The result is :

{
  "data": {
    "node": {
      "path": "/a1-DE",
      "uuid": "30dfd534cdee40dd8551e6322c6b1518",
      "availableLanguages": [
        "de"
      ],
      "fields": {
        "Bs": [
          {
            "path": "/b1-DE",
            "fields": {
              "id": "b1-DE"
            }
          },
          {
            "path": null,
            "fields": null
          }
        ]
      }
    }
  }
}

Question:

Why the result is not showing the b2-EN node in the list of nodes ? Is the query wrong ? What I would like to get as result is the default language version of the node (b2-EN) because the b2-DE is not contributed yet. so the expected result :

{
  "data": {
    "node": {
      "path": "/a1-DE",
      "uuid": "30dfd534cdee40dd8551e6322c6b1518",
      "availableLanguages": [
        "de"
      ],
      "fields": {
        "Bs": [
          {
            "path": "/b1-DE",
            "fields": {
              "id": "b1-DE"
            }
          },
          {
            "path": "/b2-EN",
            "fields": {
              "id": "b2-EN"
            }
          }
        ]
      }
    }
  }
}

In the documentation (2):

The fallback to the configured default language will be applied if no other matching content found be found. Null will be returned if this also fails.

Can someone enlighten me ?

(1): Schema

{
    "name": "A",
    "container": false,
    "autoPurge": false,
    "displayField": "id",
    "segmentField": "id",
    "urlFields": [
        "id"
    ],
    "fields": [
        {
            "name": "Bs",
            "type": "list",
            "label": "Bs",
            "required": false,
            "listType": "node",
            "allow": [
                "B"
            ]
        },
        {
            "name": "id",
            "type": "string",
            "label": "id",
            "required": true
        }
    ]
}

(2) https://getmesh.io/docs/graphql/#_multilanguage_support

1 Answers1

1

There are some known issues and inconsistent behaviour when loading nodes via GraphQL. See this issue: https://github.com/gentics/mesh/issues/971

In your case, the queried list of nodes will always be in the configured default language (in mesh.yml). In your case this seems to be de. This is why the English-only node yields no result.

Until this is fixed, you can work around this issue by loading all languages of the node list:

{
  node(path: "/a1-DE") {
      ... on A {
        path
        uuid
        availableLanguages
        fields {
          Bs {
            ... on B {
              languages {
                path
                language
                fields {
                  id
                }
              }
            }
          }
       }
    }
  }
}

You will the contents of all languages of the node list. This means that you will have to filter for the desired language in your code after receiving the response.

PGuertler
  • 243
  • 1
  • 2
  • 6
  • "de" was used because "en" is my default language in mesh.yml file (defaultLanguage : "en"). That's why I don't get why I don't get "en" version of the node. – Martin Bogaert May 26 '20 at 11:25
  • With your query I get : "fields": { "Bs": [ { "languages": [ { "path": "/b1-EN", "language": "en" }, { "path": "/b1-DE", "language": "de" } ] }, { "languages": [ { "path": "/b2-EN", "language": "en" } ] } ] } – Martin Bogaert May 26 '20 at 11:28
  • The question is : Architecturally speaking, Gentics Mesh API should or should not return the default language node version if the node in the queried language is not created. In the example above, should Gentics Mesh should return { "path": "/b2-EN", "fields": { "id": "b2-EN" } } or not ? – Martin Bogaert May 26 '20 at 11:33
  • You can see how it works for node reference lists here: https://github.com/gentics/mesh/blob/2b65a01c33d5db9b2cb3a3db6566433882188bb2/verticles/graphql/src/main/java/com/gentics/mesh/graphql/type/field/FieldDefinitionProvider.java#L315 For the parent node you used the path to fetch the node. The path is language specific, so you will always get the node in the language that matches the path. The node reference list actually looks for nodes of the same language of the initially queried node. That's why you get nodes in language `de`. We want to change this to make this less confusing. – PGuertler May 27 '20 at 07:43
  • Your answer is pretty clear, I do get that the path is closely linked to the language version as the identifier is unique and specific to the language version of a specific node. In my example a1-DE is the ID of the DE version of the node. Though, I don't get why in the UI I can assign b2-EN (where DE doesn't exist) and when I'm writing the query to get DE version I get this ambiguous result. As you mentioned in your original answer. The explanation of the issue is not easy though ... – Martin Bogaert May 27 '20 at 12:06