Gatsby Graph ql子字段选择错误



我想用盖茨比创建自己的网站。这是第一次使用图形ql,我用Gatsby提供的图形ql-ide查询collect 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: srccomponentsseo.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
}
}
}
`
);

在我的情况下,我向author添加了子字段,所以我应该像一样更改它

graphql`
query {
site {
siteMetadata {
title
description
author {
name
summary
}
}
}
}
`
);

在我的中

src/hooks/use-site-metadata.jsx

我添加了

author {
name,
twitter,
summary
}

它对我有效。

最新更新