Skip to content

Commit

Permalink
feat(biome_graphql_parser): parse interface type extension (#2942)
Browse files Browse the repository at this point in the history
  • Loading branch information
vohoanglong0107 authored May 27, 2024
1 parent fb24ed7 commit e4644da
Show file tree
Hide file tree
Showing 15 changed files with 587 additions and 680 deletions.
78 changes: 13 additions & 65 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.

91 changes: 2 additions & 89 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.

32 changes: 30 additions & 2 deletions crates/biome_graphql_parser/src/parser/definitions/interface.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::parser::{
directive::{is_at_directive, DirectiveList},
is_nth_at_name, parse_description,
parse_error::{expected_name, expected_named_type},
parse_error::{expected_name, expected_named_type, expected_object_extension},
parse_name,
r#type::parse_named_type,
GraphqlParser,
Expand All @@ -10,7 +10,10 @@ use biome_graphql_syntax::{
GraphqlSyntaxKind::{self, *},
T,
};
use biome_parser::parse_lists::{ParseNodeList, ParseSeparatedList};
use biome_parser::{
parse_lists::{ParseNodeList, ParseSeparatedList},
token_source::TokenSource,
};
use biome_parser::{
parse_recovery::ParseRecovery, parsed_syntax::ParsedSyntax, prelude::ParsedSyntax::*, Parser,
};
Expand Down Expand Up @@ -42,6 +45,31 @@ pub(super) fn parse_interface_type_definition(p: &mut GraphqlParser) -> ParsedSy
Present(m.complete(p, GRAPHQL_INTERFACE_TYPE_DEFINITION))
}

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

p.bump(T![extend]);
p.bump(T![interface]);

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

let implements_interface_empty = parse_implements_interface(p).is_absent();

let pos = p.source().position();
DirectiveList.parse_list(p);
let directive_empty = p.source().position() == pos;

let fields_definition_empty = parse_fields_definition(p).is_absent();

if directive_empty && implements_interface_empty && fields_definition_empty {
p.error(expected_object_extension(p, p.cur_range()));
}

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

#[inline]
pub(super) fn parse_implements_interface(p: &mut GraphqlParser) -> ParsedSyntax {
if !is_at_implements_interface(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 @@ -24,7 +24,7 @@ use self::{
directive::parse_directive_definition,
fragment::parse_fragment_definition,
input_object::parse_input_object_type_definition,
interface::parse_interface_type_definition,
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},
r#enum::parse_enum_type_definition,
Expand Down Expand Up @@ -99,6 +99,7 @@ fn parse_extension(p: &mut GraphqlParser) -> ParsedSyntax {
T![schema] => parse_schema_extension(p),
T![scalar] => parse_scalar_type_extension(p),
T![type] => parse_object_type_extension(p),
T![interface] => parse_interface_type_extension(p),
_ => Absent,
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
extend interface Story

extend interface User
name: String
}
Loading

0 comments on commit e4644da

Please sign in to comment.