Apollo GraphQL + Minio - function callback never called

Viewed 195

I'm attempting to upload a file to Minio as part of an Apollo GraphQL mutation. For some reason, the callback in minioClient.putObject() is never called. I used this guide as my starting point: https://www.apollographql.com/docs/apollo-server/data/file-uploads/ and mixed it with Minio's example: https://docs.min.io/docs/javascript-client-api-reference.html#putObject.

Here's my code:

    Mutation: {
        newFile: (parent, args) => {
            return args.file.then(file => {
                //Contents of Upload scalar: https://github.com/jaydenseric/graphql-upload#class-graphqlupload
                //file.createReadStream() is a readable node stream that contains the contents of the uploaded file
                //node stream api: https://nodejs.org/api/stream.html
                const stream = file.createReadStream();

                const fileName = file.filename;
                const mimetype = file.mimetype;
                const metaData = {
                    'Content-Type': mimetype,
                };
                // put it in the bucket
                minioClient.putObject(BUCKETNAME, fileName, stream, metaData, function (err, objInfo) {
                    console.log("shouldn't this run?");
                    if (err) {
                        console.log(err);
                    } else {
                        console.log('File uploaded successfully.');
                        console.log(objInfo);
                    }
                });
                return file;
            });
        },

GraphQL schema:

const typeDefs = gql`
    type File {
        filename: String!
        mimetype: String!
        encoding: String!
    }
    type Mutation {
        newFile(file: Upload!): File!
    }

I get no standard out from the code above. Only when I put console.log() above and below the minioClient.putObject() function.

There are no errors in the Chrome console or in NodeJS output.

I'm stumped as to why this callback isn't executed by the event loop.

0 Answers
Related