我正在尝试使用 Gatsby 制作自己的网站。第一次使用graph-ql,我使用Gatsby提供的graph-ql ide进行查询以收集SiteMeatadata
const data = useStaticQuery(graphql`
query SiteInformationQuery {
__typename
site {
siteMetadata {
author {
name
summary
}
title
description
}
}
}
`);
我预测它会返回
{
"data": {
"site": {
"siteMetadata": {
"title": "Gatsby Typewriter theme",
"author": {
"name": "dodok8",
"summary" : "student"
}
}
}
}
}
但它犯了一个错误。
ERROR #85901 GRAPHQL
There was an error in your GraphQL query:
Field "author" of type "SiteSiteMetadataAuthor" must have a selection of subfields. Did you mean "author { ... }"?
File: src\components\seo.js:21:13
但是我在查询中配置了 author
的所有子文件。我的子字段和查询语句有什么问题?
它是有关存储在 gatsby-config.js
中的 siteMetadata 的原始数据。
module.exports = {
siteMetadata: {
title: `Gatsby Typewriter theme`,
description: `Demo page of Gatsby Typewriter theme`,
author: {
name: 'dodok8',
summary: 'student',
},
},
最佳答案
问题不在于我编写的查询,而是 componets/seo.js
中的基本查询。如果不编辑此文件,第 13 行会有一个查询,
graphql`
query {
site {
siteMetadata {
title
description
author
}
}
}
`
);
就我而言,我向作者添加了子字段,因此我应该将其更改为
graphql`
query {
site {
siteMetadata {
title
description
author {
name
summary
}
}
}
}
`
);
关于reactjs - Gatsby Graph-ql选择子字段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61024666/