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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
# frozen_string_literal: true
require "spec_helper"
describe GraphQL::Language::Nodes::AbstractNode do
describe ".eql?" do
let(:document1) { GraphQL.parse(query_string1) }
let(:document2) { GraphQL.parse(query_string2) }
describe "large identical document" do
let(:query_string1) {%|
query getStuff($someVar: Int = 1, $anotherVar: [String!], $skipNested: Boolean! = false) @skip(if: false) {
myField: someField(someArg: $someVar, ok: 1.4) @skip(if: $anotherVar) @thing(or: "Whatever")
anotherField(someArg: [1, 2, 3]) {
nestedField
...moreNestedFields @skip(if: $skipNested)
}
... on OtherType @include(unless: false) {
field(arg: [{ key: "value", anotherKey: 0.9, anotherAnotherKey: WHATEVER }])
anotherField
}
... {
id
}
}
fragment moreNestedFields on NestedType @or(something: "ok") {
anotherNestedField
}
|}
let(:query_string2) { query_string1 }
it "should be equal" do
assert document1 == document2
assert document2 == document1
end
end
describe "different operations" do
let(:query_string1) { "query { field }" }
let(:query_string2) { "mutation { setField }" }
it "should not be equal" do
refute document1 == document2
refute document2 == document1
end
end
describe "different query fields" do
let(:query_string1) { "query { foo }" }
let(:query_string2) { "query { bar }" }
it "should not be equal" do
refute document1 == document2
refute document2 == document1
end
end
describe "different schemas" do
let(:query_string1) {%|
schema {
query: Query
}
type Query {
field: String!
}
|}
let(:query_string2) {%|
schema {
query: Query
}
type Query {
field: Int!
}
|}
it "should not be equal" do
refute document1.eql?(document2)
refute document2.eql?(document1)
end
end
end
end
|