Coder Social home page Coder Social logo

Comments (6)

jaydenseric avatar jaydenseric commented on May 29, 2024 1

@tbarkley I have not seen someone trying to send GraphQL multipart requests like that before. There is no mention of this GraphQL multipart request spec in the eko/graphql-go-upload repo, so maybe it's not intended to be compliant?

For this spec, the way to do your example (free-hand, there might be typos):

curl http://localhost:8000/graphql \
  -F operations='{ "query": "mutation DoUpload($file: Upload!, $title: String!) { upload(file: $file, title: $title) }", "variables": { "file": null, "title": "My content title" } }' \
  -F map='{ "file": ["variables.file"] }' \
  -F [email protected] \

Only file variables should be extracted into separate multipart file fields.

As for the general question of purposely sending extraneous multipart form fields, that is something I can't recall discussing; probably it was considered but in all these years we never encountered a use case. If such custom fields were to go anywhere, maybe at the end after the files? I'm not sure from memory what graphql-upload will do if it encounters non file fields after all the expected file fields.

I think an extraneous file field after operations and map will be safely ignored:

https://github.com/jaydenseric/graphql-upload/blob/1772dddbb99c4fd3764fbd4f289111c075dfeb2d/test/public/processRequest.test.js#L297-L345

Although, they will still count for the maxFiles setting:

https://github.com/jaydenseric/graphql-upload/blob/1772dddbb99c4fd3764fbd4f289111c075dfeb2d/test/public/processRequest.test.js#L435-L499

Potentially the wording of the spec could be updated, saying that operations, map, and mapped file fields must be in that order, but can have extraneous fields before, after or interspersed and that they should be ignored by server implementations. For performance though, the first fields should be operations and map so that resolvers can be run sooner.

from graphql-multipart-request-spec.

tbarkley avatar tbarkley commented on May 29, 2024 1

Thank you @jaydenseric for the explanation and help.

from graphql-multipart-request-spec.

jaydenseric avatar jaydenseric commented on May 29, 2024

This repo is for maintaining a specification, it sounds like you have a usage question about a particular (unspecified) implementation.

It looks like you are using the GraphQLUpload scalar from a reasonably modern graphql-upload version, probably your issue is that in variables on the client you are using a File incorrectly for your name variable; probably you meant for the name to be a string. Also, run npm ls graphql-upload and make sure you only have one version installed.

from graphql-multipart-request-spec.

SamuelSSan28 avatar SamuelSSan28 commented on May 29, 2024

No, Im tryng send other arg with the file. But dont work, and i try all types specifications and dont work.

from graphql-multipart-request-spec.

tbarkley avatar tbarkley commented on May 29, 2024

@jaydenseric thank you for your work, could you please clarify or reference how extra form data should be sent? I saw this example and was trying to do the same but not sure of the correct way;

https://medium.com/@vcomposieux/handle-file-uploads-using-a-graphql-middleware-11914ba05bfc

$ curl http://localhost:8000/graphql
-F operations='{ "query": "mutation DoUpload($file: Upload!, $title: String!) { upload(file: $file, title: $title) }",
"variables": { "file": null, "title": null } }'
-F map='{ "file": ["variables.file"], "title": ["variables.title"] }'
-F [email protected]
-F title="My content title

from graphql-multipart-request-spec.

jaydenseric avatar jaydenseric commented on May 29, 2024

For people only reading emails, I made a correction to my previous comment in an edit.

from graphql-multipart-request-spec.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.