jaydenseric / graphql-multipart-request-spec

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

Always batch operations to make JSON decoding easier in strongly-typed languages #7

Closed giautm closed 6 years ago

giautm commented 6 years ago

Hi, I try to implement this spec with Go lang. But I face issue is: operations can be object or array (in the batch query). Method json.Unmarshal in Go lang required to knows the root object is array or map.

You may consider changing operations to an array, with a single item for the non-batch query?

PS: I have a way to workaround is check the first byte of JSON is [ or not. It not, I can add [ to the begin, and ] to the end, then decode bytes to array.

jaydenseric commented 6 years ago

It's an idea to consider, but I'm leaning towards not doing it.

It would push the burden onto every client implementation to convert unbatched requests into an array, where it does not make clear sense why. Additional logic affects client bundle size; not an issue on the server. Strictly typed GraphQL server implementations already have to conditionally handle objects/arrays for regular batched/non-batched requests. I don't know for sure, but some clients and servers might not even support batching since it is an Apollo thing.

I don't write Go, but Googling reveals it is possible to inspect the first JSON character for { or [ to decide how it should be typed for decoding.

Speccing things around batching as a default might be risky, since interest in batching is waning and it's possible (although unlikely?) the community could drop it some time in the future.

jaydenseric commented 6 years ago

Thanks for the suggestion, but I don't think we'll go ahead with this idea for now. If it gains consensus we can reopen and publish a breaking change in a major update. It's probably a good idea to keep the spec fairly stable though as there are already 4+ implementations.