Gentics Mesh - 多语言支持 - 节点列表中的跨语言 - GraphQL 查询

Gentics Mesh - Multilanguage support - Cross language in a list of node - GraphQL query

Gentics 网格版本:v1.5.1

简介:

假设我们有架构A,字段类型为:list,列表类型为:node 和允许的模式:B。 (见(1))。

因此,当在 Gentics Mesh CMS 中选择 de 语言时,节点 a1-DE (de) 有一个包含 2 个节点的列表 b1-DE, b2-EN.

当应用以下 GraphQL 查询时:

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

结果是:

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

问题:

为什么结果没有在节点列表中显示 b2-EN 节点?查询有误吗?结果我想得到的是节点的默认语言版本 (b2-EN) 因为 b2-DE 还没有贡献.所以预期的结果:

{
  "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"
            }
          }
        ]
      }
    }
  }
}

在文档 (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.

谁能赐教一下?

(1):架构

{
    "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

通过 GraphQL 加载节点时存在一些已知问题和不一致的行为。看到这个问题:https://github.com/gentics/mesh/issues/971

在您的情况下,查询的节点列表将始终使用配置的默认语言(mesh.yml)。在您的情况下,这似乎是 de。这就是为什么只有英语的节点没有结果。

在解决此问题之前,您可以通过加载节点列表的所有语言来解决此问题:

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

您将获得节点列表所有语言的内容。这意味着您必须在收到响应后在代码中过滤所需的语言。