Closed shipcake closed 5 years ago
@shipcake How was this resolved ?
@shipcake wondering the same what was the resolution for this, thank you
In case someone else is stuck with this, I was able to solve it by using processRequest()
:
import { ApolloServer } from "apollo-server-micro"
import { processRequest } from "graphql-upload"
export const config = {
api: {
bodyParser: false,
},
}
const apolloServer = new ApolloServer({
// ...
})
const apolloHandler = apolloServer.createHandler({ path: "/api/graphql" })
export default async (req, res) => {
const contentType = req.headers["content-type"]
if (contentType && contentType.startsWith("multipart/form-data")) {
req.filePayload = await processRequest(req, res)
}
return apolloHandler(req, res)
}
For the guys who are used Next.js and custom express server to apply middleware, you have to move the handle up than middleware:
const express = require("express");
const next = require("next");
const { graphqlUploadExpress } = require("graphql-upload");
const port = 3000;
const dev = process.env.NODE_ENV !== "production";
const app = next({ dev });
const handle = app.getRequestHandler();
app.prepare().then(() => {
const server = express();
server.all("*", (req, res) => handle(req, res));
server.use(
graphqlUploadExpress({
maxFileSize: 10000000, // 10 MB
maxFiles: 20,
})
);
server.listen(port, (err) => {
if (err) throw err;
console.log(`> Ready on http://localhost:${port}`);
});
});
Any drawbacks of using express custom server instead of micro ? I remember reading on Next.JS own docs that custom servers are not compatible with Vercel ...
I use Nextjs 9 and happy to use apollo graphql run same project. but i problem to use graphql-upload in apollo-server-micro
I console.log request income
when I upload in client to server i found error "createReadStream is not a function" :( please help.