@@ -86,12 +86,19 @@ impl<'a> TypeInfoRegistry<'a> {
86
86
}
87
87
}
88
88
89
+ /// This struct is used to mark a "node" or nothing (null, undefined). While tracking TypeInfo, we need to check if there was a node before or not.
90
+ #[ derive( Debug , Clone , Copy ) ]
91
+ pub enum TypeInfoElementRef < T > {
92
+ Empty ,
93
+ Ref ( T ) ,
94
+ }
95
+
89
96
pub struct TypeInfo {
90
- pub type_stack : Vec < schema:: Type > ,
91
- pub parent_type_stack : Vec < CompositeType > ,
92
- pub field_def_stack : Vec < schema:: Field > ,
93
- pub input_type_stack : Vec < schema:: InputObjectType > ,
94
- pub argument : Option < schema:: InputValue > ,
97
+ pub type_stack : Vec < TypeInfoElementRef < schema:: Type > > ,
98
+ pub parent_type_stack : Vec < TypeInfoElementRef < CompositeType > > ,
99
+ pub field_def_stack : Vec < TypeInfoElementRef < schema:: Field > > ,
100
+ pub input_type_stack : Vec < TypeInfoElementRef < schema:: InputObjectType > > ,
101
+ pub argument : Option < TypeInfoElementRef < schema:: InputValue > > ,
95
102
}
96
103
97
104
impl TypeInfo {
@@ -105,59 +112,59 @@ impl TypeInfo {
105
112
} ;
106
113
}
107
114
108
- pub fn get_argument ( & self ) -> Option < schema:: InputValue > {
115
+ pub fn get_argument ( & self ) -> Option < TypeInfoElementRef < schema:: InputValue > > {
109
116
self . argument . clone ( )
110
117
}
111
118
112
- pub fn enter_argument ( & mut self , input_value : schema:: InputValue ) {
119
+ pub fn enter_argument ( & mut self , input_value : TypeInfoElementRef < schema:: InputValue > ) {
113
120
self . argument = Some ( input_value) ;
114
121
}
115
122
116
123
pub fn leave_argument ( & mut self ) {
117
124
self . argument = None ;
118
125
}
119
126
120
- pub fn get_type ( & self ) -> Option < schema:: Type > {
127
+ pub fn get_type ( & self ) -> Option < TypeInfoElementRef < schema:: Type > > {
121
128
self . type_stack . last ( ) . cloned ( )
122
129
}
123
130
124
- pub fn enter_type ( & mut self , object : schema:: Type ) {
131
+ pub fn enter_type ( & mut self , object : TypeInfoElementRef < schema:: Type > ) {
125
132
self . type_stack . push ( object) ;
126
133
}
127
134
128
135
pub fn leave_type ( & mut self ) {
129
136
self . type_stack . pop ( ) ;
130
137
}
131
138
132
- pub fn get_input_type ( & self ) -> Option < schema:: InputObjectType > {
139
+ pub fn get_input_type ( & self ) -> Option < TypeInfoElementRef < schema:: InputObjectType > > {
133
140
self . input_type_stack . last ( ) . cloned ( )
134
141
}
135
142
136
- pub fn enter_input_type ( & mut self , object : schema:: InputObjectType ) {
143
+ pub fn enter_input_type ( & mut self , object : TypeInfoElementRef < schema:: InputObjectType > ) {
137
144
self . input_type_stack . push ( object) ;
138
145
}
139
146
140
147
pub fn leave_input_type ( & mut self ) {
141
148
self . input_type_stack . pop ( ) ;
142
149
}
143
150
144
- pub fn get_parent_type ( & self ) -> Option < CompositeType > {
151
+ pub fn get_parent_type ( & self ) -> Option < TypeInfoElementRef < CompositeType > > {
145
152
self . parent_type_stack . last ( ) . cloned ( )
146
153
}
147
154
148
- pub fn enter_parent_type ( & mut self , object : CompositeType ) {
155
+ pub fn enter_parent_type ( & mut self , object : TypeInfoElementRef < CompositeType > ) {
149
156
self . parent_type_stack . push ( object) ;
150
157
}
151
158
152
159
pub fn leave_parent_type ( & mut self ) {
153
160
self . parent_type_stack . pop ( ) ;
154
161
}
155
162
156
- pub fn get_field_def ( & self ) -> Option < schema:: Field > {
163
+ pub fn get_field_def ( & self ) -> Option < TypeInfoElementRef < schema:: Field > > {
157
164
self . field_def_stack . last ( ) . cloned ( )
158
165
}
159
166
160
- pub fn enter_field_def ( & mut self , field : schema:: Field ) {
167
+ pub fn enter_field_def ( & mut self , field : TypeInfoElementRef < schema:: Field > ) {
161
168
self . field_def_stack . push ( field) ;
162
169
}
163
170
0 commit comments