Skip to content

Commit

Permalink
fix(biome_graphql_parser): better diagnostic for directive location
Browse files Browse the repository at this point in the history
  • Loading branch information
vohoanglong0107 committed May 9, 2024
1 parent 9bb6185 commit 79b8078
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 55 deletions.
55 changes: 29 additions & 26 deletions crates/biome_graphql_parser/src/parser/parse_error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate::parser::GraphqlParser;
use biome_parser::diagnostic::{expected_any, expected_node, ParseDiagnostic};
use biome_parser::{
diagnostic::{expected_any, expected_node, ParseDiagnostic},
Parser,
};
use biome_rowan::TextRange;

pub(crate) fn expected_any_definition(p: &GraphqlParser, range: TextRange) -> ParseDiagnostic {
Expand Down Expand Up @@ -62,29 +65,29 @@ pub(crate) fn expected_operation_type(p: &GraphqlParser, range: TextRange) -> Pa
}

pub(crate) fn expected_directive_location(p: &GraphqlParser, range: TextRange) -> ParseDiagnostic {
expected_any(
&[
"QUERY",
"MUTATION",
"SUBSCRIPTION",
"FIELD",
"FRAGMENT_DEFINITION",
"FRAGMENT_SPREAD",
"INLINE_FRAGMENT",
"VARIABLE_DEFINITION",
"SCHEMA",
"SCALAR",
"OBJECT",
"FIELD_DEFINITION",
"ARGUMENT_DEFINITION",
"INTERFACE",
"UNION",
"ENUM",
"ENUM_VALUE",
"INPUT_OBJECT",
"INPUT_FIELD_DEFINITION",
],
range,
p,
)
p.err_builder("Expected a valid directive location", range)
.with_alternatives(
"Must be one of:",
&[
"QUERY",
"MUTATION",
"SUBSCRIPTION",
"FIELD",
"FRAGMENT_DEFINITION",
"FRAGMENT_SPREAD",
"INLINE_FRAGMENT",
"VARIABLE_DEFINITION",
"SCHEMA",
"SCALAR",
"OBJECT",
"FIELD_DEFINITION",
"ARGUMENT_DEFINITION",
"INTERFACE",
"UNION",
"ENUM",
"ENUM_VALUE",
"INPUT_OBJECT",
"INPUT_FIELD_DEFINITION",
],
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ GraphqlRoot {
```
directive_definition.graphql:3:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× Expected a QUERY, a MUTATION, a SUBSCRIPTION, a FIELD, a FRAGMENT_DEFINITION, a FRAGMENT_SPREAD, a INLINE_FRAGMENT, a VARIABLE_DEFINITION, a SCHEMA, a SCALAR, a OBJECT, a FIELD_DEFINITION, a ARGUMENT_DEFINITION, a INTERFACE, a UNION, a ENUM, a ENUM_VALUE, a INPUT_OBJECT, or a INPUT_FIELD_DEFINITION but instead found 'directive'.
× Expected a valid directive location
1 │ directive @example on |
2 │
Expand All @@ -328,14 +328,27 @@ directive_definition.graphql:3:1 parse ━━━━━━━━━━━━━
4 │
5 │ directive example on | ARGUMENT_DEFINITION
i Expected a QUERY, a MUTATION, a SUBSCRIPTION, a FIELD, a FRAGMENT_DEFINITION, a FRAGMENT_SPREAD, a INLINE_FRAGMENT, a VARIABLE_DEFINITION, a SCHEMA, a SCALAR, a OBJECT, a FIELD_DEFINITION, a ARGUMENT_DEFINITION, a INTERFACE, a UNION, a ENUM, a ENUM_VALUE, a INPUT_OBJECT, or a INPUT_FIELD_DEFINITION here.
1 │ directive @example on |
2 │
> 3 │ directive @ on | ARGUMENT_DEFINITION
│ ^^^^^^^^^
4 │
5 │ directive example on | ARGUMENT_DEFINITION
i Must be one of:
- QUERY
- MUTATION
- SUBSCRIPTION
- FIELD
- FRAGMENT_DEFINITION
- FRAGMENT_SPREAD
- INLINE_FRAGMENT
- VARIABLE_DEFINITION
- SCHEMA
- SCALAR
- OBJECT
- FIELD_DEFINITION
- ARGUMENT_DEFINITION
- INTERFACE
- UNION
- ENUM
- ENUM_VALUE
- INPUT_OBJECT
- INPUT_FIELD_DEFINITION
directive_definition.graphql:3:13 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Expand Down Expand Up @@ -396,7 +409,7 @@ directive_definition.graphql:6:19 parse ━━━━━━━━━━━━━
directive_definition.graphql:13:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× Expected a QUERY, a MUTATION, a SUBSCRIPTION, a FIELD, a FRAGMENT_DEFINITION, a FRAGMENT_SPREAD, a INLINE_FRAGMENT, a VARIABLE_DEFINITION, a SCHEMA, a SCALAR, a OBJECT, a FIELD_DEFINITION, a ARGUMENT_DEFINITION, a INTERFACE, a UNION, a ENUM, a ENUM_VALUE, a INPUT_OBJECT, or a INPUT_FIELD_DEFINITION but instead found 'directive'.
× Expected a valid directive location
11 │ |
12 │
Expand All @@ -405,14 +418,27 @@ directive_definition.graphql:13:1 parse ━━━━━━━━━━━━━
14 │
15 │ directve @example on
i Expected a QUERY, a MUTATION, a SUBSCRIPTION, a FIELD, a FRAGMENT_DEFINITION, a FRAGMENT_SPREAD, a INLINE_FRAGMENT, a VARIABLE_DEFINITION, a SCHEMA, a SCALAR, a OBJECT, a FIELD_DEFINITION, a ARGUMENT_DEFINITION, a INTERFACE, a UNION, a ENUM, a ENUM_VALUE, a INPUT_OBJECT, or a INPUT_FIELD_DEFINITION here.
11 │ |
12 │
> 13 │ directive @delegateField(: !) repeatable on OBJECT | INTERFACE
│ ^^^^^^^^^
14 │
15 │ directve @example on
i Must be one of:
- QUERY
- MUTATION
- SUBSCRIPTION
- FIELD
- FRAGMENT_DEFINITION
- FRAGMENT_SPREAD
- INLINE_FRAGMENT
- VARIABLE_DEFINITION
- SCHEMA
- SCALAR
- OBJECT
- FIELD_DEFINITION
- ARGUMENT_DEFINITION
- INTERFACE
- UNION
- ENUM
- ENUM_VALUE
- INPUT_OBJECT
- INPUT_FIELD_DEFINITION
directive_definition.graphql:13:26 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Expand Down Expand Up @@ -469,8 +495,7 @@ directive_definition.graphql:15:1 parse ━━━━━━━━━━━━━
directive_definition.graphql:19:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× Expected a QUERY, a MUTATION, a SUBSCRIPTION, a FIELD, a FRAGMENT_DEFINITION, a FRAGMENT_SPREAD, a INLINE_FRAGMENT, a VARIABLE_DEFINITION, a SCHEMA, a SCALAR, a OBJECT, a FIELD_DEFINITION, a ARGUMENT_DEFINITION, a INTERFACE, a UNION, a ENUM, a ENUM_VALUE, a INPUT_OBJECT, or a INPUT_FIELD_DEFINITION but instead found '123
| name'.
× Expected a valid directive location
17 │ directive @example on
18 │ | #
Expand All @@ -480,14 +505,26 @@ directive_definition.graphql:19:5 parse ━━━━━━━━━━━━━
│ ^^^^^^
21 │
i Expected a QUERY, a MUTATION, a SUBSCRIPTION, a FIELD, a FRAGMENT_DEFINITION, a FRAGMENT_SPREAD, a INLINE_FRAGMENT, a VARIABLE_DEFINITION, a SCHEMA, a SCALAR, a OBJECT, a FIELD_DEFINITION, a ARGUMENT_DEFINITION, a INTERFACE, a UNION, a ENUM, a ENUM_VALUE, a INPUT_OBJECT, or a INPUT_FIELD_DEFINITION here.
17 │ directive @example on
18 │ | #
> 19 │ | 123
│ ^^^
> 20 │ | name
│ ^^^^^^
21 │
i Must be one of:
- QUERY
- MUTATION
- SUBSCRIPTION
- FIELD
- FRAGMENT_DEFINITION
- FRAGMENT_SPREAD
- INLINE_FRAGMENT
- VARIABLE_DEFINITION
- SCHEMA
- SCALAR
- OBJECT
- FIELD_DEFINITION
- ARGUMENT_DEFINITION
- INTERFACE
- UNION
- ENUM
- ENUM_VALUE
- INPUT_OBJECT
- INPUT_FIELD_DEFINITION
```

0 comments on commit 79b8078

Please sign in to comment.