diff --git a/lib/graphql/execution/executor.ex b/lib/graphql/execution/executor.ex index 30ff289..ae512bd 100644 --- a/lib/graphql/execution/executor.ex +++ b/lib/graphql/execution/executor.ex @@ -156,9 +156,15 @@ defmodule GraphQL.Execution.Executor do end end + defp maybe_unwrap(item) when is_tuple(item) do + {result,_} = Code.eval_quoted(item) + result + end + defp maybe_unwrap(item), do: item + defp field_definition(_schema, parent_type, field_name) do # TODO deal with introspection - parent_type.fields[field_name] + maybe_unwrap(parent_type.fields)[field_name] end defp argument_values(arg_defs, arg_asts, variable_values) do diff --git a/test/graphql/execution/executor_test.exs b/test/graphql/execution/executor_test.exs index 96652fc..6d69e22 100644 --- a/test/graphql/execution/executor_test.exs +++ b/test/graphql/execution/executor_test.exs @@ -8,6 +8,31 @@ defmodule GraphQL.Execution.Executor.ExecutorTest do alias GraphQL.Execution.Executor defmodule TestSchema do + def recursive_schema do + %GraphQL.Schema{ + query: %GraphQL.ObjectType{ + name: "Recursive1", + fields: quote do %{ + id: %{type: "Integer", resolve: 1}, + name: %{type: "String", resolve: "Mark"}, + b: %{type: TestSchema.recursive_schema.query }, + c: %{type: TestSchema.recursive_schema_2 } + } end + } + } + end + + def recursive_schema_2 do + %GraphQL.ObjectType{ + name: "Recursive2", + fields: quote do %{ + id: %{type: "Integer", resolve: 2}, + name: %{type: "String", resolve: "Kate"}, + b: %{type: TestSchema.recursive_schema.query } + } end + } + end + def schema do %GraphQL.Schema{ query: %GraphQL.ObjectType{ @@ -73,6 +98,11 @@ defmodule GraphQL.Execution.Executor.ExecutorTest do assert_execute {"{ a }", TestSchema.schema}, %{} end + test "Quoted fields are available" do + assert_execute({"{id, b { name, c{ id, name, b { name }}}}", TestSchema.recursive_schema}, + %{id: 1, b: %{name: "Mark", c: %{id: 2, name: "Kate", b: %{name: "Mark"}}}}) + end + test "simple selection set" do schema = %GraphQL.Schema{ query: %GraphQL.ObjectType{