graphql_depth_limit

Crates.iographql_depth_limit
lib.rsgraphql_depth_limit
version0.1.2
sourcesrc
created_at2020-02-03 01:42:38.510421
updated_at2020-04-30 06:57:37.828013
description A small lib for graphql depth limit analysis on graphql queries.
homepage
repositoryhttps://github.com/engylemure/graphql_depth_limit
max_upload_size
id204371
size29,275
Jordão Rodrigues Oliveira Rosario (engylemure)

documentation

README

graphql_depth_limit

Crate

A graphql depth limit validation in Rust inspired by graphql_depth_limit

Add this to your Cargo.toml:

[dependencies]
graphql_depth_limit = "0.1.1"

and this to your crate root (if you're using Rust 2015):

extern crate graphql_depth_limit;

Here's a simple example for verification of a graphql query:

use graphql_depth_limit::QueryDepthAnalyzer;

fn main() {
    let query = r#"
                query {
                  a {
                    b {
                      c
                    }
                  }
                }
            "#;
    let depth = match QueryDepthAnalyzer::new(query, vec![], |_a, _b| true) {
        Ok(validator) => validator.verify(5),
        Err(val) => Err(DepthLimitError::Parse(val))
    };
    asssert_eq!(depth.ok()?, 3);
}
Commit count: 8

cargo fmt