Skip to content

Commit 8d1733a

Browse files
committed
Handle GraphQL::ExecutionError from loading objects during analysis
1 parent 951cb16 commit 8d1733a

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

lib/graphql/analysis.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def analyze_query(query, analyzers, multiplex_analyzers: [])
8181
end
8282
rescue Timeout::Error
8383
[GraphQL::AnalysisError.new("Timeout on validation of query")]
84-
rescue GraphQL::UnauthorizedError
84+
rescue GraphQL::UnauthorizedError, GraphQL::ExecutionError
8585
# This error was raised during analysis and will be returned the client before execution
8686
[]
8787
end

lib/graphql/schema/field.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ def calculate_complexity(query:, nodes:, child_complexity:)
490490
if arguments[:last] && (max_possible_page_size.nil? || arguments[:last] > max_possible_page_size)
491491
max_possible_page_size = arguments[:last]
492492
end
493-
elsif arguments.is_a?(GraphQL::UnauthorizedError)
493+
elsif arguments.is_a?(GraphQL::ExecutionError) || arguments.is_a?(GraphQL::UnauthorizedError)
494494
raise arguments
495495
end
496496

spec/graphql/analysis/max_query_complexity_spec.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,11 @@ def self.resolve_type(abs_type, object, ctx)
190190
end
191191

192192
def self.object_from_id(id, ctx)
193-
{ name: "Loaded thing #{id}" }
193+
if id == "13"
194+
raise GraphQL::ExecutionError, "No Thing ##{id}"
195+
else
196+
{ name: "Loaded thing #{id}" }
197+
end
194198
end
195199

196200
def self.unauthorized_object(err)
@@ -209,5 +213,11 @@ def self.unauthorized_object(err)
209213
res2 = AuthorizedTypeSchema.execute(query_str)
210214
assert_equal ["Unauthorized Object: \"Loaded thing 123\""], res2["errors"].map { |e| e["message"] }
211215
end
216+
217+
it "returns the right error when the loaded object raises an error" do
218+
query_str = "{ things(thingId: \"13\", first: 1) { nodes { name } } }"
219+
res = AuthorizedTypeSchema.execute(query_str, context: { authorized: true })
220+
assert_equal ["No Thing #13"], res["errors"].map { |e| e["message"] }
221+
end
212222
end
213223
end

0 commit comments

Comments
 (0)