1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
# frozen_string_literal: true
require "spec_helper"
describe GraphQL::StaticValidation::InputObjectNamesAreUnique do
include StaticValidationHelpers
let(:query_string) {%|
query getCheese {
validInputObjectName: searchDairy(product: [{source: YAK}]) { __typename }
duplicateInputObjectNames: searchDairy(product: [{source: YAK, source: YAK}]) { __typename }
}
|}
describe "when queries contain duplicate input fields" do
duplicate_input_field_error = {
"message" => 'There can be only one input field named "source"',
"locations"=>[{ "line" => 4, "column" => 57 }, { "line" => 4, "column" => 70 }],
"path" => ["query getCheese", "duplicateInputObjectNames", "product", 0],
"extensions" => { "code" => "inputFieldNotUnique", "name" => "source" }
}
it "returns errors in the response" do
assert_includes(errors, duplicate_input_field_error)
end
end
describe "with error limiting" do
let(:query_string) {%|
query getCheese {
validInputObjectName: searchDairy(product: [{source: YAK}]) { __typename }
duplicateInputObjectNames: searchDairy(product: [{source: YAK, source: YAK}]) { __typename }
moreDuplicateInputObjectNames: searchDairy(product: [{fatContent: YAK, fatContent: YAK, source: COW}]) { __typename }
}
|}
describe("disabled") do
let(:args) {
{ max_errors: nil }
}
it "does not limit the number of errors" do
assert_equal(error_messages.length, 3)
assert_equal(error_messages, [
"There can be only one input field named \"source\"",
"There can be only one input field named \"fatContent\"",
"Argument 'fatContent' on InputObject 'DairyProductInput' has an invalid value (YAK). Expected type 'Float'."
])
end
end
describe("enabled") do
let(:args) {
{ max_errors: 1 }
}
it "does limit the number of errors" do
assert_equal(error_messages.length, 1)
assert_equal(error_messages, [
"There can be only one input field named \"source\"",
])
end
end
end
end
|