postmanlabs / postman-app-support

Postman is an API platform for building and using APIs. Postman simplifies each step of the API lifecycle and streamlines collaboration so you can create better APIs—faster.
https://www.postman.com
5.86k stars 840 forks source link

GraphQL multipart request (file uploads) #7072

Open fubar-coder opened 5 years ago

fubar-coder commented 5 years ago

Is your feature request related to a problem? Please describe.

File uploads via GraphQL are only possible when sending the mutation query as a multipart/form-data request, see GraphQL multipart request specification.

Describe the solution you'd like

An additional panel for GraphQL requests where I can specify the files (and the map) to be sent with the GraphQL request, just like the "GraphQL Variables" panel.

Describe alternatives you've considered

Manually creating the multipart/form-data request.

stevemk14ebr commented 4 years ago

please! This is really hard to get right manually as the query blob is json-ified with string escapes for quotes. Ex form:

form-data:

operations: { "query": "mutation($file: Upload) { manualUpload(file: $file input: { sample: { filename: \"test\"} }) { sample { md5} }}", "variables": { "file": null }} map: { "0": ["variables.file"] } 0: test.bin (file type upload from postman selector)

gregaou commented 4 years ago

That would be really good :+1:

AndresDV commented 4 years ago

Any update about this issue ? It will be awesome if you add a file uploader to GraphQL Variables or also to the Environment Variables so we can have files as variables that can be used in mutations or any other type of endpoints

fievelk commented 3 years ago

please! This is really hard to get right manually as the query blob is json-ified with string escapes for quotes. Ex form:

form-data:

operations: { "query": "mutation($file: Upload) { manualUpload(file: $file input: { sample: { filename: \"test\"} }) { sample { md5} }}", "variables": { "file": null }} map: { "0": ["variables.file"] } 0: test.bin (file type upload from postman selector)

@stevemk14ebr Your solution doesn't unfortunately seem to work for me:

{ "0": ["variables.file"] }

seems to just fill the variables.file value with "0", and not with the file that I uploaded in that 0 variable. Do you have suggestions?

ajlive commented 3 years ago

+1, but please don't only support https://github.com/jaydenseric/graphql-multipart-request-spec, as it's not part of the GraphQL spec and is both complicated and underspecified, I'm guessing because it's tied pretty closely to the https://github.com/jaydenseric/graphql-upload implementation.

I'm not saying don't support it: I'm just saying also support constructing multipart-form uploads manually. Basically, as is, but with rich editing for the "query" value, which is in the official spec after all.

thehappycoder commented 3 years ago

This feature would be a game changer for Postman as competitors don't seem to have this feature.

allestaire commented 2 years ago

Examples only supports one file, Is there a way to send out array of files?

{
   "files": []
}

Found the answer here : https://github.com/jaydenseric/graphql-multipart-request-spec

curl localhost:3001/graphql \
  -F operations='{ "query": "mutation($files: [Upload!]!) { multipleUpload(files: $files) { id } }", "variables": { "files": [null, null] } }' \
  -F map='{ "0": ["variables.files.0"], "1": ["variables.files.1"] }' \
  -F 0=@b.txt \
  -F 1=@c.txt
viraj-novo commented 1 year ago

This is a life saver comment @allestaire . Thanks a bunch.

axiomofjoy commented 9 months ago

This is a pain point for me. I love Postman's GraphQL layout, but I can't use it for multipart uploads. Postman doesn't seem to allow you to store mixed collections with both GraphQL and HTTP request types, so as a result, I can't keep all my requests in a single collection.

hickscorp commented 8 months ago

Bump, this is really a pain point for us too. In our case, we use a collection that seems to be "typed" to GQL only requests. There are no options to alter the body in this type of requests...