absinthe v0.2.2 Absinthe.Type.Definitions
Utility functions to define new types
Summary
Functions
Define a set of arguments
Deprecate a field or argument with an optional reason
Define a set of fields
Declare a list of a type
Add a non-null constraint to a type
Functions
Specs
args([{atom, Keyword.t}]) :: %{atom => Absinthe.Type.Argument.t}
Define a set of arguments.
Examples
The following:
args(
active: [type: :boolean, default_value: true, description: "Limit to active projects"],
category: [type: :string, description: "Limit to category"]
)
Is equivalent to:
%{
active: %Absinthe.Type.Argument{
name: "active",
default_value: true,
description: "Limit to active projects",
type: :boolean
},
category: %Absinthe.Type.Argument{
name: "category",
description: "Limit to category",
type: :string
}
}
There’s a similar convenience function for fields, fields/1
.
Options
For information on the options available for an argument, see Absinthe.Type.Argument
.
Deprecate a field or argument with an optional reason
Examples
Wrap around an argument or a field definition
(of a Absinthe.Type.InputObject
) to deprecate it:
args(
name: deprecate([type: :string, description: "The person's name"])
# ...
)
You can also provide a reason:
args(
age: deprecate([type: :integer, description: "The person's age"],
reason: "None of your business!")
# ...
)
Some usage information for deprecations:
- They make non-null types nullable.
- Currently use of a deprecated argument/field causes an error to be added to the
:errors
entry of a result.
Specs
fields([{atom, Keyword.t}]) :: %{atom => Absinthe.Type.FieldDefinition.t}
Define a set of fields.
Each value defines a field.
Examples
The following:
fields(
item: [
description: "Get an item by ID",
type: :item,
args: args(id: [type: :id]),
resolve: &MyResolver.Item.resolve/2
]
)
Is equivalent to:
%{
item: %Absinthe.Type.FieldDefinition{
name: "item",
description: "Get an item by ID"
type: :string,
args: %{
id: %Absinthe.Type.Argument{
name: "id"
type: :id
}
},
resolve: &MyResolver.Item.resolve/2
}
}
Note the use of args/1
; it is a similar convenience function.
Options
For information on the options available for a field, see Absinthe.Type.FieldDefintion
.