AbsintheHelpers.Phases.ApplyTransforms (absinthe_helpers v0.1.7)

The module identifies input nodes with transformation metadata and applies them to the values. These transformations can be applied to both single-value nodes and lists of items.

New transformations can be added in the lib/transforms/ directory, like AbsintheHelpers.Transforms.ToInteger, or within your own project, as long as they implement the same behaviour.

Example usage

To add this phase to your pipeline, add the following to your router:

forward "/graphql",
    to: Absinthe.Plug,
    init_opts: [
      schema: MyProject.Schema,
      pipeline: {__MODULE__, :absinthe_pipeline},
    ]

def absinthe_pipeline(config, opts) do
  config
  |> Absinthe.Plug.default_pipeline(opts)
  |> AbsintheHelpers.Phases.ApplyTransforms.add_to_pipeline(opts)
end

Then apply transforms on a schema field:

alias AbsintheHelpers.Transforms.ToInteger
alias AbsintheHelpers.Transforms.Trim
alias AbsintheHelpers.Transforms.Increment

field :employee_id, :id do
  meta transforms: [Trim, ToInteger, {Increment, 3}]
end

or on a list:

field :employee_ids, non_null(list_of(non_null(:id))) do
  meta transforms: [Trim, ToInteger, {Increment, 3}]
end

or on a schema arg:

field(:create_booking, :string) do
  arg(:employee_id, non_null(:id),
    __private__: [meta: [transforms: [Trim, ToInteger, {Increment, 3}]]]
  )

  resolve(&TestResolver.run/3)
end

In this case, both the Trim, ToInteger, and Increment will be applied to the employee_id field.

Summary

Functions

Link to this function

add_to_pipeline(pipeline, opts)

Link to this function

flag_invalid(node)

@spec flag_invalid(node :: Absinthe.Blueprint.node_t()) :: Absinthe.Blueprint.node_t()
Link to this function

flag_invalid(node, flag)

@spec flag_invalid(node :: Absinthe.Blueprint.node_t(), flag :: atom()) ::
  Absinthe.Blueprint.node_t()
Link to this function

flag_invalid(node, flag, reason)

@spec flag_invalid(
  node :: Absinthe.Blueprint.node_t(),
  flag :: atom(),
  reason :: String.t()
) ::
  Absinthe.Blueprint.node_t()
Link to this function

inherit_invalid(node, children, add_flag)

Link to this function

put_flag(node, flag)

Link to this function

run(input, opts \\ [])

Callback implementation for Absinthe.Phase.run/2.