@@ -28,14 +28,36 @@ pub enum Type<'a> {
28
28
NonNullList ( Box < Type < ' a > > , Option < usize > ) ,
29
29
}
30
30
31
+ #[ cfg( feature = "arbitrary" ) ]
32
+ impl < ' a > arbitrary:: Arbitrary < ' a > for Type < ' a > {
33
+ fn arbitrary ( u : & mut arbitrary:: Unstructured < ' a > ) -> arbitrary:: Result < Self > {
34
+ let num_choices = 4 ;
35
+
36
+ let ty = match u. int_in_range :: < u8 > ( 1 ..=num_choices) ? {
37
+ 1 => Type :: Named ( u. arbitrary :: < Cow < ' a , str > > ( ) ?) ,
38
+ 2 => Type :: List (
39
+ u. arbitrary :: < Box < Type < ' a > > > ( ) ?,
40
+ u. arbitrary :: < Option < usize > > ( ) ?,
41
+ ) ,
42
+ 3 => Type :: NonNullNamed ( u. arbitrary :: < Cow < ' a , str > > ( ) ?) ,
43
+ 4 => Type :: NonNullList (
44
+ u. arbitrary :: < Box < Type < ' a > > > ( ) ?,
45
+ u. arbitrary :: < Option < usize > > ( ) ?,
46
+ ) ,
47
+ _ => unreachable ! ( ) ,
48
+ } ;
49
+ Ok ( ty)
50
+ }
51
+ }
52
+
31
53
/// A JSON-like value that can be passed into the query execution, either
32
54
/// out-of-band, or in-band as default variable values. These are _not_ constant
33
55
/// and might contain variables.
34
56
///
35
57
/// Lists and objects variants are _spanned_, i.e. they contain a reference to
36
58
/// their position in the source file, if available.
37
59
#[ derive( Clone , Debug , PartialEq ) ]
38
- #[ allow ( missing_docs ) ]
60
+ #[ cfg_attr ( feature = "arbitrary" , derive ( arbitrary :: Arbitrary ) ) ]
39
61
pub enum InputValue < S = DefaultScalarValue > {
40
62
Null ,
41
63
Scalar ( S ) ,
@@ -46,23 +68,67 @@ pub enum InputValue<S = DefaultScalarValue> {
46
68
}
47
69
48
70
#[ derive( Clone , PartialEq , Debug ) ]
71
+ #[ allow( missing_docs) ]
49
72
pub struct VariableDefinition < ' a , S > {
50
73
pub var_type : Spanning < Type < ' a > > ,
51
74
pub default_value : Option < Spanning < InputValue < S > > > ,
52
75
pub directives : Option < Vec < Spanning < Directive < ' a , S > > > > ,
53
76
}
54
77
78
+ #[ cfg( feature = "arbitrary" ) ]
79
+ impl < ' a , S > arbitrary:: Arbitrary < ' a > for VariableDefinition < ' a , S >
80
+ where
81
+ S : arbitrary:: Arbitrary < ' a > ,
82
+ {
83
+ fn arbitrary ( u : & mut arbitrary:: Unstructured < ' a > ) -> arbitrary:: Result < Self > {
84
+ let var_type: Spanning < Type < ' a > > = u. arbitrary ( ) ?;
85
+ let default_value: Option < Spanning < InputValue < S > > > = u. arbitrary ( ) ?;
86
+ let directives: Option < Vec < Spanning < Directive < ' a , S > > > > = u. arbitrary ( ) ?;
87
+
88
+ Ok ( Self {
89
+ var_type,
90
+ default_value,
91
+ directives,
92
+ } )
93
+ }
94
+ }
95
+
55
96
#[ derive( Clone , PartialEq , Debug ) ]
97
+ #[ allow( missing_docs) ]
56
98
pub struct Arguments < ' a , S > {
57
99
pub items : Vec < ( Spanning < & ' a str > , Spanning < InputValue < S > > ) > ,
58
100
}
59
101
102
+ #[ cfg( feature = "arbitrary" ) ]
103
+ impl < ' a , S > arbitrary:: Arbitrary < ' a > for Arguments < ' a , S >
104
+ where
105
+ S : arbitrary:: Arbitrary < ' a > ,
106
+ {
107
+ fn arbitrary ( u : & mut arbitrary:: Unstructured < ' a > ) -> arbitrary:: Result < Self > {
108
+ let items: Vec < ( Spanning < & ' a str > , Spanning < InputValue < S > > ) > = u. arbitrary ( ) ?;
109
+ Ok ( Self { items } )
110
+ }
111
+ }
112
+
60
113
#[ derive( Clone , PartialEq , Debug ) ]
114
+ #[ allow( missing_docs) ]
61
115
pub struct VariableDefinitions < ' a , S > {
62
116
pub items : Vec < ( Spanning < & ' a str > , VariableDefinition < ' a , S > ) > ,
63
117
}
64
118
119
+ #[ cfg( feature = "arbitrary" ) ]
120
+ impl < ' a , S > arbitrary:: Arbitrary < ' a > for VariableDefinitions < ' a , S >
121
+ where
122
+ S : arbitrary:: Arbitrary < ' a > ,
123
+ {
124
+ fn arbitrary ( u : & mut arbitrary:: Unstructured < ' a > ) -> arbitrary:: Result < Self > {
125
+ let items: Vec < ( Spanning < & ' a str > , VariableDefinition < ' a , S > ) > = u. arbitrary ( ) ?;
126
+ Ok ( Self { items } )
127
+ }
128
+ }
129
+
65
130
#[ derive( Clone , PartialEq , Debug ) ]
131
+ #[ allow( missing_docs) ]
66
132
pub struct Field < ' a , S > {
67
133
pub alias : Option < Spanning < & ' a str > > ,
68
134
pub name : Spanning < & ' a str > ,
@@ -71,19 +137,74 @@ pub struct Field<'a, S> {
71
137
pub selection_set : Option < Vec < Selection < ' a , S > > > ,
72
138
}
73
139
140
+ #[ cfg( feature = "arbitrary" ) ]
141
+ impl < ' a , S > arbitrary:: Arbitrary < ' a > for Field < ' a , S >
142
+ where
143
+ S : arbitrary:: Arbitrary < ' a > ,
144
+ {
145
+ fn arbitrary ( u : & mut arbitrary:: Unstructured < ' a > ) -> arbitrary:: Result < Self > {
146
+ let alias: Option < Spanning < & ' a str > > = u. arbitrary ( ) ?;
147
+ let name: Spanning < & ' a str > = u. arbitrary ( ) ?;
148
+ let arguments: Option < Spanning < Arguments < ' a , S > > > = u. arbitrary ( ) ?;
149
+ let directives: Option < Vec < Spanning < Directive < ' a , S > > > > = u. arbitrary ( ) ?;
150
+ let selection_set: Option < Vec < Selection < ' a , S > > > = u. arbitrary ( ) ?;
151
+
152
+ Ok ( Self {
153
+ alias,
154
+ name,
155
+ arguments,
156
+ directives,
157
+ selection_set,
158
+ } )
159
+ }
160
+ }
161
+
74
162
#[ derive( Clone , PartialEq , Debug ) ]
163
+ #[ allow( missing_docs) ]
75
164
pub struct FragmentSpread < ' a , S > {
76
165
pub name : Spanning < & ' a str > ,
77
166
pub directives : Option < Vec < Spanning < Directive < ' a , S > > > > ,
78
167
}
79
168
169
+ #[ cfg( feature = "arbitrary" ) ]
170
+ impl < ' a , S > arbitrary:: Arbitrary < ' a > for FragmentSpread < ' a , S >
171
+ where
172
+ S : arbitrary:: Arbitrary < ' a > ,
173
+ {
174
+ fn arbitrary ( u : & mut arbitrary:: Unstructured < ' a > ) -> arbitrary:: Result < Self > {
175
+ let name: Spanning < & ' a str > = u. arbitrary ( ) ?;
176
+ let directives: Option < Vec < Spanning < Directive < ' a , S > > > > = u. arbitrary ( ) ?;
177
+
178
+ Ok ( Self { name, directives } )
179
+ }
180
+ }
181
+
80
182
#[ derive( Clone , PartialEq , Debug ) ]
183
+ #[ allow( missing_docs) ]
81
184
pub struct InlineFragment < ' a , S > {
82
185
pub type_condition : Option < Spanning < & ' a str > > ,
83
186
pub directives : Option < Vec < Spanning < Directive < ' a , S > > > > ,
84
187
pub selection_set : Vec < Selection < ' a , S > > ,
85
188
}
86
189
190
+ #[ cfg( feature = "arbitrary" ) ]
191
+ impl < ' a , S > arbitrary:: Arbitrary < ' a > for InlineFragment < ' a , S >
192
+ where
193
+ S : arbitrary:: Arbitrary < ' a > ,
194
+ {
195
+ fn arbitrary ( u : & mut arbitrary:: Unstructured < ' a > ) -> arbitrary:: Result < Self > {
196
+ let type_condition: Option < Spanning < & ' a str > > = u. arbitrary ( ) ?;
197
+ let directives: Option < Vec < Spanning < Directive < ' a , S > > > > = u. arbitrary ( ) ?;
198
+ let selection_set: Vec < Selection < ' a , S > > = u. arbitrary ( ) ?;
199
+
200
+ Ok ( Self {
201
+ type_condition,
202
+ directives,
203
+ selection_set,
204
+ } )
205
+ }
206
+ }
207
+
87
208
/// Entry in a GraphQL selection set
88
209
///
89
210
/// This enum represents one of the three variants of a selection that exists
@@ -107,22 +228,54 @@ pub enum Selection<'a, S = DefaultScalarValue> {
107
228
InlineFragment ( Spanning < InlineFragment < ' a , S > > ) ,
108
229
}
109
230
231
+ #[ cfg( feature = "arbitrary" ) ]
232
+ impl < ' a , S > arbitrary:: Arbitrary < ' a > for Selection < ' a , S >
233
+ where
234
+ S : arbitrary:: Arbitrary < ' a > ,
235
+ {
236
+ fn arbitrary ( u : & mut arbitrary:: Unstructured < ' a > ) -> arbitrary:: Result < Self > {
237
+ let num_choices = 3 ;
238
+
239
+ let ty = match u. int_in_range :: < u8 > ( 1 ..=num_choices) ? {
240
+ 1 => Selection :: Field ( u. arbitrary :: < Spanning < Field < ' a , S > > > ( ) ?) ,
241
+ 2 => Selection :: FragmentSpread ( u. arbitrary :: < Spanning < FragmentSpread < ' a , S > > > ( ) ?) ,
242
+ 3 => Selection :: InlineFragment ( u. arbitrary :: < Spanning < InlineFragment < ' a , S > > > ( ) ?) ,
243
+ _ => unreachable ! ( ) ,
244
+ } ;
245
+ Ok ( ty)
246
+ }
247
+ }
248
+
110
249
#[ derive( Clone , PartialEq , Debug ) ]
250
+ #[ allow( missing_docs) ]
111
251
pub struct Directive < ' a , S > {
112
252
pub name : Spanning < & ' a str > ,
113
253
pub arguments : Option < Spanning < Arguments < ' a , S > > > ,
114
254
}
115
255
116
- #[ allow( missing_docs) ]
256
+ #[ cfg( feature = "arbitrary" ) ]
257
+ impl < ' a , S > arbitrary:: Arbitrary < ' a > for Directive < ' a , S >
258
+ where
259
+ S : arbitrary:: Arbitrary < ' a > ,
260
+ {
261
+ fn arbitrary ( u : & mut arbitrary:: Unstructured < ' a > ) -> arbitrary:: Result < Self > {
262
+ let name: Spanning < & ' a str > = u. arbitrary ( ) ?;
263
+ let arguments: Option < Spanning < Arguments < ' a , S > > > = u. arbitrary ( ) ?;
264
+ Ok ( Self { name, arguments } )
265
+ }
266
+ }
267
+
117
268
#[ derive( Clone , PartialEq , Debug ) ]
269
+ #[ cfg_attr( feature = "arbitrary" , derive( arbitrary:: Arbitrary ) ) ]
270
+ #[ allow( missing_docs) ]
118
271
pub enum OperationType {
119
272
Query ,
120
273
Mutation ,
121
274
Subscription ,
122
275
}
123
276
124
- #[ allow( missing_docs) ]
125
277
#[ derive( Clone , PartialEq , Debug ) ]
278
+ #[ allow( missing_docs) ]
126
279
pub struct Operation < ' a , S > {
127
280
pub operation_type : OperationType ,
128
281
pub name : Option < Spanning < & ' a str > > ,
@@ -132,15 +285,16 @@ pub struct Operation<'a, S> {
132
285
}
133
286
134
287
#[ derive( Clone , PartialEq , Debug ) ]
288
+ #[ allow( missing_docs) ]
135
289
pub struct Fragment < ' a , S > {
136
290
pub name : Spanning < & ' a str > ,
137
291
pub type_condition : Spanning < & ' a str > ,
138
292
pub directives : Option < Vec < Spanning < Directive < ' a , S > > > > ,
139
293
pub selection_set : Vec < Selection < ' a , S > > ,
140
294
}
141
295
142
- #[ doc( hidden) ]
143
296
#[ derive( Clone , PartialEq , Debug ) ]
297
+ #[ allow( missing_docs) ]
144
298
pub enum Definition < ' a , S > {
145
299
Operation ( Spanning < Operation < ' a , S > > ) ,
146
300
Fragment ( Spanning < Fragment < ' a , S > > ) ,
0 commit comments