-
-
Notifications
You must be signed in to change notification settings - Fork 444
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(graphql_formatter): implement graphql formatter (#3296)
- Loading branch information
1 parent
099bc1e
commit 2244c0b
Showing
239 changed files
with
8,731 additions
and
715 deletions.
There are no files selected for viewing
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
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
8 changes: 5 additions & 3 deletions
8
crates/biome_graphql_formatter/src/graphql/auxiliary/alias.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 |
---|---|---|
@@ -1,10 +1,12 @@ | ||
use crate::prelude::*; | ||
use biome_graphql_syntax::GraphqlAlias; | ||
use biome_rowan::AstNode; | ||
use biome_formatter::write; | ||
use biome_graphql_syntax::{GraphqlAlias, GraphqlAliasFields}; | ||
#[derive(Debug, Clone, Default)] | ||
pub(crate) struct FormatGraphqlAlias; | ||
impl FormatNodeRule<GraphqlAlias> for FormatGraphqlAlias { | ||
fn fmt_fields(&self, node: &GraphqlAlias, f: &mut GraphqlFormatter) -> FormatResult<()> { | ||
format_verbatim_node(node.syntax()).fmt(f) | ||
let GraphqlAliasFields { value, colon_token } = node.as_fields(); | ||
|
||
write!(f, [value.format(), colon_token.format(), space()]) | ||
} | ||
} |
16 changes: 13 additions & 3 deletions
16
crates/biome_graphql_formatter/src/graphql/auxiliary/argument.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 |
---|---|---|
@@ -1,10 +1,20 @@ | ||
use crate::prelude::*; | ||
use biome_graphql_syntax::GraphqlArgument; | ||
use biome_rowan::AstNode; | ||
use biome_formatter::write; | ||
use biome_graphql_syntax::{GraphqlArgument, GraphqlArgumentFields}; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub(crate) struct FormatGraphqlArgument; | ||
impl FormatNodeRule<GraphqlArgument> for FormatGraphqlArgument { | ||
fn fmt_fields(&self, node: &GraphqlArgument, f: &mut GraphqlFormatter) -> FormatResult<()> { | ||
format_verbatim_node(node.syntax()).fmt(f) | ||
let GraphqlArgumentFields { | ||
name, | ||
colon_token, | ||
value, | ||
} = node.as_fields(); | ||
|
||
write!( | ||
f, | ||
[name.format(), colon_token.format(), space(), value.format(),] | ||
) | ||
} | ||
} |
20 changes: 17 additions & 3 deletions
20
crates/biome_graphql_formatter/src/graphql/auxiliary/arguments.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 |
---|---|---|
@@ -1,10 +1,24 @@ | ||
use crate::prelude::*; | ||
use biome_graphql_syntax::GraphqlArguments; | ||
use biome_rowan::AstNode; | ||
use biome_formatter::{format_args, write}; | ||
use biome_graphql_syntax::{GraphqlArguments, GraphqlArgumentsFields}; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub(crate) struct FormatGraphqlArguments; | ||
impl FormatNodeRule<GraphqlArguments> for FormatGraphqlArguments { | ||
fn fmt_fields(&self, node: &GraphqlArguments, f: &mut GraphqlFormatter) -> FormatResult<()> { | ||
format_verbatim_node(node.syntax()).fmt(f) | ||
let GraphqlArgumentsFields { | ||
l_paren_token, | ||
arguments, | ||
r_paren_token, | ||
} = node.as_fields(); | ||
|
||
write!( | ||
f, | ||
[group(&format_args!( | ||
l_paren_token.format(), | ||
soft_block_indent(&arguments.format()), | ||
r_paren_token.format(), | ||
))] | ||
) | ||
} | ||
} |
11 changes: 8 additions & 3 deletions
11
crates/biome_graphql_formatter/src/graphql/auxiliary/description.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 |
---|---|---|
@@ -1,10 +1,15 @@ | ||
use crate::prelude::*; | ||
use biome_graphql_syntax::GraphqlDescription; | ||
use biome_rowan::AstNode; | ||
use biome_formatter::write; | ||
use biome_graphql_syntax::{GraphqlDescription, GraphqlDescriptionFields}; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub(crate) struct FormatGraphqlDescription; | ||
impl FormatNodeRule<GraphqlDescription> for FormatGraphqlDescription { | ||
fn fmt_fields(&self, node: &GraphqlDescription, f: &mut GraphqlFormatter) -> FormatResult<()> { | ||
format_verbatim_node(node.syntax()).fmt(f) | ||
let GraphqlDescriptionFields { | ||
graphql_string_value, | ||
} = node.as_fields(); | ||
|
||
write!(f, [graphql_string_value.format()]) | ||
} | ||
} |
13 changes: 10 additions & 3 deletions
13
crates/biome_graphql_formatter/src/graphql/auxiliary/directive.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 |
---|---|---|
@@ -1,10 +1,17 @@ | ||
use crate::prelude::*; | ||
use biome_graphql_syntax::GraphqlDirective; | ||
use biome_rowan::AstNode; | ||
use biome_formatter::write; | ||
use biome_graphql_syntax::{GraphqlDirective, GraphqlDirectiveFields}; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub(crate) struct FormatGraphqlDirective; | ||
impl FormatNodeRule<GraphqlDirective> for FormatGraphqlDirective { | ||
fn fmt_fields(&self, node: &GraphqlDirective, f: &mut GraphqlFormatter) -> FormatResult<()> { | ||
format_verbatim_node(node.syntax()).fmt(f) | ||
let GraphqlDirectiveFields { | ||
at_token, | ||
name, | ||
arguments, | ||
} = node.as_fields(); | ||
|
||
write![f, [at_token.format(), name.format(), arguments.format()]] | ||
} | ||
} |
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
29 changes: 26 additions & 3 deletions
29
crates/biome_graphql_formatter/src/graphql/auxiliary/field.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 |
---|---|---|
@@ -1,10 +1,33 @@ | ||
use crate::prelude::*; | ||
use biome_graphql_syntax::GraphqlField; | ||
use biome_rowan::AstNode; | ||
use biome_formatter::write; | ||
use biome_graphql_syntax::{GraphqlField, GraphqlFieldFields}; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub(crate) struct FormatGraphqlField; | ||
impl FormatNodeRule<GraphqlField> for FormatGraphqlField { | ||
fn fmt_fields(&self, node: &GraphqlField, f: &mut GraphqlFormatter) -> FormatResult<()> { | ||
format_verbatim_node(node.syntax()).fmt(f) | ||
let GraphqlFieldFields { | ||
alias, | ||
name, | ||
arguments, | ||
directives, | ||
selection_set, | ||
} = node.as_fields(); | ||
|
||
write!( | ||
f, | ||
[ | ||
alias.format(), | ||
name.format(), | ||
arguments.format(), | ||
directives.format(), | ||
] | ||
)?; | ||
|
||
if let Some(selection_set) = selection_set { | ||
write!(f, [space(), selection_set.format()])?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |
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
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
20 changes: 17 additions & 3 deletions
20
crates/biome_graphql_formatter/src/graphql/auxiliary/list_type.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 |
---|---|---|
@@ -1,10 +1,24 @@ | ||
use crate::prelude::*; | ||
use biome_graphql_syntax::GraphqlListType; | ||
use biome_rowan::AstNode; | ||
use biome_formatter::write; | ||
use biome_graphql_syntax::{GraphqlListType, GraphqlListTypeFields}; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub(crate) struct FormatGraphqlListType; | ||
impl FormatNodeRule<GraphqlListType> for FormatGraphqlListType { | ||
fn fmt_fields(&self, node: &GraphqlListType, f: &mut GraphqlFormatter) -> FormatResult<()> { | ||
format_verbatim_node(node.syntax()).fmt(f) | ||
let GraphqlListTypeFields { | ||
l_brack_token, | ||
element, | ||
r_brack_token, | ||
} = node.as_fields(); | ||
|
||
write!( | ||
f, | ||
[ | ||
l_brack_token.format(), | ||
element.format(), | ||
r_brack_token.format() | ||
] | ||
) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,10 +1,13 @@ | ||
use crate::prelude::*; | ||
use biome_graphql_syntax::GraphqlName; | ||
use biome_rowan::AstNode; | ||
use biome_formatter::write; | ||
use biome_graphql_syntax::{GraphqlName, GraphqlNameFields}; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub(crate) struct FormatGraphqlName; | ||
impl FormatNodeRule<GraphqlName> for FormatGraphqlName { | ||
fn fmt_fields(&self, node: &GraphqlName, f: &mut GraphqlFormatter) -> FormatResult<()> { | ||
format_verbatim_node(node.syntax()).fmt(f) | ||
let GraphqlNameFields { value_token } = node.as_fields(); | ||
|
||
write![f, [value_token.format()]] | ||
} | ||
} |
Oops, something went wrong.