Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement overridable global ID translator #93

Merged
merged 15 commits into from
Apr 12, 2018
9 changes: 7 additions & 2 deletions lib/absinthe/relay/node.ex
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ defmodule Absinthe.Relay.Node do
end
end

@doc """
Similar to `from_global_id/2` but raises `RuntimeError` if fails to decode global ID.
Copy link
Contributor Author

@avitex avitex Nov 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bruce Not sure if RuntimeError is correct in this context (same with to_global_id!/2). What do you think?

"""
@spec from_global_id!(global_id_t | nil, Absinthe.Schema.t) :: %{type: atom, id: binary} | nil
def from_global_id!(global_id, schema) do
case from_global_id(global_id, schema) do
Expand Down Expand Up @@ -243,7 +246,10 @@ defmodule Absinthe.Relay.Node do
to_global_id(type.name, source_id, schema)
end
end


@doc """
Similar to `to_global_id/3` but raises `RuntimeError` if fails to encode global ID.
"""
@spec to_global_id!(atom | binary, integer | binary | nil, Absinthe.Schema.t | nil) :: global_id_t | nil
def to_global_id!(node_type, source_id, schema \\ nil) do
case to_global_id(node_type, source_id, schema) do
Expand All @@ -257,7 +263,6 @@ defmodule Absinthe.Relay.Node do
defp translate_global_id(nil, direction, args) do
apply(Absinthe.Relay.Node.IDTranslator.Default, direction, args ++ [nil])
end

defp translate_global_id(schema, direction, args) do
(global_id_translator(:env, schema) || global_id_translator(:schema, schema) || Absinthe.Relay.Node.IDTranslator.Default)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure that the environment setting should be the fallback for the explicit schema (use) setting, not the other way around.

|> apply(direction, args ++ [schema])
Expand Down