@@ -223,11 +223,176 @@ public void GetGraphTypeFromType_Matrix(Type type, bool nullable, TypeMappingMod
223
223
}
224
224
}
225
225
226
+ [ Theory ]
227
+ [ InlineData ( typeof ( IntGraphType ) , typeof ( IntGraphType ) ) ]
228
+ [ InlineData ( typeof ( StringGraphType ) , typeof ( StringGraphType ) ) ]
229
+ [ InlineData ( typeof ( ListGraphType < StringGraphType > ) , typeof ( ListGraphType < StringGraphType > ) ) ]
230
+ [ InlineData ( typeof ( NonNullGraphType < StringGraphType > ) , typeof ( NonNullGraphType < StringGraphType > ) ) ]
231
+ [ InlineData ( typeof ( MyClassObjectType ) , typeof ( MyClassObjectType ) ) ]
232
+ [ InlineData ( typeof ( NonNullGraphType < ListGraphType < ListGraphType < NonNullGraphType < MyClassObjectType > > > > ) , typeof ( NonNullGraphType < ListGraphType < ListGraphType < NonNullGraphType < MyClassObjectType > > > > ) ) ]
233
+ [ InlineData ( typeof ( GraphQLClrOutputTypeReference < int > ) , typeof ( IntGraphType ) ) ]
234
+ [ InlineData ( typeof ( GraphQLClrOutputTypeReference < string > ) , typeof ( StringGraphType ) ) ]
235
+ [ InlineData ( typeof ( ListGraphType < GraphQLClrOutputTypeReference < string > > ) , typeof ( ListGraphType < StringGraphType > ) ) ]
236
+ [ InlineData ( typeof ( NonNullGraphType < GraphQLClrOutputTypeReference < string > > ) , typeof ( NonNullGraphType < StringGraphType > ) ) ]
237
+ [ InlineData ( typeof ( GraphQLClrOutputTypeReference < MyClass > ) , typeof ( MyClassObjectType ) ) ]
238
+ [ InlineData ( typeof ( GraphQLClrOutputTypeReference < MyEnum > ) , typeof ( EnumerationGraphType < MyEnum > ) ) ]
239
+ [ InlineData ( typeof ( NonNullGraphType < ListGraphType < ListGraphType < NonNullGraphType < GraphQLClrOutputTypeReference < MyClass > > > > > ) , typeof ( NonNullGraphType < ListGraphType < ListGraphType < NonNullGraphType < MyClassObjectType > > > > ) ) ]
240
+ public void OutputTypeIsDereferenced ( Type referenceType , Type mappedType )
241
+ {
242
+ var query = new ObjectGraphType ( ) ;
243
+ query . Field ( referenceType , "test" ) ;
244
+ var schema = new Schema
245
+ {
246
+ Query = query
247
+ } ;
248
+ schema . RegisterTypeMapping ( typeof ( MyClass ) , typeof ( MyClassObjectType ) ) ;
249
+ schema . RegisterTypeMapping ( typeof ( MyClass ) , typeof ( MyClassInputType ) ) ;
250
+ schema . Initialize ( ) ;
251
+ schema . Query . Fields . Find ( "test" ) . Type . ShouldBe ( mappedType ) ;
252
+ }
253
+
254
+ [ Theory ]
255
+ [ InlineData ( typeof ( IntGraphType ) , typeof ( IntGraphType ) ) ]
256
+ [ InlineData ( typeof ( StringGraphType ) , typeof ( StringGraphType ) ) ]
257
+ [ InlineData ( typeof ( ListGraphType < StringGraphType > ) , typeof ( ListGraphType < StringGraphType > ) ) ]
258
+ [ InlineData ( typeof ( NonNullGraphType < StringGraphType > ) , typeof ( NonNullGraphType < StringGraphType > ) ) ]
259
+ [ InlineData ( typeof ( MyClassInputType ) , typeof ( MyClassInputType ) ) ]
260
+ [ InlineData ( typeof ( NonNullGraphType < ListGraphType < ListGraphType < NonNullGraphType < MyClassInputType > > > > ) , typeof ( NonNullGraphType < ListGraphType < ListGraphType < NonNullGraphType < MyClassInputType > > > > ) ) ]
261
+ [ InlineData ( typeof ( GraphQLClrInputTypeReference < int > ) , typeof ( IntGraphType ) ) ]
262
+ [ InlineData ( typeof ( GraphQLClrInputTypeReference < string > ) , typeof ( StringGraphType ) ) ]
263
+ [ InlineData ( typeof ( ListGraphType < GraphQLClrInputTypeReference < string > > ) , typeof ( ListGraphType < StringGraphType > ) ) ]
264
+ [ InlineData ( typeof ( NonNullGraphType < GraphQLClrInputTypeReference < string > > ) , typeof ( NonNullGraphType < StringGraphType > ) ) ]
265
+ [ InlineData ( typeof ( GraphQLClrInputTypeReference < MyClass > ) , typeof ( MyClassInputType ) ) ]
266
+ [ InlineData ( typeof ( GraphQLClrInputTypeReference < MyEnum > ) , typeof ( EnumerationGraphType < MyEnum > ) ) ]
267
+ [ InlineData ( typeof ( GraphQLClrInputTypeReference < MappedEnum > ) , typeof ( MappedEnumGraphType ) ) ]
268
+ [ InlineData ( typeof ( NonNullGraphType < ListGraphType < ListGraphType < NonNullGraphType < GraphQLClrInputTypeReference < MyClass > > > > > ) , typeof ( NonNullGraphType < ListGraphType < ListGraphType < NonNullGraphType < MyClassInputType > > > > ) ) ]
269
+ public void InputTypeIsDereferenced_Argument ( Type referenceType , Type mappedType )
270
+ {
271
+ var query = new ObjectGraphType ( ) ;
272
+ query . Field ( typeof ( IntGraphType ) , "test" ,
273
+ arguments : new QueryArguments
274
+ {
275
+ new QueryArgument ( referenceType ) { Name = "arg" }
276
+ } ) ;
277
+ var schema = new Schema
278
+ {
279
+ Query = query
280
+ } ;
281
+ schema . RegisterTypeMapping ( typeof ( MyClass ) , typeof ( MyClassObjectType ) ) ;
282
+ schema . RegisterTypeMapping ( typeof ( MyClass ) , typeof ( MyClassInputType ) ) ;
283
+ schema . RegisterTypeMapping ( typeof ( MappedEnum ) , typeof ( MappedEnumGraphType ) ) ;
284
+ schema . Initialize ( ) ;
285
+ schema . Query . Fields . Find ( "test" ) . Arguments . Find ( "arg" ) . Type . ShouldBe ( mappedType ) ;
286
+ }
287
+
288
+ [ Theory ]
289
+ [ InlineData ( typeof ( IntGraphType ) , typeof ( IntGraphType ) ) ]
290
+ [ InlineData ( typeof ( StringGraphType ) , typeof ( StringGraphType ) ) ]
291
+ [ InlineData ( typeof ( ListGraphType < StringGraphType > ) , typeof ( ListGraphType < StringGraphType > ) ) ]
292
+ [ InlineData ( typeof ( NonNullGraphType < StringGraphType > ) , typeof ( NonNullGraphType < StringGraphType > ) ) ]
293
+ [ InlineData ( typeof ( MyClassInputType ) , typeof ( MyClassInputType ) ) ]
294
+ [ InlineData ( typeof ( NonNullGraphType < ListGraphType < ListGraphType < NonNullGraphType < MyClassInputType > > > > ) , typeof ( NonNullGraphType < ListGraphType < ListGraphType < NonNullGraphType < MyClassInputType > > > > ) ) ]
295
+ [ InlineData ( typeof ( GraphQLClrInputTypeReference < int > ) , typeof ( IntGraphType ) ) ]
296
+ [ InlineData ( typeof ( GraphQLClrInputTypeReference < string > ) , typeof ( StringGraphType ) ) ]
297
+ [ InlineData ( typeof ( ListGraphType < GraphQLClrInputTypeReference < string > > ) , typeof ( ListGraphType < StringGraphType > ) ) ]
298
+ [ InlineData ( typeof ( NonNullGraphType < GraphQLClrInputTypeReference < string > > ) , typeof ( NonNullGraphType < StringGraphType > ) ) ]
299
+ [ InlineData ( typeof ( GraphQLClrInputTypeReference < MyClass > ) , typeof ( MyClassInputType ) ) ]
300
+ [ InlineData ( typeof ( GraphQLClrInputTypeReference < MyEnum > ) , typeof ( EnumerationGraphType < MyEnum > ) ) ]
301
+ [ InlineData ( typeof ( GraphQLClrInputTypeReference < MappedEnum > ) , typeof ( MappedEnumGraphType ) ) ]
302
+ [ InlineData ( typeof ( NonNullGraphType < ListGraphType < ListGraphType < NonNullGraphType < GraphQLClrInputTypeReference < MyClass > > > > > ) , typeof ( NonNullGraphType < ListGraphType < ListGraphType < NonNullGraphType < MyClassInputType > > > > ) ) ]
303
+ public void InputTypeIsDereferenced_DirectiveArgument ( Type referenceType , Type mappedType )
304
+ {
305
+ var query = new ObjectGraphType ( ) ;
306
+ query . Field ( typeof ( StringGraphType ) , "test" ) ;
307
+ var schema = new Schema
308
+ {
309
+ Query = query
310
+ } ;
311
+ var directive = new DirectiveGraphType ( "MyDirective" )
312
+ {
313
+ Arguments = new QueryArguments
314
+ {
315
+ new QueryArgument ( referenceType ) { Name = "arg" }
316
+ }
317
+ } ;
318
+ directive . Locations . Add ( DirectiveLocation . Field ) ;
319
+ schema . Directives . Register ( directive ) ;
320
+ schema . RegisterTypeMapping ( typeof ( MyClass ) , typeof ( MyClassObjectType ) ) ;
321
+ schema . RegisterTypeMapping ( typeof ( MyClass ) , typeof ( MyClassInputType ) ) ;
322
+ schema . RegisterTypeMapping ( typeof ( MappedEnum ) , typeof ( MappedEnumGraphType ) ) ;
323
+ schema . Initialize ( ) ;
324
+ schema . Directives . Find ( "MyDirective" ) . Arguments . Find ( "arg" ) . Type . ShouldBe ( mappedType ) ;
325
+ }
326
+
327
+ [ Theory ]
328
+ [ InlineData ( typeof ( IntGraphType ) , typeof ( IntGraphType ) ) ]
329
+ [ InlineData ( typeof ( StringGraphType ) , typeof ( StringGraphType ) ) ]
330
+ [ InlineData ( typeof ( ListGraphType < StringGraphType > ) , typeof ( ListGraphType < StringGraphType > ) ) ]
331
+ [ InlineData ( typeof ( NonNullGraphType < StringGraphType > ) , typeof ( NonNullGraphType < StringGraphType > ) ) ]
332
+ [ InlineData ( typeof ( MyClassInputType ) , typeof ( MyClassInputType ) ) ]
333
+ [ InlineData ( typeof ( NonNullGraphType < ListGraphType < ListGraphType < NonNullGraphType < MyClassInputType > > > > ) , typeof ( NonNullGraphType < ListGraphType < ListGraphType < NonNullGraphType < MyClassInputType > > > > ) ) ]
334
+ [ InlineData ( typeof ( GraphQLClrInputTypeReference < int > ) , typeof ( IntGraphType ) ) ]
335
+ [ InlineData ( typeof ( GraphQLClrInputTypeReference < string > ) , typeof ( StringGraphType ) ) ]
336
+ [ InlineData ( typeof ( ListGraphType < GraphQLClrInputTypeReference < string > > ) , typeof ( ListGraphType < StringGraphType > ) ) ]
337
+ [ InlineData ( typeof ( NonNullGraphType < GraphQLClrInputTypeReference < string > > ) , typeof ( NonNullGraphType < StringGraphType > ) ) ]
338
+ [ InlineData ( typeof ( GraphQLClrInputTypeReference < MyClass > ) , typeof ( MyClassInputType ) ) ]
339
+ [ InlineData ( typeof ( GraphQLClrInputTypeReference < MyEnum > ) , typeof ( EnumerationGraphType < MyEnum > ) ) ]
340
+ [ InlineData ( typeof ( GraphQLClrInputTypeReference < MappedEnum > ) , typeof ( MappedEnumGraphType ) ) ]
341
+ [ InlineData ( typeof ( NonNullGraphType < ListGraphType < ListGraphType < NonNullGraphType < GraphQLClrInputTypeReference < MyClass > > > > > ) , typeof ( NonNullGraphType < ListGraphType < ListGraphType < NonNullGraphType < MyClassInputType > > > > ) ) ]
342
+ public void InputTypeIsDereferenced_InputField ( Type referenceType , Type mappedType )
343
+ {
344
+ var inputType = new InputObjectGraphType ( ) ;
345
+ inputType . Field ( referenceType , "field" ) ;
346
+ var query = new ObjectGraphType ( ) ;
347
+ query . Field ( typeof ( IntGraphType ) , "test" ,
348
+ arguments : new QueryArguments
349
+ {
350
+ new QueryArgument ( inputType ) { Name = "arg" }
351
+ } ) ;
352
+ var schema = new Schema
353
+ {
354
+ Query = query
355
+ } ;
356
+ schema . RegisterTypeMapping ( typeof ( MyClass ) , typeof ( MyClassObjectType ) ) ;
357
+ schema . RegisterTypeMapping ( typeof ( MyClass ) , typeof ( MyClassInputType ) ) ;
358
+ schema . RegisterTypeMapping ( typeof ( MappedEnum ) , typeof ( MappedEnumGraphType ) ) ;
359
+ schema . Initialize ( ) ;
360
+ var inputTypeActual = schema . Query . Fields . Find ( "test" ) . Arguments . Find ( "arg" ) . ResolvedType . ShouldBeOfType < InputObjectGraphType > ( ) ;
361
+ inputTypeActual . ShouldBe ( inputType ) ;
362
+ inputTypeActual . Fields . Find ( "field" ) . Type . ShouldBe ( mappedType ) ;
363
+ }
364
+
365
+ private class MyClassObjectType : ObjectGraphType < MyClass >
366
+ {
367
+ public MyClassObjectType ( )
368
+ {
369
+ Field < IntGraphType > ( "field" ) ;
370
+ }
371
+ }
372
+
373
+ private class MyClassInputType : InputObjectGraphType
374
+ {
375
+ public MyClassInputType ( )
376
+ {
377
+ Field < IntGraphType > ( "field" ) ;
378
+ }
379
+ }
380
+
226
381
private class MyClass
227
382
{
228
383
}
229
384
230
385
private enum MyEnum
386
+ {
387
+ Value1
388
+ }
389
+
390
+ private enum MappedEnum
391
+ {
392
+ Value1
393
+ }
394
+
395
+ private class MappedEnumGraphType : EnumerationGraphType < MappedEnum >
231
396
{
232
397
}
233
398
}
0 commit comments