【发布时间】:2020-04-01 22:31:59
【问题描述】:
在 Gatsby 中,如何创建使用 gatsby-source-graphql 插件加载的数据的解析器。我无法弄清楚在解析器中查询数据。这可以做到吗?关于我所缺少的任何建议都会有所帮助。
gatsby-node.js 中的类似内容 ...
exports.createResolvers = ({ createResolvers }) => {
createResolvers({
Query: {
getStructure: {
type: `Structure`,
async resolve(source, args, context, info) {
// assume gatsby-config.js is configured with gatsby-source-graphql and this node exists
const myGraphQlApiNode = await context.nodeModel.runQuery({
query: {
filter: {
fieldName: { eq: "myGqlApi" }
}
},
type: "GraphQLSource"
});
const someGqlApiData = // query all of type MyGqlApi_SomeTypeFromGqlApi loaded via gatsby-source-graphql
return toStructure(someGqlApiData)
}
}
}
});
};
【问题讨论】: