Packages
absinthe_relay
1.4.1
1.6.0
1.5.2
1.5.1
1.5.0
1.5.0-rc.0
1.5.0-beta.0
1.5.0-alpha.0
1.4.6
1.4.5
1.4.4
1.4.3
1.4.2
1.4.1
1.4.0
1.4.0-rc.1
1.4.0-rc.0
1.3.6
1.3.5
1.3.4
1.3.3
1.3.2
1.3.1
1.3.0
1.3.0-rc.0
1.3.0-beta.1
1.3.0-beta.0
1.2.0
1.2.0-alpha0
1.2.0-alpha.3
1.2.0-alpha.2
1.2.0-alpha.1
0.9.4
0.9.3
0.9.2
0.9.1
0.9.0
0.8.1
0.8.0
Relay framework support for Absinthe
Current section
Files
Jump to
Current section
Files
lib/absinthe/relay/node/helpers.ex
defmodule Absinthe.Relay.Node.Helpers do
@moduledoc """
Useful schema helper functions for node IDs.
"""
@doc """
Wrap a resolver to parse node (global) ID arguments before it is executed.
Note: This function is deprecated and will be removed in a future release. Use
the `Absinthe.Relay.Node.ParseIDs` middleware instead.
For each argument:
- If a single node type is provided, the node ID in the argument map will
be replaced by the ID specific to your application.
- If multiple node types are provided (as a list), the node ID in the
argument map will be replaced by a map with the node ID specific to your
application as `:id` and the parsed node type as `:type`.
## Examples
Parse a node (global) ID argument `:item_id` as an `:item` type. This replaces
the node ID in the argument map (key `:item_id`) with your
application-specific ID. For example, `"123"`.
```
resolve parsing_node_ids(&my_field_resolver/2, item_id: :item)
```
Parse a node (global) ID argument `:interface_id` into one of multiple node
types. This replaces the node ID in the argument map (key `:interface_id`)
with map of the parsed node type and your application-specific ID. For
example, `%{type: :thing, id: "123"}`.
```
resolve parsing_node_ids(&my_field_resolver/2, interface_id: [:item, :thing])
```
"""
def parsing_node_ids(resolver, rules) do
fn args, info ->
Absinthe.Relay.Node.ParseIDs.parse(args, rules, info)
|> case do
{:ok, parsed_args} ->
resolver.(parsed_args, info)
error ->
error
end
end
end
end