View Source AbsintheUtils.Middleware.DeprecatedArgs (absinthe_utils v0.0.8)

Absinthe middleware for handling deprecated or renamed field arguments (arg).

It automatically handles mutual exclusivity and changing the argument keys (names) before passing it to the resolver. For this to work, this middleware must be added before the resolver.

Middleware options:

  • legacy_arg_identifier: The identifier of the field that has been deprecated. If this argument is provided, this middleware will rename it to the new_arg_identifier.

  • new_arg_identifier: The identifier of the new field, if passed, nothing changes.

  • is_required: if at least one of the arguments must be provided. If the validation fails, an Absinthe compliant error will be returned and the operation marked as resolved (it will not reach the resolver).

All options are required.

example-usage

Example usage

field :query_with_deprecated_required_args, non_null(:string) do
  arg(:old_arg, :string, deprecate: "Use `newParam` instead.")
  arg(:new_arg, :string)

  # Add the middleware before your resolver
  middleware(
    DeprecatedArgs,
    %{
      legacy_arg_identifier: :old_arg,
      new_arg_identifier: :new_arg,
      is_required: true
    }
  )

  resolve(&MyApp.my_resolver/3)
end