-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added diagnostic for unsupported operations.
- Loading branch information
Showing
11 changed files
with
137 additions
and
0 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
[E0329] Error: Operation must be defined in schema before it can be used. | ||
╭─[graphql:1:1] | ||
│ | ||
1 │ query A { | ||
· ──┬── | ||
· ╰──── Schema doesn't have a `Query` type. You might be interested in using `@litho(url: "...")` to automatically import your existing schema. Learn more at https://litho.dev/docs/operations/import-schemas/. | ||
───╯ | ||
|
||
|
||
[E0329] Error: Operation must be defined in schema before it can be used. | ||
╭─[graphql:5:1] | ||
│ | ||
5 │ mutation B { | ||
· ────┬─── | ||
· ╰───── Schema doesn't have a `Mutation` type. You might be interested in using `@litho(url: "...")` to automatically import your existing schema. Learn more at https://litho.dev/docs/operations/import-schemas/. | ||
───╯ | ||
|
||
|
||
[E0329] Error: Operation must be defined in schema before it can be used. | ||
╭─[graphql:9:1] | ||
│ | ||
9 │ subscription C { | ||
· ──────┬───── | ||
· ╰─────── Schema doesn't have a `Subscription` type. You might be interested in using `@litho(url: "...")` to automatically import your existing schema. Learn more at https://litho.dev/docs/operations/import-schemas/. | ||
───╯ |
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,11 @@ | ||
query A { | ||
a | ||
} | ||
|
||
mutation B { | ||
b | ||
} | ||
|
||
subscription C { | ||
c | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
mod lone_anonymous_operation; | ||
mod operation_name_uniqueness; | ||
mod supported_operation; | ||
|
||
pub use lone_anonymous_operation::LoneAnonymousOperation; | ||
pub use operation_name_uniqueness::OperationNameUniqueness; | ||
pub use supported_operation::SupportedOperation; |
49 changes: 49 additions & 0 deletions
49
litho-validation/src/executable/operations/supported_operation.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,49 @@ | ||
use std::hash::Hash; | ||
use std::sync::Arc; | ||
|
||
use litho_diagnostics::Diagnostic; | ||
use litho_language::ast::*; | ||
use litho_types::Database; | ||
|
||
pub struct SupportedOperation<'a, T>(pub &'a Database<T>) | ||
where | ||
T: Eq + Hash; | ||
|
||
impl<'a, T> Visit<'a, T> for SupportedOperation<'a, T> | ||
where | ||
T: Eq + Hash + ToString, | ||
{ | ||
type Accumulator = Vec<Diagnostic<Span>>; | ||
|
||
fn visit_operation_definition( | ||
&self, | ||
node: &'a Arc<OperationDefinition<T>>, | ||
accumulator: &mut Self::Accumulator, | ||
) { | ||
let Some(selection_set) = node.selection_set.ok() else { | ||
return | ||
}; | ||
|
||
let Some(ty) = self.0.inference.type_by_selection_set.get(selection_set) else { | ||
return | ||
}; | ||
|
||
if self.0.type_exists(ty) { | ||
return; | ||
} | ||
|
||
let name = match node.ty.as_ref() { | ||
Some(OperationType::Query(_)) | None => "Query", | ||
Some(OperationType::Mutation(_)) => "Mutation", | ||
Some(OperationType::Subscription(_)) => "Subscription", | ||
}; | ||
|
||
accumulator.push(Diagnostic::unsupported_operation( | ||
name.to_owned(), | ||
node.ty | ||
.as_ref() | ||
.map(|ty| ty.span()) | ||
.unwrap_or(selection_set.span()), | ||
)) | ||
} | ||
} |