【发布时间】:2020-09-07 17:25:08
【问题描述】:
我是 Gatsby 的新手,尤其是 有趣的 语法选择(仅对字符串使用模板文字,不包括结束分号)。
我的问题是:您是否需要围绕 graphql 查询的括号?文档并没有真正解释有关使用 graphql 的语法,并且教程中有带括号和不带括号的查询。
Gatsby tutorial - uses surrounding parentheses
exports.createPages = async ({ graphql, actions }) => {
...
const result = await graphql(` <--- parentheses here
query {
allMarkdownRemark {
edges {
node {
fields {
slug
}
}
}
}
}
`)
console.log(JSON.stringify(result, null, 4))
}
Gatsby tutorial - no surrounding parentheses
export const query = graphql` <--- no parentheses here
query {
site {
siteMetadata {
title
}
}
}
`
是因为第一个示例中的await,还是我不理解其他内容?提前谢谢!
【问题讨论】:
标签: gatsby graphql-js