drupal - 如何使用 graphql 获取 drupal 节点的特定翻译

标签 drupal graphql multilingual gatsby

我正在使用 drupal 8 使用 gatsbygraphql 构建 headless 页面。

如何查询页面的翻译?

query MyQuery {
  allNodePage {
    nodes {
      body {
        value
      }
    }
  }
}

我想以特定语言获取此allNodePage.nodes.body.value

编辑: 这是 graphiql allNodePage 实体。

enter image description here

编辑_1:

根据this issue您只能通过修改 drupal 8 中的 api 主机路由 (/fr/jsonapi/node/page) 来查询翻译。

但是在 gatsby-source-drupal-plugin 中,api 主机路由在运行时不可更改。

编辑_2:

我尝试翻译页面节点。默认语言为英语。我想请求 drupal 中存在的德语翻译。

最佳答案

经过一些实验,我发现它还不能与 Drupal JSON API 一起使用,但我让它与 Drupal GraphQL 模块一起工作。这可以与 Gatsby 和 gatsby-source-graphql 一起使用,而不是与 gatsby-source-drupal 一起使用。查询看起来像这样:

{
  nodeQuery(
    filter: {
      conditions:[
        {operator: IN, field: "type", value: ["my_node_type"]},
        {operator: EQUAL, field: "langcode", value: "de"},
      ]
    }
  ) {
    entities {
      ...on NodeMyNodeType {
        entityTranslation(language: DE) {
          entityLabel
        }
      }
    }
  }
}

关于drupal - 如何使用 graphql 获取 drupal 节点的特定翻译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56551190/

相关文章:

php - 我们如何使用 PHP/Drupal 锁定表

apache - Drupal迁移问题

php - dompdf 和 img 标签,图像不会显示

shopify - Liquid:如何以编程方式更改我的 Shopify 主题语言?

javascript - 在 Drupal 7 中使用 JQuery

javascript - 如何在 forEach 中运行 useQuery?

python - graphene-django - 如何过滤?

scala - 如何在 sangria-graphql 中执行突变?

localization - 用于 Web 应用程序的多语言应用程序工具包

php - 如何将一维数组转换为二维数组