Skip to content

Commit d981317

Browse files
committed
WIP: Implement input extension
1 parent 1f64296 commit d981317

File tree

6 files changed

+39
-3
lines changed

6 files changed

+39
-3
lines changed

src/schema/ast.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ pub struct InputObjectType {
173173

174174
#[derive(Debug, Clone, PartialEq)]
175175
pub struct InputObjectTypeExtension {
176+
pub position: Pos,
176177
pub name: Name,
177178
pub directives: Vec<Directive>,
178179
pub fields: Vec<InputValue>,

src/schema/format.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,11 @@ impl Displayable for InputObjectType {
342342

343343
impl Displayable for InputObjectTypeExtension {
344344
fn display(&self, f: &mut Formatter) {
345-
unimplemented!();
345+
f.indent();
346+
f.write("extend input ");
347+
f.write(&self.name);
348+
format_directives(&self.directives, f);
349+
format_inputs(&self.fields, f);
346350
}
347351
}
348352

src/schema/grammar.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,11 +395,10 @@ pub fn input_object_type<'a>(input: &mut TokenStream<'a>)
395395
(
396396
position(),
397397
ident("input").with(name()),
398-
parser(implements_interfaces),
399398
parser(directives),
400399
parser(input_fields),
401400
)
402-
.map(|(position, name, interfaces, directives, fields)| {
401+
.map(|(position, name, directives, fields)| {
403402
InputObjectType {
404403
position, name, directives, fields,
405404
description: None, // is filled in type_definition
@@ -408,6 +407,30 @@ pub fn input_object_type<'a>(input: &mut TokenStream<'a>)
408407
.parse_stream(input)
409408
}
410409

410+
pub fn input_object_type_extension<'a>(input: &mut TokenStream<'a>)
411+
-> ParseResult<InputObjectTypeExtension, TokenStream<'a>>
412+
{
413+
(
414+
position(),
415+
ident("input").with(name()),
416+
parser(directives),
417+
parser(input_fields),
418+
)
419+
.flat_map(|(position, name, directives, fields)| {
420+
if directives.is_empty() && fields.is_empty() {
421+
let mut e = Errors::empty(position);
422+
e.add_error(Error::expected_static_message(
423+
"Input object type extension should contain at least \
424+
one directive or field."));
425+
return Err(e);
426+
}
427+
Ok(InputObjectTypeExtension {
428+
position, name, directives, fields,
429+
})
430+
})
431+
.parse_stream(input)
432+
}
433+
411434
pub fn type_definition<'a>(input: &mut TokenStream<'a>)
412435
-> ParseResult<TypeDefinition, TokenStream<'a>>
413436
{
@@ -450,6 +473,7 @@ pub fn type_extension<'a>(input: &mut TokenStream<'a>)
450473
parser(interface_type_extension).map(TypeExtension::Interface),
451474
parser(union_type_extension).map(TypeExtension::Union),
452475
parser(enum_type_extension).map(TypeExtension::Enum),
476+
parser(input_object_type_extension).map(TypeExtension::InputObject),
453477
)))
454478
.parse_stream(input)
455479
}

tests/schema_roundtrips.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,6 @@ fn roundtrip2(filename: &str) {
4545
#[test] fn enum_type() { roundtrip("enum"); }
4646
#[test] fn extend_enum() { roundtrip("extend_enum"); }
4747
#[test] fn input_type() { roundtrip("input_type"); }
48+
#[test] fn extend_input() { roundtrip2("extend_input"); }
4849
// Not yet fully supported
4950
//#[test] fn kitchen_sink() { roundtrip2("kitchen-sink"); }

tests/schemas/extend_input.graphql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
extend input InputType {
2+
other: Float = 1.23e4
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
extend input InputType {
2+
other: Float = 12300
3+
}

0 commit comments

Comments
 (0)