@@ -6,7 +6,7 @@ use position::Pos;
66pub type NamedType = String ;
77
88
9- #[ derive( Debug , Clone , PartialEq ) ]
9+ #[ derive( Debug , Clone , Default , PartialEq ) ]
1010pub struct Document {
1111 pub definitions : Vec < Definition > ,
1212}
@@ -19,7 +19,7 @@ pub enum Definition {
1919 DirectiveDefinition ( DirectiveDefinition ) ,
2020}
2121
22- #[ derive( Debug , Clone , PartialEq ) ]
22+ #[ derive( Debug , Clone , Default , PartialEq ) ]
2323pub struct SchemaDefinition {
2424 pub position : Pos ,
2525 pub directives : Vec < Directive > ,
@@ -56,13 +56,34 @@ pub struct ScalarType {
5656 pub directives : Vec < Directive > ,
5757}
5858
59+ impl ScalarType {
60+ pub fn new ( name : Name ) -> Self {
61+ Self {
62+ position : Pos :: default ( ) ,
63+ description : None ,
64+ name,
65+ directives : vec ! [ ] ,
66+ }
67+ }
68+ }
69+
5970#[ derive( Debug , Clone , PartialEq ) ]
6071pub struct ScalarTypeExtension {
6172 pub position : Pos ,
6273 pub name : Name ,
6374 pub directives : Vec < Directive > ,
6475}
6576
77+ impl ScalarTypeExtension {
78+ pub fn new ( name : Name ) -> Self {
79+ Self {
80+ position : Pos :: default ( ) ,
81+ name,
82+ directives : vec ! [ ] ,
83+ }
84+ }
85+ }
86+
6687#[ derive( Debug , Clone , PartialEq ) ]
6788pub struct ObjectType {
6889 pub position : Pos ,
@@ -73,6 +94,19 @@ pub struct ObjectType {
7394 pub fields : Vec < Field > ,
7495}
7596
97+ impl ObjectType {
98+ pub fn new ( name : Name ) -> Self {
99+ Self {
100+ position : Pos :: default ( ) ,
101+ description : None ,
102+ name,
103+ implements_interfaces : vec ! [ ] ,
104+ directives : vec ! [ ] ,
105+ fields : vec ! [ ] ,
106+ }
107+ }
108+ }
109+
76110#[ derive( Debug , Clone , PartialEq ) ]
77111pub struct ObjectTypeExtension {
78112 pub position : Pos ,
@@ -82,6 +116,18 @@ pub struct ObjectTypeExtension {
82116 pub fields : Vec < Field > ,
83117}
84118
119+ impl ObjectTypeExtension {
120+ pub fn new ( name : Name ) -> Self {
121+ Self {
122+ position : Pos :: default ( ) ,
123+ name,
124+ implements_interfaces : vec ! [ ] ,
125+ directives : vec ! [ ] ,
126+ fields : vec ! [ ] ,
127+ }
128+ }
129+ }
130+
85131#[ derive( Debug , Clone , PartialEq ) ]
86132pub struct Field {
87133 pub position : Pos ,
@@ -111,6 +157,18 @@ pub struct InterfaceType {
111157 pub fields : Vec < Field > ,
112158}
113159
160+ impl InterfaceType {
161+ pub fn new ( name : Name ) -> Self {
162+ Self {
163+ position : Pos :: default ( ) ,
164+ description : None ,
165+ name,
166+ directives : vec ! [ ] ,
167+ fields : vec ! [ ] ,
168+ }
169+ }
170+ }
171+
114172#[ derive( Debug , Clone , PartialEq ) ]
115173pub struct InterfaceTypeExtension {
116174 pub position : Pos ,
@@ -119,6 +177,17 @@ pub struct InterfaceTypeExtension {
119177 pub fields : Vec < Field > ,
120178}
121179
180+ impl InterfaceTypeExtension {
181+ pub fn new ( name : Name ) -> Self {
182+ Self {
183+ position : Pos :: default ( ) ,
184+ name,
185+ directives : vec ! [ ] ,
186+ fields : vec ! [ ] ,
187+ }
188+ }
189+ }
190+
122191#[ derive( Debug , Clone , PartialEq ) ]
123192pub struct UnionType {
124193 pub position : Pos ,
@@ -128,6 +197,18 @@ pub struct UnionType {
128197 pub types : Vec < NamedType > ,
129198}
130199
200+ impl UnionType {
201+ pub fn new ( name : Name ) -> Self {
202+ Self {
203+ position : Pos :: default ( ) ,
204+ description : None ,
205+ name,
206+ directives : vec ! [ ] ,
207+ types : vec ! [ ] ,
208+ }
209+ }
210+ }
211+
131212#[ derive( Debug , Clone , PartialEq ) ]
132213pub struct UnionTypeExtension {
133214 pub position : Pos ,
@@ -136,6 +217,17 @@ pub struct UnionTypeExtension {
136217 pub types : Vec < NamedType > ,
137218}
138219
220+ impl UnionTypeExtension {
221+ pub fn new ( name : Name ) -> Self {
222+ Self {
223+ position : Pos :: default ( ) ,
224+ name,
225+ directives : vec ! [ ] ,
226+ types : vec ! [ ] ,
227+ }
228+ }
229+ }
230+
139231#[ derive( Debug , Clone , PartialEq ) ]
140232pub struct EnumType {
141233 pub position : Pos ,
@@ -145,6 +237,18 @@ pub struct EnumType {
145237 pub values : Vec < EnumValue > ,
146238}
147239
240+ impl EnumType {
241+ pub fn new ( name : Name ) -> Self {
242+ Self {
243+ position : Pos :: default ( ) ,
244+ description : None ,
245+ name,
246+ directives : vec ! [ ] ,
247+ values : vec ! [ ] ,
248+ }
249+ }
250+ }
251+
148252#[ derive( Debug , Clone , PartialEq ) ]
149253pub struct EnumValue {
150254 pub position : Pos ,
@@ -153,6 +257,17 @@ pub struct EnumValue {
153257 pub directives : Vec < Directive > ,
154258}
155259
260+ impl EnumValue {
261+ pub fn new ( name : Name ) -> Self {
262+ Self {
263+ position : Pos :: default ( ) ,
264+ description : None ,
265+ name,
266+ directives : vec ! [ ] ,
267+ }
268+ }
269+ }
270+
156271#[ derive( Debug , Clone , PartialEq ) ]
157272pub struct EnumTypeExtension {
158273 pub position : Pos ,
@@ -161,6 +276,17 @@ pub struct EnumTypeExtension {
161276 pub values : Vec < EnumValue > ,
162277}
163278
279+ impl EnumTypeExtension {
280+ pub fn new ( name : Name ) -> Self {
281+ Self {
282+ position : Pos :: default ( ) ,
283+ name,
284+ directives : vec ! [ ] ,
285+ values : vec ! [ ] ,
286+ }
287+ }
288+ }
289+
164290#[ derive( Debug , Clone , PartialEq ) ]
165291pub struct InputObjectType {
166292 pub position : Pos ,
@@ -170,6 +296,18 @@ pub struct InputObjectType {
170296 pub fields : Vec < InputValue > ,
171297}
172298
299+ impl InputObjectType {
300+ pub fn new ( name : Name ) -> Self {
301+ Self {
302+ position : Pos :: default ( ) ,
303+ description : None ,
304+ name,
305+ directives : vec ! [ ] ,
306+ fields : vec ! [ ] ,
307+ }
308+ }
309+ }
310+
173311#[ derive( Debug , Clone , PartialEq ) ]
174312pub struct InputObjectTypeExtension {
175313 pub position : Pos ,
@@ -178,6 +316,17 @@ pub struct InputObjectTypeExtension {
178316 pub fields : Vec < InputValue > ,
179317}
180318
319+ impl InputObjectTypeExtension {
320+ pub fn new ( name : Name ) -> Self {
321+ Self {
322+ position : Pos :: default ( ) ,
323+ name,
324+ directives : vec ! [ ] ,
325+ fields : vec ! [ ] ,
326+ }
327+ }
328+ }
329+
181330#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
182331pub enum DirectiveLocation {
183332 // executable
@@ -212,6 +361,18 @@ pub struct DirectiveDefinition {
212361 pub locations : Vec < DirectiveLocation > ,
213362}
214363
364+ impl DirectiveDefinition {
365+ pub fn new ( name : Name ) -> Self {
366+ Self {
367+ position : Pos :: default ( ) ,
368+ description : None ,
369+ name,
370+ arguments : vec ! [ ] ,
371+ locations : vec ! [ ] ,
372+ }
373+ }
374+ }
375+
215376impl DirectiveLocation {
216377 /// Returns GraphQL syntax compatible name of the directive
217378 pub fn as_str ( & self ) -> & ' static str {
0 commit comments