Skip to content

Commit

Permalink
feat(graphql_parser): parse input object type extension
Browse files Browse the repository at this point in the history
  • Loading branch information
vohoanglong0107 committed Jun 7, 2024
1 parent 9590d57 commit e7205f1
Show file tree
Hide file tree
Showing 17 changed files with 552 additions and 499 deletions.
107 changes: 63 additions & 44 deletions crates/biome_graphql_factory/src/generated/node_factory.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 2 additions & 43 deletions crates/biome_graphql_factory/src/generated/syntax_factory.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 26 additions & 2 deletions crates/biome_graphql_parser/src/parser/definitions/input_object.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::parser::{
directive::DirectiveList, parse_description, parse_error::expected_name, parse_name,
GraphqlParser,
directive::DirectiveList,
parse_description,
parse_error::{expected_input_object_extension, expected_name},
parse_name, GraphqlParser,
};
use biome_graphql_syntax::{
GraphqlSyntaxKind::{self, *},
Expand Down Expand Up @@ -32,6 +34,28 @@ pub(crate) fn parse_input_object_type_definition(p: &mut GraphqlParser) -> Parse
Present(m.complete(p, GRAPHQL_INPUT_OBJECT_TYPE_DEFINITION))
}

/// Must only be called if the next 2 token is `extend` and `input`, otherwise it will panic.
#[inline]
pub(crate) fn parse_input_object_type_extension(p: &mut GraphqlParser) -> ParsedSyntax {
let m = p.start();

p.bump(T![extend]);
p.expect(T![input]);

parse_name(p).or_add_diagnostic(p, expected_name);

let directive_list = DirectiveList.parse_list(p);
let directive_empty = directive_list.range(p).is_empty();

let input_fields_empty = parse_input_fields_definition(p).is_absent();

if directive_empty && input_fields_empty {
p.error(expected_input_object_extension(p, p.cur_range()));
}

Present(m.complete(p, GRAPHQL_INPUT_OBJECT_TYPE_EXTENSION))
}

#[inline]
fn parse_input_fields_definition(p: &mut GraphqlParser) -> ParsedSyntax {
if !is_at_input_fields_definition(p) {
Expand Down
3 changes: 2 additions & 1 deletion crates/biome_graphql_parser/src/parser/definitions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use biome_parser::{
use self::{
directive::parse_directive_definition,
fragment::parse_fragment_definition,
input_object::parse_input_object_type_definition,
input_object::{parse_input_object_type_definition, parse_input_object_type_extension},
interface::{parse_interface_type_definition, parse_interface_type_extension},
object::{parse_object_type_definition, parse_object_type_extension},
operation::{parse_operation_definition, parse_selection_set},
Expand Down Expand Up @@ -102,6 +102,7 @@ fn parse_extension(p: &mut GraphqlParser) -> ParsedSyntax {
T![interface] => parse_interface_type_extension(p),
T![union] => parse_union_type_extension(p),
T![enum] => parse_enum_type_extension(p),
T![input] => parse_input_object_type_extension(p),
_ => Absent,
}
}
Expand Down
10 changes: 10 additions & 0 deletions crates/biome_graphql_parser/src/parser/parse_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,13 @@ pub(crate) fn expected_enum_extension(p: &GraphqlParser, range: TextRange) -> Pa
range,
)
}

pub(crate) fn expected_input_object_extension(
p: &GraphqlParser,
range: TextRange,
) -> ParseDiagnostic {
p.err_builder(
"Expected at least one directive or a set of fields definition",
range,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
extend input Point2D

extend input Point2D
x: Float
y: Float
}
Loading

0 comments on commit e7205f1

Please sign in to comment.