pub struct DocumentBuilder<'a> { /* private fields */ }
Expand description

DocumentBuilder is a struct to build an arbitrary valid GraphQL document

// fuzz/fuzz_targets/my_apollo_smith_fuzz_target.rs
#![no_main]

use libfuzzer_sys::fuzz_target;
use arbitrary::Unstructured;
use apollo_smith::DocumentBuilder;

fuzz_target!(|input: &[u8]| {
    let mut u = Unstructured::new(input);
    let gql_doc = DocumentBuilder::new(&mut u)?;
    let document = gql_doc.finish();
    let document_str = String::from(document);

    // Your code here...
});

Implementations§

source§

impl<'a> DocumentBuilder<'a>

source

pub fn arguments(&mut self) -> ArbitraryResult<Vec<Argument>>

Create an arbitrary vector of Argument

source

pub fn arguments_with_def( &mut self, args_def: &ArgumentsDef ) -> ArbitraryResult<Vec<Argument>>

Create an arbitrary vector of Argument given ArgumentsDef

source

pub fn argument(&mut self) -> ArbitraryResult<Argument>

Create an arbitrary Argument

source

pub fn argument_with_def( &mut self, input_val_def: &InputValueDef ) -> ArbitraryResult<Argument>

Create an arbitrary Argument

source

pub fn arguments_definition(&mut self) -> ArbitraryResult<ArgumentsDef>

Create an arbitrary ArgumentsDef

source§

impl<'a> DocumentBuilder<'a>

source

pub fn description(&mut self) -> ArbitraryResult<Description>

Create an arbitrary Description

source§

impl<'a> DocumentBuilder<'a>

source

pub fn directives( &mut self, directive_location: DirectiveLocation ) -> ArbitraryResult<HashMap<Name, Directive>>

Create an arbitrary vector of Directive

source

pub fn directive( &mut self, directive_location: DirectiveLocation ) -> ArbitraryResult<Option<Directive>>

Create an arbitrary Directive given a directive location

source

pub fn directive_def(&mut self) -> ArbitraryResult<DirectiveDef>

Create an arbitrary DirectiveDef

source

pub fn directive_locations( &mut self ) -> ArbitraryResult<HashSet<DirectiveLocation>>

Create an arbitrary HashSet of DirectiveLocation

source§

impl<'a> DocumentBuilder<'a>

source

pub fn enum_type_definition(&mut self) -> Result<EnumTypeDef>

Create an arbitrary EnumTypeDef

source

pub fn choose_enum(&mut self) -> Result<&EnumTypeDef>

Choose an arbitrary EnumTypeDef in existings (already created) enum definitions

source

pub fn arbitrary_variant<'b>( &mut self, enum_: &'b EnumTypeDef ) -> Result<&'b Name>

Create an arbitrary variant Name given an enum

source

pub fn enum_values_definition(&mut self) -> Result<HashSet<EnumValueDefinition>>

Create an arbitrary EnumValueDefinition

source§

impl<'a> DocumentBuilder<'a>

source

pub fn fields_definition( &mut self, exclude: &[&Name] ) -> ArbitraryResult<Vec<FieldDef>>

Create an arbitrary list of FieldDef

source

pub fn field(&mut self, index: usize) -> ArbitraryResult<Field>

Create an arbitrary Field given an object type

source§

impl<'a> DocumentBuilder<'a>

source

pub fn fragment_definition(&mut self) -> ArbitraryResult<FragmentDef>

Create an arbitrary FragmentDef

source

pub fn fragment_spread( &mut self, excludes: &mut Vec<Name> ) -> ArbitraryResult<Option<FragmentSpread>>

Create an arbitrary FragmentSpread, returns None if no fragment definition was previously created

source

pub fn inline_fragment(&mut self) -> ArbitraryResult<InlineFragment>

Create an arbitrary InlineFragment

source

pub fn type_condition(&mut self) -> ArbitraryResult<TypeCondition>

Create an arbitrary TypeCondition

source§

impl<'a> DocumentBuilder<'a>

source

pub fn input_object_type_definition( &mut self ) -> ArbitraryResult<InputObjectTypeDef>

Create an arbitrary InputObjectTypeDef

source§

impl<'a> DocumentBuilder<'a>

source

pub fn input_value(&mut self) -> ArbitraryResult<InputValue>

Create an arbitrary InputValue

