Skip to content

Commit

Permalink
Add a test for InputObject#prepare + loads
Browse files Browse the repository at this point in the history
  • Loading branch information
rmosolgo committed Apr 25, 2024
1 parent 0799211 commit c72f700
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions spec/graphql/schema/input_object_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,18 @@ def resolve(input:)
end
end

class Thing < GraphQL::Schema::Object
field :name, String
end

class PrepareAndLoadInput < GraphQL::Schema::InputObject
argument :value, String
argument :thing_id, ID, loads: Thing
def prepare
{ value: "Prepared: #{value}", thing: thing }
end
end

class Query < GraphQL::Schema::Object
field :inputs, String do
argument :input, RangeInput
Expand All @@ -407,13 +419,35 @@ def inputs(input:)
def prepare_once(input:)
input.prepared_count
end

field :prepare_and_load, String do
argument :input, PrepareAndLoadInput
end

def prepare_and_load(input:)
"#{input[:value]}/#{input[:thing][:name]}"
end
end

class Schema < GraphQL::Schema
query(Query)

def self.resolve_type(_abs_t, _obj, _ctx)
Thing
end

def self.object_from_id(id, _ctx)
{ name: "Thing #{id}"}
end
end
end

it "calls prepare and loads" do
query_str = "{ prepareAndLoad(input: { value: \"Hello\", thingId: \"123\"}) }"
res = InputObjectPrepareObjectTest::Schema.execute(query_str)
assert_equal "Prepared: Hello/Thing 123", res["data"]["prepareAndLoad"]
end

it "calls prepare on the input object (literal)" do
query_str = <<-GRAPHQL
{ inputs(input: { min: 5, max: 10 }) }
Expand Down

0 comments on commit c72f700

Please sign in to comment.