简体   繁体   English

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

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

Gentics Mesh Version: v1.5.1 Gentics Mesh 版本:v1.5.1

Intro:介绍:

Let suppose we have schema A with a field of type: list and list type: node and allowed schemas: B .假设我们的模式A具有类型字段:列表和列表类型:节点和允许的模式: B (see (1)). (见(1))。

  • An instance of B node has been created ( b1-EN ) in language en and ( b1-DE ) in de .已在语言en中创建了B节点的实例 ( b1-EN ),在de中创建了 ( b1-DE )。
  • An instance of B node has been created ( b2-EN ) in languages en .已使用en语言创建了B节点的实例 ( b2-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 .已使用de语言创建了A节点的实例 ( a1-DE ),并将b1-DEb2-EN添加到a1的节点列表 ( Bs ) 中。

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 .结果,当在 Gentics Mesh CMS 中选择de语言时,节点a1-DE ( de ) 具有 2 个节点b1-DEb2-EN的列表。

When the following GraphQL query is applied:当应用以下 GraphQL 查询时:

{
  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?为什么结果没有在节点列表中显示 b2-EN 节点? 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.我想得到的结果是节点的默认语言版本( b2-EN ),因为b2-DE尚未贡献。 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):在文档 (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.如果这也失败,将返回 Null。

Can someone enlighten me?有人可以启发我吗?

(1): Schema (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 (2) https://getmesh.io/docs/graphql/#_multilanguage_support

There are some known issues and inconsistent behaviour when loading nodes via GraphQL.通过 GraphQL 加载节点时存在一些已知问题和不一致的行为。 See this issue: https://github.com/gentics/mesh/issues/971看到这个问题: 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 ).在您的情况下,查询的节点列表将始终使用配置的默认语言(在mesh.yml中)。 In your case this seems to be de .在您的情况下,这似乎是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.这意味着您必须在收到响应后过滤代码中所需的语言。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM