Skip to content

Instantly share code, notes, and snippets.

@hl hl/handle_fields.ex
Created Apr 15, 2019

What would you like to do?
defmodule MyApp.Middleware.HandleFields do
@moduledoc false
@behaviour Absinthe.Middleware
alias Absinthe.Resolution
alias Absinthe.Blueprint.Document.Field
@type resolution() :: Absinthe.Resolution.t()
@type field() :: Absinthe.Blueprint.Document.Field.t()
@spec call(resolution(), any()) :: resolution()
def call(resolution, config)
def call(%{context: context} = resolution, _config) do
fields =
|> Resolution.project()
%{resolution | context: Map.put(context, :fields, fields)}
@spec field(field()) :: binary() | map()
def field(%Field{name: name, selections: []}), do: name
def field(%Field{name: name, selections: selections}),
do: %{name =>, &field/1)}
def field(%Field{name: name}), do: name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.