architv
Sending a downloadable file using absinthe graphql
I currently have a grahql API which sends out json as string. I now want to tweak this to be able send a downloadable json file in the API response. My schema currently currently looks like this:
object :export_data do
field :resp_data, :json
end
My initial idea was to change the resp_data type of a file data type and then in the resolver function return a file (using File.write/2). Something like this:
object :export_data do
field :resp_data, :file
end
But I couldn’t find a data type in the absinthe documentation that supports a file. How do I send a downloadable file in a graphql API response?
First Post!
olivermt
You would have to build a custom scalar on both sides or base64 encode.
A much easier solution is to make a short lived Phoenix.Token or JTW that allows for file download (like a url with the token on it, similar to how signed urls work in s3). Pass that in the response and then use js to instigate a download.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








