Skip to content

Commit

Permalink
Support passing through object scalars
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaden Wilkinson committed May 12, 2021
1 parent 9cb0900 commit e489948
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/absinthe/phase/document/arguments/parse.ex
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ defmodule Absinthe.Phase.Document.Arguments.Parse do
end
end

defp build_value(%Input.Object{} = normalized, %Type.Scalar{} = _schema_node, _context) do
{:ok, normalized}
end

defp build_value(_normalized, %Type.Scalar{}, _context) do
{:error, :bad_parse}
end
Expand Down
17 changes: 17 additions & 0 deletions lib/absinthe/phase/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,23 @@ defmodule Absinthe.Phase.Schema do
node
end

defp set_schema_node(
%Blueprint.Input.Field{} = node,
%Blueprint.Input.Object{schema_node: %{of_type: %Absinthe.Type.Scalar{}}} = _parent,
_schema,
_adapter
) do
%{
node
| schema_node: %Absinthe.Type.Field{
definition: Absinthe.Fixtures.ArgumentsSchema,
identifier: String.to_atom(node.name),
name: node.name,
type: %Absinthe.Type.NonNull{of_type: :string}
}
}
end

defp set_schema_node(%Blueprint.Input.Field{} = node, parent, schema, adapter) do
case node.name do
"__" <> _ ->
Expand Down
9 changes: 9 additions & 0 deletions test/absinthe/execution/arguments_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ defmodule Absinthe.Execution.ArgumentsTest do
)
end

@graphql """
query {
entities(representations: [{__typename: "Product", upc: "123"}])
}
"""
test "does not give error for object scalars" do
assert {:ok, %{data: %{"entities" => ["ok"]}}} = run(@graphql, @schema)
end

describe "errors" do
@graphql """
query FindUser {
Expand Down
13 changes: 13 additions & 0 deletions test/support/fixtures/arguments_schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ defmodule Absinthe.Fixtures.ArgumentsSchema do
false: "NO"
}

scalar :any do
parse fn value -> {:ok, value} end
serialize fn value -> value end
end

scalar :input_name do
parse fn %{value: value} -> {:ok, %{first_name: value}} end
serialize fn %{first_name: name} -> name end
Expand Down Expand Up @@ -62,6 +67,14 @@ defmodule Absinthe.Fixtures.ArgumentsSchema do
end

query do
field :entities, list_of(:string) do
arg :representations, non_null(list_of(non_null(:any)))

resolve fn %{representations: [%{__typename: "Product", upc: "123"}]}, _ ->
{:ok, ["ok"]}
end
end

field :stuff, :integer do
arg :stuff, non_null(:input_stuff)

Expand Down

0 comments on commit e489948

Please sign in to comment.