jaydenseric / graphql-multipart-request-spec

A spec for GraphQL multipart form requests (file uploads).
1.01k stars 56 forks source link

Ordered fields? #45

Closed justinmakaila closed 4 years ago

justinmakaila commented 4 years ago

Why is there the requirement to order fields in the request? Trying to build something that would handle this in react native with mostly native code handling the requests to ensure execution and completion in the background, but when passing a dictionary of parameters over the bridge to the native code, it's getting ordered and added to the body alphabetically.

Just wanted to know if there were technical limitations/requirements to the field ordering before spending time trying to re-work my native implementation. Thanks!

jaydenseric commented 4 years ago

Yes, the ordering of the fields is required by spec, for technical reasons:

So operations can be resolved while the files are still uploading, the fields are ordered — https://github.com/jaydenseric/graphql-multipart-request-spec#multipart-form-field-structure

The operations field must be first, and the map field must be second.

Implementations such as graphql-upload rely on this order; it has tests ensuring misordered fields result in appropriate errors, e.g:

https://github.com/jaydenseric/graphql-upload/blob/901e5ee7af2f8806e4fe7d704969c1f10280d30a/test/public/processRequest.test.js#L878