About
The goal of apollo-smith is to generate valid GraphQL documents by sampling
from all available possibilities of GraphQL grammar.
We've written apollo-smith to use in fuzzing, but you may wish to use it for
anything that requires GraphQL document generation.
apollo-smith is inspired by bytecodealliance's wasm-smith crate, and the
article written by Nick Fitzgerald on writing test case generators in Rust.
This is still a work in progress, for outstanding issues, checkout out the apollo-smith label in our issue tracker.
Rust versions
apollo-smith is tested on the latest stable version of Rust.
Older version may or may not be compatible.
Using apollo-smith with cargo fuzz
Define a new target with cargo fuzz,
$ cargo fuzz add my_apollo_smith_fuzz_target
and add apollo-smith to your Cargo.toml:
## fuzz/Cargo.toml
[]
= "0.15.2"
It can then be used in a fuzz_target along with the arbitrary crate,
// fuzz/fuzz_targets/my_apollo_smith_fuzz_target.rs
use fuzz_target;
use Unstructured;
use DocumentBuilder;
fuzz_target!;
and fuzzed with the following command:
$ cargo +nightly fuzz run my_apollo_smith_fuzz_target
Using apollo-smith with apollo-parser
You can use apollo-parser to generate valid operations in apollo-smith.
use fs;
use Parser;
use ;
use ;
/// This generate an arbitrary valid GraphQL operation
Generating responses using apollo-smith with apollo-compiler
If you have a GraphQL operation in the form of an ExecutableDocument and its
accompanying Schema, you can generate a response matching the shape of the
operation with apollo_smith::ResponseBuilder.
use Valid;
use ExecutableDocument;
use Schema;
use ResponseBuilder;
use Result;
use Unstructured;
use Rng;
use Value;
Limitations
- Recursive object type not yet supported (example :
myType { inner: myType })
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.