我正在使用 drupal 8
使用 gatsby
和 graphql
构建 headless 页面。
如何查询页面的翻译?
query MyQuery {
allNodePage {
nodes {
body {
value
}
}
}
}
我想以特定语言获取此allNodePage.nodes.body.value
。
编辑: 这是 graphiql allNodePage 实体。
编辑_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/