@@ -10,6 +10,12 @@ use apollo_compiler::Node;
10
10
use arbitrary:: Result as ArbitraryResult ;
11
11
use indexmap:: IndexMap ;
12
12
13
+ #[ derive( Debug , Clone , Copy ) ]
14
+ pub enum Constness {
15
+ Const ,
16
+ NonConst ,
17
+ }
18
+
13
19
#[ derive( Debug , Clone , PartialEq ) ]
14
20
pub enum InputValue {
15
21
Variable ( Name ) ,
@@ -160,8 +166,12 @@ impl TryFrom<apollo_parser::cst::InputValueDefinition> for InputValueDef {
160
166
161
167
impl < ' a > DocumentBuilder < ' a > {
162
168
/// Create an arbitrary `InputValue`
163
- pub fn input_value ( & mut self ) -> ArbitraryResult < InputValue > {
164
- let val = match self . u . int_in_range ( 0 ..=8usize ) ? {
169
+ pub fn input_value ( & mut self , constness : Constness ) -> ArbitraryResult < InputValue > {
170
+ let index = match constness {
171
+ Constness :: Const => self . u . int_in_range ( 0 ..=7usize ) ?,
172
+ Constness :: NonConst => self . u . int_in_range ( 0 ..=8usize ) ?,
173
+ } ;
174
+ let val = match index {
165
175
// Int
166
176
0 => InputValue :: Int ( self . u . arbitrary ( ) ?) ,
167
177
// Float
@@ -179,22 +189,22 @@ impl<'a> DocumentBuilder<'a> {
179
189
let enum_choosed = self . choose_enum ( ) ?. clone ( ) ;
180
190
InputValue :: Enum ( self . arbitrary_variant ( & enum_choosed) ?. clone ( ) )
181
191
} else {
182
- self . input_value ( ) ?
192
+ self . input_value ( constness ) ?
183
193
}
184
194
}
185
195
// List
186
196
6 => {
187
197
// FIXME: it's semantically wrong it should always be the same type inside
188
198
InputValue :: List (
189
199
( 0 ..self . u . int_in_range ( 2 ..=4usize ) ?)
190
- . map ( |_| self . input_value ( ) )
200
+ . map ( |_| self . input_value ( constness ) )
191
201
. collect :: < ArbitraryResult < Vec < _ > > > ( ) ?,
192
202
)
193
203
}
194
204
// Object
195
205
7 => InputValue :: Object (
196
206
( 0 ..self . u . int_in_range ( 2 ..=4usize ) ?)
197
- . map ( |_| Ok ( ( self . name ( ) ?, self . input_value ( ) ?) ) )
207
+ . map ( |_| Ok ( ( self . name ( ) ?, self . input_value ( constness ) ?) ) )
198
208
. collect :: < ArbitraryResult < Vec < _ > > > ( ) ?,
199
209
) ,
200
210
// Variable TODO: only generate valid variable name (existing variables)
@@ -287,7 +297,7 @@ impl<'a> DocumentBuilder<'a> {
287
297
. u
288
298
. arbitrary ( )
289
299
. unwrap_or ( false )
290
- . then ( || self . input_value ( ) )
300
+ . then ( || self . input_value ( Constness :: Const ) )
291
301
. transpose ( ) ?;
292
302
293
303
input_values. push ( InputValueDef {
@@ -318,7 +328,7 @@ impl<'a> DocumentBuilder<'a> {
318
328
. u
319
329
. arbitrary ( )
320
330
. unwrap_or ( false )
321
- . then ( || self . input_value ( ) )
331
+ . then ( || self . input_value ( Constness :: Const ) )
322
332
. transpose ( ) ?;
323
333
324
334
Ok ( InputValueDef {
0 commit comments