-
-
Notifications
You must be signed in to change notification settings - Fork 506
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(biome_graphql_parser): parse fragment definition (#2506)
- Loading branch information
1 parent
4847ab1
commit a094dac
Showing
8 changed files
with
722 additions
and
17 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
crates/biome_graphql_parser/src/parser/definitions/fragment.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use crate::parser::{ | ||
directive::DirectiveList, | ||
parse_error::{expected_name, expected_named_type}, | ||
parse_name, | ||
r#type::parse_named_type, | ||
GraphqlParser, | ||
}; | ||
use biome_graphql_syntax::{GraphqlSyntaxKind::*, T}; | ||
use biome_parser::{ | ||
parse_lists::ParseNodeList, parsed_syntax::ParsedSyntax, prelude::ParsedSyntax::*, | ||
CompletedMarker, Parser, | ||
}; | ||
|
||
use super::operation::parse_selection_set; | ||
|
||
#[inline] | ||
pub(crate) fn parse_fragment_definition(p: &mut GraphqlParser) -> ParsedSyntax { | ||
if !is_at_fragment_definition(p) { | ||
return Absent; | ||
} | ||
|
||
let m = p.start(); | ||
p.bump(T![fragment]); | ||
|
||
parse_name(p).or_add_diagnostic(p, expected_name); | ||
parse_type_condition(p); | ||
|
||
DirectiveList.parse_list(p); | ||
parse_selection_set(p).ok(); | ||
|
||
Present(m.complete(p, GRAPHQL_FRAGMENT_DEFINITION)) | ||
} | ||
|
||
#[inline] | ||
pub(crate) fn parse_type_condition(p: &mut GraphqlParser) -> CompletedMarker { | ||
let m = p.start(); | ||
p.expect(T![on]); | ||
parse_named_type(p).or_add_diagnostic(p, expected_named_type); | ||
m.complete(p, GRAPHQL_TYPE_CONDITION) | ||
} | ||
|
||
#[inline] | ||
pub(crate) fn is_at_fragment_definition(p: &GraphqlParser<'_>) -> bool { | ||
p.at(T![fragment]) | ||
} | ||
|
||
#[inline] | ||
pub(crate) fn is_at_type_condition(p: &GraphqlParser<'_>) -> bool { | ||
p.at(T![on]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/fragment.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
fragmen friendFields on User { | ||
id | ||
name | ||
} | ||
|
||
fragment friendFields User @deprecated { | ||
id | ||
name | ||
} | ||
|
||
fragment friendFields o User @deprecated { | ||
id | ||
name | ||
} |
Oops, something went wrong.