Skip to content

Raise when both query string and document are provided to Query #957

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/graphql/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ def initialize(schema, query_string = nil, query: nil, document: nil, context: n
@query_string = query_string || query
@document = document

if @query_string && @document
raise ArgumentError, "Query should only be provided a query string or a document, not both."
end

# A two-layer cache of type resolution:
# { abstract_type => { value => resolved_type } }
@resolved_types_cache = Hash.new do |h1, k1|
Expand Down
22 changes: 22 additions & 0 deletions spec/graphql/query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,28 @@
)}
let(:result) { query.result }

describe "when passed both a query string and a document" do
it "returns an error to the client when query kwarg is used" do
assert_raises ArgumentError do
GraphQL::Query.new(
schema,
query: "{ fromSource(source: COW) { id } }",
document: document
)
end
end

it "returns an error to the client" do
assert_raises ArgumentError do
GraphQL::Query.new(
schema,
"{ fromSource(source: COW) { id } }",
document: document
)
end
end
end

describe "when passed no query string or document" do
it 'returns an error to the client' do
res = GraphQL::Query.new(
Expand Down