1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//! # Validation Rules for GraphQL ASTs
//!
//! This module contains logic to run validation rules on GraphQL Query Language documents.
//! It provides rules that have already been implemented to validate a document as much as it can
//! without using any schema information, which are rules grouped into this module's [`DefaultRules`](rules::DefaultRules)
//! and utilities to create your own [`ValidationRules`](ValidationRule).
//!
//! The rules this module already comes with are:
//!
//! - [`rules::KnownFragmentNames`]: validates that all spread fragments are defined
//! - [`rules::LoneAnonymousOperation`]: validates that a document only contains a single anonymous operation
//! - [`rules::NoFragmentCycles`]: validates that no fragment is spread in on itself to avoid looping
//! - [`rules::NoUndefinedVariables`]: checks that all used variables are defined per operation
//! - [`rules::NoUnusedFragments`]: validates that all fragments in a document are used at least once
//! - [`rules::UniqueArgumentNames`]: checks for arguments that are used to not contain duplicates
//! - [`rules::UniqueFragmentNames`]: checks that no fragments share the same name
//! - [`rules::UniqueOperationNames`]: checks that no operations share the same name
//! - [`rules::UniqueVariableNames`]: checks that no variables share the same name
//!
//! The [visit](crate::visit) module is used to actually execute validation rules.
//! The [`ValidationRule`] trait is simply defined to implement the [Visitor](crate::visit::Visitor) trait
//! and to accept the [`ValidationContext`], which is used to keep track of validation errors.
//!
//! As such, the [`DefaultRules`](rules::DefaultRules) rule is a [`ValidationRule`] itself that's
//! composed using the [`ComposedVisitor`](crate::visit::ComposedVisitor) utility.
//!
//! All rules must implement the [`DefaultIn`](crate::ast::DefaultIn) or `Default` trait, which makes it easier to quickly run a validation
//! rule and isolates them from external state, since no validation requires any external state.
//!
//! For example, this is one way to run a validation rule, in this case `DefaultRules`:
//!
//! ```
//! use graphql_query::{ast::*, validate::*};
//!
//! let ctx = ASTContext::new();
//! let document = Document::parse(&ctx, "{ field }").unwrap();
//!
//! DefaultRules::validate(&ctx, &document).unwrap()
//! ```
//!
//! Another way is to utilize the [`ValidateNode`] trait instead to run validation starting from an
//! AST Node rather from the rule itself:
//!
//! ```
//! use graphql_query::{ast::*, validate::*};
//!
//! let ctx = ASTContext::new();
//! let document = Document::parse(&ctx, "{ field }").unwrap();
//! document.validate::<DefaultRules>(&ctx).unwrap()
//! ```
pub use ValidationContext;
pub use DefaultRules;
pub use *;