jaydenseric / graphql-multipart-request-spec

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

Issues with multiple file list example? #60

Closed flimybook closed 2 years ago

flimybook commented 2 years ago
{
  query: `
    mutation($files: [Upload!]!) {
      multipleUpload(files: $files) {
        id
      }
    }
  `,
  variables: {
    files: [
      File, // b.txt
      File // c.txt
    ]
  }
}

For above mutation, you this example- 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

But Here User can upload 1 or 2 or 3 or 5 or any numbers of file. How can I understand user only upload 2 files? If I write above code User only can upload 2 files, If user want to upload 3 or 5 files or any number of files then?

jaydenseric commented 2 years ago

The example shows 2 files in variables, but you could have 1, or 10, it doesn't matter. The important thing is to understand the structure of how each uploaded file is accounted for in the fields of the multipart request. The request can be programmatically generated by looping the files you want to upload; you don't need to hardcode the request with a fixed number of files.

jaydenseric commented 2 years ago

Here is a JavaScript example of dynamically generating a GraphQL multipart request based upon the files used in variables:

https://github.com/jaydenseric/graphql-react/blob/60a2118869923929b51e3e785d9a1498105f4200/public/fetchOptionsGraphQL.js#L52-L68

flimybook commented 2 years ago

Thank you. In you given link Every think is clear. You are very good person...