Skip to content

Commit

Permalink
Add test for subclass usage of oneOf
Browse files Browse the repository at this point in the history
  • Loading branch information
rmosolgo committed Sep 8, 2022
1 parent 9f16823 commit 352cd6b
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions spec/graphql/schema/input_object_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,39 @@ def f(a:)

res = OneOfSchema.execute(q_str, variables: { args: { arg1: nil } })
assert_equal ["'OneOfInput' requires exactly one argument, but 'arg1' was `null`."], res["errors"].map { |e| e["extensions"]["problems"].map { |p| p["explanation"] } }.flatten
end

it "works with a subclass" do
one_of_object_class = Class.new(GraphQL::Schema::InputObject) do
one_of

def self.member(*args, **kwargs, &block)
argument(*args, required: false, **kwargs, &block)
end
end

one_of_concrete_class = Class.new(one_of_object_class) do
graphql_name "OneOfInput"
member :a, Integer
member :b, Integer
end

assert one_of_concrete_class.one_of?
refute one_of_concrete_class.arguments["a"].type.non_null?

query_type = Class.new(GraphQL::Schema::Object) do
graphql_name "Query"
field :f, Integer do
argument :i, one_of_concrete_class
end
end

schema = Class.new(GraphQL::Schema) do
query(query_type)
end

schema_sdl = schema.to_definition
assert_includes schema_sdl, "input OneOfInput @oneOf {\n"
end
end
end

0 comments on commit 352cd6b

Please sign in to comment.