AbsintheUtils.Middleware.MutuallyExclusiveInputs (absinthe_utils v0.3.0)

View Source

Absinthe middleware for validating mutually exclusive input arguments, so your code doesn't have to.

Example Usage

Simple multiple args:

field :example_query_with_two_args, :example_result do
  arg(:arg_one, :string)
  arg(:arg_two, :string)

  middleware(
    MutuallyExclusiveInputs,
    fields: [:arg_one, :arg_two],
    is_required: true
  )

  resolve(&sample_resolver/3)
end

Nested input object fields:

object :example_input do
  field :field_one, :string
  field :field_two, :string
  field :field_three, :string
end

field :example_query_with_nested_inputs, :example_result do
  arg(:input, :example_input)

  middleware(
    MutuallyExclusiveInputs,
    fields: [
      [:input, :field_one],
      [:input, :field_two],
      [:input, :field_three]
    ],
    is_required: true
  )

  resolve(&MyApp.Resolvers.ExampleResolver.example_query/3)
end

Summary

Functions

has_key?(map, arg2)

@spec has_key?(map :: map(), keys :: [atom()]) :: boolean()