@@ -268,6 +268,11 @@ def resolve(left:, right:)
268
268
end
269
269
end
270
270
271
+ class ThingIdInput < BaseInputObject
272
+ argument :id , ID , future_schema : true , loads : Thing , as : :thing
273
+ argument :id , Int , future_schema : false , loads : Thing , as : :thing
274
+ end
275
+
271
276
class Query < BaseObject
272
277
field :node , Node do
273
278
argument :id , ID
@@ -285,12 +290,11 @@ def f1
285
290
end
286
291
287
292
field :thing , Thing do
288
- argument :id , ID , future_schema : true
289
- argument :id , Int , future_schema : false
293
+ argument :input , ThingIdInput
290
294
end
291
295
292
- def thing ( id :)
293
- { id : id , database_id : id , uuid : " thing- #{ id } " , legacy_price : "⚛︎ #{ id } 00" , price : { amount : id . to_i * 100 , currency : "⚛︎" } }
296
+ def thing ( input :)
297
+ input [ : thing]
294
298
end
295
299
296
300
field :legacy_thing , LegacyThing , null : false do
@@ -361,6 +365,14 @@ class Mutation < BaseObject
361
365
query ( Query )
362
366
mutation ( Mutation )
363
367
orphan_types ( Place , LegacyPlace , Locale , Region , Country )
368
+
369
+ def self . object_from_id ( id , ctx )
370
+ { id : id , database_id : id , uuid : "thing-#{ id } " , legacy_price : "⚛︎#{ id } 00" , price : { amount : id . to_i * 100 , currency : "⚛︎" } }
371
+ end
372
+
373
+ def self . resolve_type ( type , obj , ctx )
374
+ Thing
375
+ end
364
376
end
365
377
366
378
def check_for_multiple_visible_calls ( context )
@@ -466,7 +478,7 @@ def legacy_schema_sdl
466
478
favoriteLanguage(lang: Language): Language!
467
479
legacyThing(id: ID!): LegacyThing!
468
480
node(id: ID!): Node
469
- thing(id: Int !): Thing
481
+ thing(input: ThingIdInput !): Thing
470
482
yell(scream: Scream!): String!
471
483
}
472
484
GRAPHQL
@@ -479,7 +491,7 @@ def legacy_schema_sdl
479
491
favoriteLanguage(lang: Language): Language!
480
492
legacyThing(id: ID!): LegacyThing!
481
493
node(id: ID!): Node
482
- thing(id: ID !): Thing
494
+ thing(input: ThingIdInput !): Thing
483
495
yell(scream: Scream!): String!
484
496
}
485
497
GRAPHQL
@@ -501,7 +513,7 @@ def legacy_schema_sdl
501
513
}
502
514
GRAPHQL
503
515
504
- query_str = "{ thing(id: 15) { databaseId id uuid } }"
516
+ query_str = "{ thing(input: { id: 15 } ) { databaseId id uuid } }"
505
517
assert_equal [ "Field 'databaseId' doesn't exist on type 'Thing'" , "Field 'uuid' doesn't exist on type 'Thing'" ] , exec_query ( query_str ) [ "errors" ] . map { |e | e [ "message" ] }
506
518
res = exec_future_query ( query_str )
507
519
assert_equal ( { "thing" => { "databaseId" => 15 , "id" => 15 , "uuid" => "thing-15" } } , res [ "data" ] )
@@ -520,18 +532,18 @@ def legacy_schema_sdl
520
532
end
521
533
522
534
it "supports different versions of field arguments" do
523
- res = exec_future_query ( "{ thing(id: \" 15\" ) { id } }" )
535
+ res = exec_future_query ( "{ thing(input: { id: \" 15\" } ) { id } }" )
524
536
assert_equal 15 , res [ "data" ] [ "thing" ] [ "id" ]
525
537
# On legacy, `"15"` is parsed as an int, which makes it null:
526
- res = exec_query ( "{ thing(id: \" 15\" ) { id } }" )
527
- assert_equal [ "Argument 'id' on Field 'thing ' has an invalid value (\" 15\" ). Expected type 'Int!'." ] , res [ "errors" ] . map { |e | e [ "message" ] }
538
+ res = exec_query ( "{ thing(input: { id: \" 15\" } ) { id } }" )
539
+ assert_equal [ "Argument 'id' on InputObject 'ThingIdInput ' has an invalid value (\" 15\" ). Expected type 'Int!'." ] , res [ "errors" ] . map { |e | e [ "message" ] }
528
540
529
- introspection_query = "{ __type(name: \" Query \" ) { fields { name args { name type { name ofType { name } } } } } }"
541
+ introspection_query = "{ __type(name: \" ThingIdInput \" ) { inputFields { name type { name ofType { name } } } } }"
530
542
introspection_res = exec_query ( introspection_query )
531
- assert_equal "Int" , introspection_res [ "data" ] [ "__type" ] [ "fields " ] . find { |f | f [ "name" ] == "thing " } [ "args" ] . first [ "type" ] [ "ofType" ] [ "name" ]
543
+ assert_equal "Int" , introspection_res [ "data" ] [ "__type" ] [ "inputFields " ] . find { |f | f [ "name" ] == "id " } [ "type" ] [ "ofType" ] [ "name" ]
532
544
533
545
introspection_res = exec_future_query ( introspection_query )
534
- assert_equal "ID" , introspection_res [ "data" ] [ "__type" ] [ "fields " ] . find { |f | f [ "name" ] == "thing " } [ "args" ] . first [ "type" ] [ "ofType" ] [ "name" ]
546
+ assert_equal "ID" , introspection_res [ "data" ] [ "__type" ] [ "inputFields " ] . find { |f | f [ "name" ] == "id " } [ "type" ] [ "ofType" ] [ "name" ]
535
547
end
536
548
537
549
it "hides fields from hidden interfaces" do
@@ -654,22 +666,22 @@ def legacy_schema_sdl
654
666
expected_message = "Found two visible definitions for `Money`: MultifieldSchema::Money, MultifieldSchema::MoneyScalar"
655
667
assert_equal expected_message , err . message
656
668
657
- assert_equal "⚛︎100" , exec_query ( "{ thing(id: 1) { price } }" ) [ "data" ] [ "thing" ] [ "price" ]
669
+ assert_equal "⚛︎100" , exec_query ( "{ thing( input: { id: 1 } ) { price } }" ) [ "data" ] [ "thing" ] [ "price" ]
658
670
res = exec_query ( "{ __type(name: \" Money\" ) { kind name } }" )
659
671
assert_equal "SCALAR" , res [ "data" ] [ "__type" ] [ "kind" ]
660
672
assert_equal "Money" , res [ "data" ] [ "__type" ] [ "name" ]
661
- assert_equal ( { "amount" => 200 , "currency" => "⚛︎" } , exec_future_query ( "{ thing(id: 2) { price { amount currency } } }" ) [ "data" ] [ "thing" ] [ "price" ] )
673
+ assert_equal ( { "amount" => 200 , "currency" => "⚛︎" } , exec_future_query ( "{ thing(input: { id: 2} ) { price { amount currency } } }" ) [ "data" ] [ "thing" ] [ "price" ] )
662
674
res = exec_future_query ( "{ __type(name: \" Money\" ) { name kind } }" )
663
675
assert_equal "OBJECT" , res [ "data" ] [ "__type" ] [ "kind" ]
664
676
assert_equal "Money" , res [ "data" ] [ "__type" ] [ "name" ]
665
677
end
666
678
667
679
it "works with subclasses" do
668
- res = exec_query ( "{ legacyThing(id: 1) { price } thing(id: 3) { price } }" )
680
+ res = exec_query ( "{ legacyThing(id: 1) { price } thing(input: { id: 3 } ) { price } }" )
669
681
assert_equal "⚛︎100" , res [ "data" ] [ "legacyThing" ] [ "price" ]
670
682
assert_equal "⚛︎300" , res [ "data" ] [ "thing" ] [ "price" ]
671
683
672
- future_res = exec_future_query ( "{ legacyThing(id: 1) { price } thing(id: 3) { price { amount } } }" )
684
+ future_res = exec_future_query ( "{ legacyThing(id: 1) { price } thing(input: { id: 3 } ) { price { amount } } }" )
673
685
assert_equal "⚛︎100" , future_res [ "data" ] [ "legacyThing" ] [ "price" ]
674
686
assert_equal 300 , future_res [ "data" ] [ "thing" ] [ "price" ] [ "amount" ]
675
687
end
0 commit comments