Skip to content
This repository was archived by the owner on Jul 25, 2024. It is now read-only.

Commit 683cd82

Browse files
author
Josh Price
authored
Merge pull request #94 from graphql-elixir/issue-59-missing-resolve
Handle missing resolve function head
2 parents a06441f + 020c400 commit 683cd82

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

lib/graphql/execution/resolvable.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ defmodule GraphQL.Execution.ResolveWrapper do
1111
{:ok, fun.()}
1212
rescue
1313
e in RuntimeError -> {:error, e.message}
14+
e in FunctionClauseError -> {:error, "Could not find a resolve function for this query."}
1415
end
1516
end
1617
end

test/graphql/execution/executor_test.exs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,26 @@ defmodule GraphQL.Execution.Executor.ExecutorTest do
133133
assert_data(result, %{g: "Hello, world!", h: "Hello, Joe!"})
134134
end
135135

136+
test "return error when no function matches" do
137+
schema = %Schema{
138+
query: %ObjectType{
139+
name: "RootQueryType",
140+
fields: %{
141+
greeting: %{
142+
type: %String{},
143+
args: %{
144+
name: %{type: %String{}}
145+
},
146+
resolve: fn(_, %{name: name}, _) -> "Hello #{name}!!" end,
147+
}
148+
}
149+
}
150+
}
151+
152+
{_, result } = execute(schema, "query Q{greeting}")
153+
assert_has_error(result, %{message: "Could not find a resolve function for this query."})
154+
end
155+
136156
test "must specify operation name when multiple operations exist" do
137157
{_, result} = execute(TestSchema.schema, "query a {greeting} query b {greeting} query c {greeting}")
138158
assert_has_error(result, %{message: "Must provide operation name if query contains multiple operations."})

0 commit comments

Comments
 (0)