Great work! I am encountering some issue with file upload. Wondering if you have any clue where i did wrong. Here's the details:
curl -v -L http://localhost:5001/testAPI \
-F operations='{ "query": "mutation($file: Upload!) { singleUpload(file: $file) }", "variables": { "file": null } }' \
-F map='{ "0": ["variables.file"] }' \
-F 0=@[PATH_TO_FILE]
Server just hanging, I can see the file upload being process. but for some reason, it's not calling the resolver.
const express = require('express');
const {
ApolloServer,
gql,
} = require('apollo-server-cloud-functions');
const {
graphqlUploadExpress,
GraphQLUpload
} = require("graphql-upload-minimal");
const typeDefs = gql`
# The implementation for this scalar is provided by the
# 'GraphQLUpload' export from the 'graphql-upload' package
# in the resolver map below.
scalar Upload
input DocumentUploadInput {
docType: String!
file: Upload!
}
type File {
filename: String!
mimetype: String!
encoding: String!
}
type Query {
# This is only here to satisfy the requirement that at least one
# field be present within the 'Query' type. This example does not
# demonstrate how to fetch uploads back.
otherFields: Boolean!
}
type Mutation {
# Multiple uploads are supported. See graphql-upload docs for details.
singleFile(file: DocumentUploadInput!): String!
guff: String
}
`;
const resolvers = {
// This maps the `Upload` scalar to the implementation provided
// by the `graphql-upload` package.
Upload: GraphQLUpload,
Query: {
otherFields: () => {
return true;
},
},
Mutation: {
guff: () => {
return 'ok';
},
singleFile: async (root: any, args: any, context: any) => {
console.log(args);
const {file} = args;
const { createReadStream } = await file;
// // Invoking the `createReadStream` will return a Readable Stream.
// // See https://nodejs.org/api/stream.html#stream_readable_streams
createReadStream();
return 'ok';
},
},
};
const server = new ApolloServer({
typeDefs,
resolvers,
});
export const TestHandler = server.createHandler({
expressAppFromMiddleware(middleware: any) {
const app = express();
app.use(graphqlUploadExpress({ maxFileSize: 10000000, maxFiles: 10, environment: "gcf" }))
app.use(middleware)
return app;
},
});
const testAPI = functions
.https.onRequest(TestHandler);
"apollo-server-cloud-functions": "^3.6.7",
"firebase-admin": "^10.1.0",
"firebase-functions": "^3.20.1",
"graphql": "^16.3.0",
"graphql-upload-minimal": "^1.4.0",