jaydenseric / graphql-multipart-request-spec

A spec for GraphQL multipart form requests (file uploads).
993 stars 54 forks source link

Add GraphQL Yoga to Server implementations #62

Closed ardatan closed 2 years ago

ardatan commented 2 years ago

GraphQL Yoga implements GraphQL Multipart Spec in a different way by using WHATWG Fetch API. https://github.com/dotansimha/graphql-yoga/blob/master/packages/common/src/getGraphQLParameters.ts#L50

jaydenseric commented 2 years ago

Some side notes about the actual implementation: It's great you guys are going for as few dependencies as possible; I'm not salty that you're not using graphql-upload! But I do worry about the implications of such a simple approach, if my shallow understanding of it is correct.

Is it the first sync scenario explained in this graphic?

Sync vs async GraphQL multipart request middleware

It appears you are awaiting the entire multipart request before running any resolvers:

https://github.com/dotansimha/graphql-yoga/blob/c3be07f6a1bd13c34fa8714495dcf6c07483c095/packages/common/src/getGraphQLParameters.ts#L50

If so, there are a few implications…

Also, not something problematic with the general strategy but an opportunity for improvement is error handling for when the GraphQL multipart request has weird/invalid form fields. In the early days before we had really robust checks in graphql-upload for everything that could possible be wrong it was possible to bring down Apollo Server just with a maliciously structured request. Hopefully you are already testing for and handling such errors! You can see all the weird things we test for here:

https://github.com/jaydenseric/graphql-upload/blob/v13.0.0/test/public/processRequest.test.mjs

Aside from tightening security, it's nice to have meaningful error messages presented to the developer in the response if they get the structure of the GraphQL multipart request wrong. For example, somehow here would generate an error message if the operations field is missing:

https://github.com/dotansimha/graphql-yoga/blob/c3be07f6a1bd13c34fa8714495dcf6c07483c095/packages/common/src/getGraphQLParameters.ts#L51