source

pub fn input_value_for_type(&mut self, ty: &Ty) -> ArbitraryResult<InputValue>

source

pub fn input_values_def(&mut self) -> ArbitraryResult<Vec<InputValueDef>>

Create an arbitrary list of InputValueDef

source

pub fn input_value_def(&mut self) -> ArbitraryResult<InputValueDef>

Create an arbitrary InputValueDef

source§

impl<'a> DocumentBuilder<'a>

source

pub fn interface_type_definition(&mut self) -> ArbitraryResult<InterfaceTypeDef>

Create an arbitrary InterfaceTypeDef

source

pub fn implements_interfaces(&mut self) -> ArbitraryResult<HashSet<Name>>

Create an arbitrary HashSet of implemented interfaces

source§

impl<'a> DocumentBuilder<'a>

source

pub fn name(&mut self) -> ArbitraryResult<Name>

Create an arbitrary Name

source

pub fn type_name(&mut self) -> ArbitraryResult<Name>

Create an arbitrary type Name

source

pub fn name_with_index(&mut self, index: usize) -> ArbitraryResult<Name>

Create an arbitrary Name with an index included in the name (to avoid name conflict)

source§

impl<'a> DocumentBuilder<'a>

source

pub fn object_type_definition(&mut self) -> ArbitraryResult<ObjectTypeDef>

Create an arbitrary ObjectTypeDef

source§

impl<'a> DocumentBuilder<'a>

source

pub fn operation_definition(&mut self) -> ArbitraryResult<Option<OperationDef>>

Create an arbitrary OperationDef taking the last SchemaDef

source§

impl<'a> DocumentBuilder<'a>

source

pub fn scalar_type_definition(&mut self) -> ArbitraryResult<ScalarTypeDef>

Create an arbitrary ScalarTypeDef

source§

impl<'a> DocumentBuilder<'a>

source

pub fn schema_definition(&mut self) -> ArbitraryResult<SchemaDef>

Create an arbitrary SchemaDef

source§

impl<'a> DocumentBuilder<'a>

source

pub fn selection_set(&mut self) -> ArbitraryResult<SelectionSet>

Create an arbitrary SelectionSet

source

pub fn selection( &mut self, index: usize, excludes: &mut Vec<Name> ) -> ArbitraryResult<Selection>

Create an arbitrary Selection

source§

impl<'a> DocumentBuilder<'a>

source

pub fn ty(&mut self) -> ArbitraryResult<Ty>

Create an arbitrary Ty

source

pub fn choose_ty(&mut self, existing_types: &[Ty]) -> ArbitraryResult<Ty>

Choose an arbitrary existing Ty given a slice of existing types

source

pub fn choose_named_ty(&mut self, existing_types: &[Ty]) -> ArbitraryResult<Ty>

Choose an arbitrary existing named Ty given a slice of existing types

source§

impl<'a> DocumentBuilder<'a>

source

pub fn union_type_definition(&mut self) -> ArbitraryResult<UnionTypeDef>

Create an arbitrary UnionTypeDef

source§

impl<'a> DocumentBuilder<'a>

source

pub fn variable_definitions(&mut self) -> ArbitraryResult<Vec<VariableDef>>

Create an arbitrary list of VariableDef

source

pub fn variable_definition(&mut self) -> ArbitraryResult<VariableDef>

Create an arbitrary VariableDef

source§

impl<'a> DocumentBuilder<'a>

source

pub fn new(u: &'a mut Unstructured<'a>) -> Result<Self>

Create an instance of DocumentBuilder

source

pub fn with_document( u: &'a mut Unstructured<'a>, document: Document ) -> Result<Self>

Create an instance of DocumentBuilder given a Document to be able to call methods on DocumentBuilder and generate valid entities like for example an operation

source

pub fn input_exhausted(&self) -> bool

Returns whether the provided Unstructured is now empty

source

pub fn finish(self) -> Document

Convert a DocumentBuilder into a GraphQL Document

Trait Implementations§

source§

impl<'a> Debug for DocumentBuilder<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for DocumentBuilder<'a>

§

impl<'a> !Send for DocumentBuilder<'a>

§

impl<'a> !Sync for DocumentBuilder<'a>

§

impl<'a> Unpin for DocumentBuilder<'a>

§

impl<'a> !UnwindSafe for DocumentBuilder<'a>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.