@@ -15,6 +15,22 @@ String getShapeInfo($Shape data) {
15
15
}
16
16
}
17
17
18
+ String getShapeInfoNoRefs ($Shape data) {
19
+ final shape = data.shape;
20
+ final type = shape.$__typename;
21
+ final area = shape.area;
22
+
23
+ final square = shape.asSquare ();
24
+ if (square != null ) {
25
+ return "$type (area: $area , sideLength: ${square .sideLength })" ;
26
+ }
27
+
28
+ final rectangle = shape.asRectangle ();
29
+ if (rectangle != null ) {
30
+ return "$type (area: $area , sideLengthA: ${rectangle .sideLengthA }, sideLengthB: ${rectangle .sideLengthB })" ;
31
+ }
32
+ }
33
+
18
34
void main () {
19
35
group ("shape" , () {
20
36
test ("square" , () async {
@@ -48,4 +64,37 @@ void main() {
48
64
);
49
65
});
50
66
});
67
+
68
+ group ("shape without ref to generated classes" , () {
69
+ test ("square" , () async {
70
+ const shapeData = < String , dynamic > {
71
+ "shape" : < String , dynamic > {
72
+ "__typename" : "Square" ,
73
+ "area" : 4 ,
74
+ "sideLength" : 2 ,
75
+ },
76
+ };
77
+
78
+ expect (
79
+ getShapeInfoNoRefs ($Shape (shapeData)),
80
+ "Square(area: 4.0, sideLength: 2.0)" ,
81
+ );
82
+ });
83
+
84
+ test ("rectangle" , () async {
85
+ const shapeData = < String , dynamic > {
86
+ "shape" : < String , dynamic > {
87
+ "__typename" : "Rectangle" ,
88
+ "area" : 3 ,
89
+ "sideLengthA" : 3 ,
90
+ "sideLengthB" : 1 ,
91
+ },
92
+ };
93
+
94
+ expect (
95
+ getShapeInfoNoRefs ($Shape (shapeData)),
96
+ "Rectangle(area: 3.0, sideLengthA: 3.0, sideLengthB: 1.0)" ,
97
+ );
98
+ });
99
+ });
51
100
}
0 commit comments