如何解决GraphQl 查询节点图像 url 与 gatsby-source-drupal 上下文
- 我使用 drupal 作为 Gatsby 站点的无头 CMS。
-
Recipe
的每个节点类型都有一个关联的图像。 - 我正在尝试查询每个
Recipe
图像,而不必跳过所有relationships
。
对于图像是否有比通过 relationships
和 gatsby-source-drupal
进行更直接的 graphql 查询?
Gatsby 自己的 gatsby-source-drupal example 使用 relationships
访问 drupal 节点的图像。
query($slug: String!) {
recipe: nodeRecipe(fields: { slug: { eq: $slug } }) {
title
...
relationships {
image: field_image {
localFile { // NodeType: 'File'
childImageSharp {
fluid(maxWidth: 470,maxHeight: 353) {
...GatsbyImageSharpFluid
}
}
}
}
}
}
}
上下文
根据相关question:
“在 Gatsby 中使用 Drupal 节点要求深入了解节点与媒体实体之间的关系,然后深入了解媒体实体与文件之间的关系。” @Spanners
我不禁认为必须有更好的方法。有问题的查询产生一个节点类型“文件”,这是一个内置的 Gatsby。但是由于我需要将字段附加到图像的节点,我真的不想对内置的 File
节点这样做。感觉应该有另一个节点类型与图像相关联。
更新:
- 这就是我的
localhost:8000/__graphql
的样子
allRecipes { // Query.allRecipes: recipesConnection!
nodes { // recipesConnection.nodes: [recipes!]!
id
relationships { // recipes.relationships: recipesRelationships
image { // recipesRelationships.image: images
relationships { // images.relationships: imagesRelationships
imageFile { // imagesRelationships.imageFile: files
localFile { // files.localFile: File ...
url
} ```
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。