File tree Expand file tree Collapse file tree 1 file changed +78
-0
lines changed
src/GraphQL.Tests/Utilities Expand file tree Collapse file tree 1 file changed +78
-0
lines changed Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using GraphQL ;
3
+ using Xunit ;
4
+
5
+ namespace GraphQL . Tests . Utilities
6
+ {
7
+ public class SchemaBuilderNestedTypesTests : SchemaBuilderTestBase
8
+ {
9
+ [ Fact ]
10
+ public void supports_nested_graph_types ( )
11
+ {
12
+ var defs = @"
13
+ type Droid {
14
+ id: String
15
+ name: String
16
+ friend: Character
17
+ }
18
+
19
+ type Character {
20
+ name: String
21
+ }
22
+
23
+ type Query {
24
+ hero: Droid
25
+ }
26
+ " ;
27
+
28
+ Builder . Types . Include < DroidType > ( ) ;
29
+ Builder . Types . For ( "Droid" ) . IsTypeOf < Droid > ( ) ;
30
+ Builder . Types . Include < Query > ( ) ;
31
+
32
+ var query = @"{ hero { id name friend { name } } }" ;
33
+ var expected = @"{ 'hero': { 'id' : '1', 'name': 'R2-D2', 'friend': { 'name': 'C3-PO' } } }" ;
34
+
35
+ AssertQuery ( _ =>
36
+ {
37
+ _ . Query = query ;
38
+ _ . Definitions = defs ;
39
+ _ . ExpectedResult = expected ;
40
+ } ) ;
41
+ }
42
+
43
+ public class Droid
44
+ {
45
+ public string Id { get ; set ; }
46
+ public string Name { get ; set ; }
47
+ }
48
+
49
+ public class Character
50
+ {
51
+ public string Name { get ; set ; }
52
+ }
53
+
54
+ public class MyUserContext
55
+ {
56
+ }
57
+
58
+ [ GraphQLMetadata ( "Droid" ) ]
59
+ public class DroidType
60
+ {
61
+ public string Id ( Droid droid ) => droid . Id ;
62
+ public string Name ( Droid droid ) => droid . Name ;
63
+ public Character Friend ( MyUserContext context )
64
+ {
65
+ return new Character { Name = "C3-PO" } ;
66
+ }
67
+ }
68
+
69
+ public class Query
70
+ {
71
+ [ GraphQLMetadata ( "hero" ) ]
72
+ public Droid GetHero ( )
73
+ {
74
+ return new Droid { Id = "1" , Name = "R2-D2" } ;
75
+ }
76
+ }
77
+ }
78
+ }
You can’t perform that action at this time.
0 commit comments