graphql-request icon indicating copy to clipboard operation
graphql-request copied to clipboard

how to send multipart request

Open mayankpandav opened this issue 5 years ago • 18 comments

how we can upload files through mutation ?

mayankpandav avatar Apr 15 '19 03:04 mayankpandav

I need this too...

ferso avatar Jun 18 '19 19:06 ferso

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 .

mayankpandav avatar Jun 21 '19 11:06 mayankpandav

This works for me

ferso avatar Jun 23 '19 08:06 ferso

good ....

mayankpandav avatar Jun 23 '19 11:06 mayankpandav

any better example? documentation?

eduarddotgg avatar Aug 16 '19 22:08 eduarddotgg

@iamfrntdv you can see request format here https://github.com/jaydenseric/graphql-multipart-request-spec

mayankpandav avatar Aug 28 '19 04:08 mayankpandav

@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 avatar Sep 02 '19 16:09 nagman

@nagman are you talking about client side or server side?

mayankpandav avatar Sep 03 '19 16:09 mayankpandav

@mayankpandav Client. graphql-request is a GraphQL client.

nagman avatar Sep 03 '19 16:09 nagman

@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.

nagman avatar Sep 03 '19 17:09 nagman

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.

jonaskello avatar Sep 07 '19 22:09 jonaskello

Why is this closed?

talzion12 avatar Feb 26 '20 13:02 talzion12

You might want to try this package: https://github.com/dividab/graphql-simple-fetch

jonaskello avatar Feb 26 '20 13:02 jonaskello

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.

dsbrgg avatar Mar 02 '20 14:03 dsbrgg

it would be great to have this

pfalomorblab avatar Jun 18 '20 14:06 pfalomorblab

I've created PR to solve this issue https://github.com/prisma-labs/graphql-request/pull/175

lynxtaa avatar Jul 12 '20 09:07 lynxtaa

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!

lynxtaa avatar Jul 20 '20 20:07 lynxtaa

Thanks @lynxtaa, exactly what I needed

warent avatar Aug 24 '20 08:08 warent

https://github.com/jasonkuhrt/graphql-request/issues/500

jasonkuhrt avatar Apr 05 '23 12:04 jasonkuhrt