I am currently sending json string in response to an API request in graphql using absinthe. The schema for it looks like this:
object :export_data do
field :resp_data, :json
end
I want to now send a downloadable json file instead of a json string in the API response. My initial idea was to use a :file
type in the absinthe schema and the return a file from resolver using File.write/2
or whatever data type is supported for files. But I couldn't find a file data type which is supported by absinthe in their documentation. How do I send a json file in a graphql API response?
I think it's better to skip graphql here and do it over the controller. Here is a pseudo example of how to handle downloadable CSV files, also file type can be handled with put_resp_header.
CSV Controller
Router
Csv Template