Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send a file to response a graphql query? (send a csv file from server to client)

I wanna send a csv file in repose of graphql query. I am using Apollo server and Apollo client and Reactjs. (send a csv file from server to client)

can anybody give me an idea how can I implement it?

like image 875
Saeid Ostad Avatar asked Feb 26 '18 20:02

Saeid Ostad


People also ask

Can GraphQL return CSV?

Yes, you can, but it's not built in and you have to override some things. It's more like a work around. Take these steps and you will get csv output: Add csv = graphene.

How do you send responses in GraphQL?

GraphQL requests can be sent via HTTP POST or HTTP GET requests. GET requests must be sent in the following format. The query, variables, and operation are sent as URL-encoded query parameters in the URL. In either request method (POST or GET), only query is required.

Can GraphQL return files?

Note that the filename of the uploaded file must be the same as the link that you are generating it for, otherwise the upload link will not be valid. The data then gets returned to the GraphQL server which returns an upload link to the frontend.


1 Answers

the Graphql responses JSON format only if you like to download files in the front end you can implement another app like express to upload and download files from/to it.

like image 161
Amir Mehrabi Avatar answered Oct 11 '22 04:10

Amir Mehrabi