Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: Implement file upload #656

Closed
hantonelli opened this issue Mar 31, 2019 · 0 comments · Fixed by #655
Closed

proposal: Implement file upload #656

hantonelli opened this issue Mar 31, 2019 · 0 comments · Fixed by #655
Labels
enhancement New feature or request v0.9 Fixed in 0.9.0

Comments

@hantonelli
Copy link

hantonelli commented Mar 31, 2019

It would be nice to support file upload using graphql.
This, https://github.com/jaydenseric/graphql-multipart-request-spec, is an unofficial spec that has been implemented by various providers.

As the spec says

An interoperable multipart form field structure for GraphQL requests, used by various file upload client/server implementations.

From the spec, the PR contains the implementation to handle the "Single file" and "File list" examples. It doesn't implement the "Batching" example.

The main points of the proposal are:
When a user submits an http request with multipart/form-data contentType, then it's assumed that the user is doing a request that involves uploading one or more files, and the payload will be parsed accordingly.
The submitted Form should have 2 keys: operations and map.
The operation value should be the usual operation json.
The map value, as the name says, should be a map, where it's keys are the uploaded file number and the values are the operation variable path where the file should be injected.

The changes in the pull request are:

  • Add graphql.Upload scalar that would be used to Marshal and Unmarshal a file Upload (graphql/upload.go file).
  • Add Upload as an additional types that will be injected if defined in the schema as scalars (codegen/config/config.go file).
  • Modify the handler so only if the request is a multipart/form-data contentType, it's parsed accordingly (handler/graphql.go).
  • Add uploadMaxMemory parameter to Config to define how much of the request body to keep in memory before stating to store on disk (handler/graphql.go).
  • Add fileupload example (example/fileupload folder).
  • Update docs (Update docs/content/reference/scalars.md and add docs/content/reference/file-upload.md)

PR #655
Fixes #342

@hantonelli hantonelli mentioned this issue Mar 31, 2019
2 tasks
@mathewbyrne mathewbyrne added the enhancement New feature or request label Apr 15, 2019
@vektah vektah added the v0.9 Fixed in 0.9.0 label May 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request v0.9 Fixed in 0.9.0
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants