I am trying to use Apollo Server's Upload scalar to send files to S3 directly. My schema:
const { gql } = require('apollo-server-express')
module.exports = gql`
extend type Mutation {
  createPicture(
    name: String!
    picture: Upload!
  ): Picture!
}
type Picture {
  name: String!
  picture: String!
}
`
Resolver:
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
      }
    )
  }
}
But my code errors like this:
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)
Note: I am sure the image was sent correctly, as filename is correct
Add this to package.json:
"resolutions": {
    "**/**/fs-capacitor":"^6.2.0",
    "**/graphql-upload": "^11.0.0"
  }
source: https://github.com/jaydenseric/graphql-upload/issues/170#issuecomment-641938198
Turns out it was this bug in graphql-upload. Downgraded to node 12 and it's fixed (solution listed there did not help me)
This error occured to me in node version 14 too! I solved it as follows:
Install latest version of graphql-upload !
use graphqlUploadExpress middleware to define the maximum file limit.
import { graphqlUploadExpress } from "graphql-upload";
const app = express()
app.use(graphqlUploadExpress({ maxFileSize: 1000000000, maxFiles: 10 }));
Set uploads to false while initializing the ApolloServer
  const server = new ApolloServer({
    uploads: false,
    schema,
  });
Since it is a bug with fs-capacitor, this would help as we can see in this issue
Worked for me in node 14.16.1 with the following configuration:
"resolutions": {
    "fs-capacitor": "^6.2.0",
    "graphql-upload": "^11.0.0"
}
I needed to add force-resolutions inside "scripts"
"scripts": {
    ....
    "preinstall": "npx npm-force-resolutions"
}
Remove ./node_modules and install dependencies again with npm install.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With