https://github.com/shavit/absinthe-upload
Absinthe plug to support Apollo upload format
https://github.com/shavit/absinthe-upload
absinthe-graphql absinthe-plug elixir
Last synced: 11 months ago
JSON representation
Absinthe plug to support Apollo upload format
- Host: GitHub
- URL: https://github.com/shavit/absinthe-upload
- Owner: shavit
- Created: 2020-11-13T02:21:04.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-11-16T16:56:36.000Z (over 5 years ago)
- Last Synced: 2025-06-01T16:42:52.665Z (about 1 year ago)
- Topics: absinthe-graphql, absinthe-plug, elixir
- Language: Elixir
- Homepage: https://hexdocs.pm/absinthe_upload
- Size: 9.77 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# AbsintheUpload
[](https://travis-ci.org/shavit/absinthe-upload)
> Absinthe plug to support Apollo upload format
## Installation
If [available in Hex](https://hexdocs.pm/absinthe_upload), the package can be installed
by adding `absinthe_upload` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:absinthe_upload, "~> 0.1.0"}
]
end
```
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm/absinthe_upload). Once published, the docs can
be found at [https://hexdocs.pm/absinthe_upload](https://hexdocs.pm/absinthe_upload).
Add the plug to a Phoenix app:
```
# phoenix_app_web/router.ex
defmodule PhoenixAppWeb.Router do
use PhoenixAppWeb, :router
pipeline :api do
plug(:accepnts, ["json"])
plug(Absinthe.Upload)
...
scope "/graphql" do
forward("/", Absinthe.Plug,
...
```
Add the plug to a Plug router:
```
# app/router.ex
defmodule App.Router do
plug(Absinthe.Upload)
...
```
## Example
Requests with file uploads from Apollo clients has `"map"` and `"operations"`
```
%{
"0" => %Plug.Upload{
content_type: "text/rtf",
filename: "San Francisco.rtf",
path: "/tmp/plug-1605/multipart-1605199833-755605321722586-2"
},
"map" => "{\"0\":[\"variables.attachment\"]}",
"operations" => "{\"query\":\"mutation DemoUpload($attachment: Upload) {\\n demoUpload(attachment: $attachment)\\n}\",\"variables\":{\"attachment\":null},\"operationName\":\"DemoUpload\"}"
}
```
The plug will transform the request to a format Absinthe understands
```
%{
"attachment" => %Plug.Upload{
content_type: "text/rtf",
filename: "San Francisco.rtf",
path: "/tmp/plug-1605/multipart-1605199833-755605321722586-2"
},
"query" => "mutation DemoUpload($attachment: Upload) { demoUpload(attachment: $attachment)}"
}
```
## Test
```
MIX_ENV=test mix test --cover
```