jaydenseric / graphql-upload

Middleware and an Upload scalar to add support for GraphQL multipart requests (file uploads via queries and mutations) to various Node.js GraphQL servers.
https://npm.im/graphql-upload
MIT License
1.43k stars 131 forks source link

Support Fastify #255

Closed zanechua closed 3 years ago

zanechua commented 3 years ago

Wondering if you would be keen to make a small change to graphqlUploadExpress on how it checks if a request is a multipart request.

Currently the code is using:

if (!request.is('multipart/form-data')) return next();

as the check for multipart requests and i know the .is function is unique to express.

However the rest of the code pretty much works well with fastify and I only had to change that line to:

if (!(/^multipart\/form-data/.test(request.headers['content-type']))) return next();

If we make the change to use plain javascript instead of a specific express function, it's a little more compatible with frameworks somewhat compatible with express. Alternatively, we could create an entire new file called graphlUploadFastify but I think that'll just be duplicating code.

Let me know and if you're fine with the change and I will create a PR for it

zanechua commented 3 years ago

And of course.. I had to learn that you are actually able to access the express request and response by using request.raw and reply.res respectively. So I think this issue is unwarranted.

For those that need to know how to implement this with Fastify and ApolloServer please looked at the linked issue above