私はApollo ServerのUpload
スカラーを直接S3に送信しようとしています。私のスキーマ:
const { gql } = require('apollo-server-express')
module.exports = gql`
extend type Mutation {
createPicture(
name: String!
picture: Upload!
): Picture!
}
type Picture {
name: String!
picture: String!
}
`
_
リゾルバ:
const { combineResolvers } = require('graphql-resolvers')
const isAuthenticated = require('./auth')
const { uploadPhoto } = require('../services/picture')
module.exports = {
Mutation: {
createPicture: combineResolvers(
isAuthenticated,
async (
parent,
{ name, picture = null },
{ models, me }
) => {
const { createReadStream, filename, mimetype, encoding } = await picture
// Does not get past this line
const stream = createReadStream()
uploadPhoto(stream, filename)
const pictureModel = models.Picture.create({
name,
picture
})
return pictureModel
}
)
}
}
_
しかし、私のコードエラーは次のようになります。
internal/util.js:55
function deprecated(...args) {
^
RangeError: Maximum call stack size exceeded
at ReadStream.deprecated [as open] (internal/util.js:55:22)
at ReadStream.open ([truncated]/node_modules/fs-capacitor/lib/index.js:90:11)
at _openReadFs (internal/fs/streams.js:123:12)
at ReadStream.<anonymous> (internal/fs/streams.js:116:3)
at ReadStream.deprecated [as open] (internal/util.js:70:15)
at ReadStream.open ([truncated]/node_modules/fs-capacitor/lib/index.js:90:11)
at _openReadFs (internal/fs/streams.js:123:12)
at ReadStream.<anonymous> (internal/fs/streams.js:116:3)
at ReadStream.deprecated [as open] (internal/util.js:70:15)
at ReadStream.open ([truncated]/node_modules/fs-capacitor/lib/index.js:90:11)
at _openReadFs (internal/fs/streams.js:123:12)
at ReadStream.<anonymous> (internal/fs/streams.js:116:3)
at ReadStream.deprecated [as open] (internal/util.js:70:15)
at ReadStream.open ([truncated]/node_modules/fs-capacitor/lib/index.js:90:11)
at _openReadFs (internal/fs/streams.js:123:12)
at ReadStream.<anonymous> (internal/fs/streams.js:116:3)
at ReadStream.deprecated [as open] (internal/util.js:70:15)
at ReadStream.open ([truncated]/node_modules/fs-capacitor/lib/index.js:90:11)
at _openReadFs (internal/fs/streams.js:123:12)
at ReadStream.<anonymous> (internal/fs/streams.js:116:3)
at ReadStream.deprecated [as open] (internal/util.js:70:15)
at ReadStream.open ([truncated]/node_modules/fs-capacitor/lib/index.js:90:11)
_
注:filename
が正しいので、画像が正しく送信されたことを確認しています
それは このgraphql-upload
。ノード12にダウングレードされ、それは固定されています(解決策は私を助けない)
このエラーはノードバージョン14で私にも起こりました!次のように解決しました。
GraphQL-Uploadの最新バージョンをインストールします。
graphQLPuloadExpressミドルウェアを使用して最大ファイル制限を定義します。
import { graphqlUploadExpress } from "graphql-upload";
const app = express()
app.use(graphqlUploadExpress({ maxFileSize: 1000000000, maxFiles: 10 }));
_
ApolloServerを初期化しながら、アップロードをfalseに設定します
const server = new ApolloServer({
uploads: false,
schema,
});
_
Package.jsonにこれを追加してください。
"resolutions": {
"**/**/fs-capacitor":"^6.2.0",
"**/graphql-upload": "^11.0.0"
}
_
出典: https://github.com/jaydenseric/graphql-upload/issues/170#iSecomment-641938198