Coder Social home page Coder Social logo

Comments (4)

chubaka avatar chubaka commented on May 29, 2024 1

Thank you very much, your idea for making a new request in the resolver with the right field structure worked. Thanks! Best Regards!

from graphql-multipart-request-spec.

jaydenseric avatar jaydenseric commented on May 29, 2024

The spec has this to say on the naming of the file fields that follow the operations and map fields:

File fields: Each file extracted from the operations object with a unique, arbitrary field name.
https://github.com/jaydenseric/graphql-multipart-request-spec#multipart-form-field-structure

You can use whatever you like for a file field name, as long as it's unique and valid for a HTTP multipart request.

I can't think of a good reason to go to trouble to create special names instead of just using a simple number sequence, but maybe you have a clever idea in mind.

from graphql-multipart-request-spec.

chubaka avatar chubaka commented on May 29, 2024

The reason for this question is that the payload is forwarded from the graphql server to a 2rd server which is expecting name="files" not name="0" and it gives 500 Internal server error.

If the same file is sent via REST the payload is:

Content-Disposition: form-data; name="files"; filename="a.txt"
Content-Type: text/plain

where the name="files" comes from <input name="files />
it does not change it to name="0"

So if there is a workaround it would be appreciated. Thanks!

from graphql-multipart-request-spec.

jaydenseric avatar jaydenseric commented on May 29, 2024

So if there is a workaround it would be appreciated.

Regarding the spec, no "workaround" is needed - what you want to do is perfectly valid.

The backend, or at least a spec-compliant implementation such as graphql-upload, should be fine out of the box.

How to get the client to send the first file field with the files name you want depends on the client. If you are using apollo-upload-client, there is no option to configure file field names so you might need to fork it and hardcode what you like:

https://github.com/jaydenseric/apollo-upload-client/blob/6dec8edc2bb1c97514e1577b84530922a40608bc/src/public/createUploadLink.js#L137-L146

It seems a bit fragile to be forking things and hardcoding field names though; I'm not familiar enough with your infrastructure to comment on a better architecture but it could probably do with a redesign.

the payload is forwarded from the graphql server to a 2rd server

Why don't you forward the upload in your singleUpload mutation resolver? Then you can construct a new request to your other server with whatever field structure you like. That way you don't need a special naming of fields in the original GraphQL multipart request.

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.