我试图用下面的代码从我在 Gatsby 的 S3 Bucket 中提取远程图像。我有一个构建经典 S3Object 的 schema.graphql。但是 Gatsby Node 抛出以下错误。在这个问题上,我已经在文档中待了好几天了,有人能指出我正确的方向吗?我只需要将图像放入 Gatsby 的数据层,这样我就可以使用 Gatsby-image。
我觉得我需要更新 S3Object 以扩展节点接口,我现在正在处理这个问题。
错误:
warn `createResolvers` passed resolvers for type `S3Object` that doesn't exist in the schema. Use `createTypes` to add the type before adding resolvers.
架构.graphql
type PortfolioItem @model @key(fields: ["title", "createdAt"]) {
id: ID!
title: String!
file: S3Object
thumbnailUrl: String
...
}
type S3Object {
bucket: String!
key: String!
region: String!
}
盖茨比-node.js
exports.createResolvers = ({ actions, cache, createNodeId, createResolvers, store, reporter }) => {
const { createNode } = actions;
createResolvers({
S3Object: {
imageFile: {
type: `File`,
resolve(source, args, context, info) {
return createRemoteFileNode({
url: 'https://my-aws-bucket-url.s3.us-east-2.amazonaws.com/' + source.key,
store,
cache,
createNode,
createNodeId,
reporter,
});
},
},
},
});
};