bluejay_validator/executable/document/rules/
fragment_spread_target_defined.rs1use crate::executable::{
2 document::{Error, Path, Rule, Visitor},
3 Cache,
4};
5use bluejay_core::definition::{SchemaDefinition, TypeDefinitionReference};
6use bluejay_core::executable::{ExecutableDocument, FragmentSpread};
7
8pub struct FragmentSpreadTargetDefined<'a, E: ExecutableDocument, S: SchemaDefinition> {
9 errors: Vec<Error<'a, E, S>>,
10 cache: &'a Cache<'a, E, S>,
11}
12
13impl<'a, E: ExecutableDocument, S: SchemaDefinition> Visitor<'a, E, S>
14 for FragmentSpreadTargetDefined<'a, E, S>
15{
16 fn new(_: &'a E, _: &'a S, cache: &'a Cache<'a, E, S>) -> Self {
17 Self {
18 errors: Vec::new(),
19 cache,
20 }
21 }
22
23 fn visit_fragment_spread(
24 &mut self,
25 fragment_spread: &'a <E as ExecutableDocument>::FragmentSpread,
26 _scoped_type: TypeDefinitionReference<'a, S::TypeDefinition>,
27 _path: &Path<'a, E>,
28 ) {
29 if self
30 .cache
31 .fragment_definition(fragment_spread.name())
32 .is_none()
33 {
34 self.errors
35 .push(Error::FragmentSpreadTargetUndefined { fragment_spread });
36 }
37 }
38}
39
40impl<'a, E: ExecutableDocument + 'a, S: SchemaDefinition + 'a> Rule<'a, E, S>
41 for FragmentSpreadTargetDefined<'a, E, S>
42{
43 type Error = Error<'a, E, S>;
44 type Errors = std::vec::IntoIter<Error<'a, E, S>>;
45
46 fn into_errors(self) -> Self::Errors {
47 self.errors.into_iter()
48 }
49}