graphql-request
graphql-request copied to clipboard
how to send multipart request
how we can upload files through mutation ?
I need this too...
Hello you can send multipart request using below method via Postman
First You have to define your type with GraphqlScalar E.G, const GraphQLProfilePic = new GraphQLScalarType({ name: 'profilePic', parseValue: value => value, parseLiteral() { throw new Error('‘Upload’ scalar literal unsupported.') }, serialize() { throw new Error('‘Upload’ scalar serialization unsupported.') }, })
**{
query: mutation($file: Upload!) { uploadFile(file: $file) { id } }
,
variables: {
file: File // a.txt
}
}
**
First Field
{ "query": "mutation ($file: Upload!) { singleUpload(file: $file) { id } }", "variables": { "file": null } } Second Field { "0": ["variables.file"] } Third Field file where you can use choose file from dropdown instead choosing text field .
This works for me
good ....
any better example? documentation?
@iamfrntdv you can see request format here https://github.com/jaydenseric/graphql-multipart-request-spec
@ferso What do you mean by "This works for me"? What did you implement?
@mayankpandav We're talking about passing multipart data through graphql-request
. Why are you talking about Postman?
Now the real question is: How can we implement a multipart request with graphql-request
?
@nagman are you talking about client side or server side?
@mayankpandav Client. graphql-request
is a GraphQL client.
@mayankpandav Yet we're on the graphql-request
package. Why would you share something from relay-runtime
?
I don't understand the point with this topic.
I too would like to see file upload support in graphql-request using the multipart specification. Is this issue about that and if so why is it closed? AFAIK multipart support is not implemented in graphql-request.
Why is this closed?
You might want to try this package: https://github.com/dividab/graphql-simple-fetch
Bump for this.
I think this feature would be great as well, I'm proxying graphql requests and this was the only feature left to make it complete.
it would be great to have this
I've created PR to solve this issue https://github.com/prisma-labs/graphql-request/pull/175
Meanwhile I've published https://www.npmjs.com/package/awesome-graphql-client with GraphQL Upload support in NodeJS and browsers which also solves https://github.com/prisma-labs/graphql-request/issues/61 and https://github.com/prisma-labs/graphql-request/issues/10 Hope you enjoy!
Thanks @lynxtaa, exactly what I needed
https://github.com/jasonkuhrt/graphql-request/issues/500