graphql_schema_validation/
lib.rs1#![deny(unsafe_code, missing_docs, rust_2018_idioms)]
2#![allow(unused_crate_dependencies)]
3#![doc = include_str!("../README.md")]
4
5mod context;
6mod diagnostics;
7mod validate;
8
9use self::{context::*, diagnostics::*};
10use std::collections::HashMap;
11
12pub fn validate(sdl: &str) -> Diagnostics {
14 validate_with_options(sdl, Options::default())
15}
16
17pub fn validate_with_options(sdl: &str, options: Options) -> Diagnostics {
19 let parsed_ast = match async_graphql_parser::parse_schema(sdl) {
20 Ok(ast) => ast,
21 Err(err) => {
22 return Diagnostics {
23 errors: vec![miette::miette! {
24 "Syntax error: {}",
25 err.to_string()
26 }],
27 };
28 }
29 };
30
31 let mut ctx = Context::new(
32 sdl,
33 HashMap::with_capacity(parsed_ast.definitions.len()),
34 Diagnostics::default(),
35 options,
36 );
37
38 validate::validate(&parsed_ast, &mut ctx);
39
40 ctx.diagnostics
41}
42
43bitflags::bitflags! {
44 #[derive(Default)]
46 pub struct Options: u8 {
47 const FORBID_EXTENDING_UNKNOWN_TYPES = 0b1;
50 const DRAFT_VALIDATIONS = 0b01;
53 }
54}