Skip to content

Commit e3b2e05

Browse files
author
Robert Mosolgo
authored
Merge pull request #957 from xuorig/raise-query-string-and-document
Raise when both query string and document are provided to Query
2 parents c737ab9 + 67e22af commit e3b2e05

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/graphql/query.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ def initialize(schema, query_string = nil, query: nil, document: nil, context: n
7878
@query_string = query_string || query
7979
@document = document
8080

81+
if @query_string && @document
82+
raise ArgumentError, "Query should only be provided a query string or a document, not both."
83+
end
84+
8185
# A two-layer cache of type resolution:
8286
# { abstract_type => { value => resolved_type } }
8387
@resolved_types_cache = Hash.new do |h1, k1|

spec/graphql/query_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,28 @@
4444
)}
4545
let(:result) { query.result }
4646

47+
describe "when passed both a query string and a document" do
48+
it "returns an error to the client when query kwarg is used" do
49+
assert_raises ArgumentError do
50+
GraphQL::Query.new(
51+
schema,
52+
query: "{ fromSource(source: COW) { id } }",
53+
document: document
54+
)
55+
end
56+
end
57+
58+
it "returns an error to the client" do
59+
assert_raises ArgumentError do
60+
GraphQL::Query.new(
61+
schema,
62+
"{ fromSource(source: COW) { id } }",
63+
document: document
64+
)
65+
end
66+
end
67+
end
68+
4769
describe "when passed no query string or document" do
4870
it 'returns an error to the client' do
4971
res = GraphQL::Query.new(

0 commit comments

Comments
 (0)