Struct apollo_smith::DocumentBuilder
source · 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>
impl<'a> DocumentBuilder<'a>
sourcepub fn arguments(&mut self) -> ArbitraryResult<Vec<Argument>>
pub fn arguments(&mut self) -> ArbitraryResult<Vec<Argument>>
Create an arbitrary vector of Argument
sourcepub fn arguments_with_def(
&mut self,
args_def: &ArgumentsDef
) -> ArbitraryResult<Vec<Argument>>
pub fn arguments_with_def(
&mut self,
args_def: &ArgumentsDef
) -> ArbitraryResult<Vec<Argument>>
Create an arbitrary vector of Argument
given ArgumentsDef
sourcepub fn argument(&mut self) -> ArbitraryResult<Argument>
pub fn argument(&mut self) -> ArbitraryResult<Argument>
Create an arbitrary Argument
sourcepub fn argument_with_def(
&mut self,
input_val_def: &InputValueDef
) -> ArbitraryResult<Argument>
pub fn argument_with_def(
&mut self,
input_val_def: &InputValueDef
) -> ArbitraryResult<Argument>
Create an arbitrary Argument
sourcepub fn arguments_definition(&mut self) -> ArbitraryResult<ArgumentsDef>
pub fn arguments_definition(&mut self) -> ArbitraryResult<ArgumentsDef>
Create an arbitrary ArgumentsDef
source§impl<'a> DocumentBuilder<'a>
impl<'a> DocumentBuilder<'a>
sourcepub fn description(&mut self) -> ArbitraryResult<Description>
pub fn description(&mut self) -> ArbitraryResult<Description>
Create an arbitrary Description
source§impl<'a> DocumentBuilder<'a>
impl<'a> DocumentBuilder<'a>
sourcepub fn directives(
&mut self,
directive_location: DirectiveLocation
) -> ArbitraryResult<HashMap<Name, Directive>>
pub fn directives(
&mut self,
directive_location: DirectiveLocation
) -> ArbitraryResult<HashMap<Name, Directive>>
Create an arbitrary vector of Directive
sourcepub fn directive(
&mut self,
directive_location: DirectiveLocation
) -> ArbitraryResult<Option<Directive>>
pub fn directive(
&mut self,
directive_location: DirectiveLocation
) -> ArbitraryResult<Option<Directive>>
Create an arbitrary Directive
given a directive location
sourcepub fn directive_def(&mut self) -> ArbitraryResult<DirectiveDef>
pub fn directive_def(&mut self) -> ArbitraryResult<DirectiveDef>
Create an arbitrary DirectiveDef
sourcepub fn directive_locations(
&mut self
) -> ArbitraryResult<HashSet<DirectiveLocation>>
pub fn directive_locations(
&mut self
) -> ArbitraryResult<HashSet<DirectiveLocation>>
Create an arbitrary HashSet
of DirectiveLocation
source§impl<'a> DocumentBuilder<'a>
impl<'a> DocumentBuilder<'a>
sourcepub fn enum_type_definition(&mut self) -> Result<EnumTypeDef>
pub fn enum_type_definition(&mut self) -> Result<EnumTypeDef>
Create an arbitrary EnumTypeDef
sourcepub fn choose_enum(&mut self) -> Result<&EnumTypeDef>
pub fn choose_enum(&mut self) -> Result<&EnumTypeDef>
Choose an arbitrary EnumTypeDef
in existings (already created) enum definitions
sourcepub fn arbitrary_variant<'b>(
&mut self,
enum_: &'b EnumTypeDef
) -> Result<&'b Name>
pub fn arbitrary_variant<'b>(
&mut self,
enum_: &'b EnumTypeDef
) -> Result<&'b Name>
Create an arbitrary variant Name
given an enum
sourcepub fn enum_values_definition(&mut self) -> Result<HashSet<EnumValueDefinition>>
pub fn enum_values_definition(&mut self) -> Result<HashSet<EnumValueDefinition>>
Create an arbitrary EnumValueDefinition
source§impl<'a> DocumentBuilder<'a>
impl<'a> DocumentBuilder<'a>
sourcepub fn fields_definition(
&mut self,
exclude: &[&Name]
) -> ArbitraryResult<Vec<FieldDef>>
pub fn fields_definition(
&mut self,
exclude: &[&Name]
) -> ArbitraryResult<Vec<FieldDef>>
Create an arbitrary list of FieldDef
sourcepub fn field(&mut self, index: usize) -> ArbitraryResult<Field>
pub fn field(&mut self, index: usize) -> ArbitraryResult<Field>
Create an arbitrary Field
given an object type
source§impl<'a> DocumentBuilder<'a>
impl<'a> DocumentBuilder<'a>
sourcepub fn fragment_definition(&mut self) -> ArbitraryResult<FragmentDef>
pub fn fragment_definition(&mut self) -> ArbitraryResult<FragmentDef>
Create an arbitrary FragmentDef
sourcepub fn fragment_spread(
&mut self,
excludes: &mut Vec<Name>
) -> ArbitraryResult<Option<FragmentSpread>>
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
sourcepub fn inline_fragment(&mut self) -> ArbitraryResult<InlineFragment>
pub fn inline_fragment(&mut self) -> ArbitraryResult<InlineFragment>
Create an arbitrary InlineFragment
sourcepub fn type_condition(&mut self) -> ArbitraryResult<TypeCondition>
pub fn type_condition(&mut self) -> ArbitraryResult<TypeCondition>
Create an arbitrary TypeCondition
source§impl<'a> DocumentBuilder<'a>
impl<'a> DocumentBuilder<'a>
sourcepub fn input_object_type_definition(
&mut self
) -> ArbitraryResult<InputObjectTypeDef>
pub fn input_object_type_definition(
&mut self
) -> ArbitraryResult<InputObjectTypeDef>
Create an arbitrary InputObjectTypeDef
source§impl<'a> DocumentBuilder<'a>
impl<'a> DocumentBuilder<'a>
sourcepub fn input_value(&mut self) -> ArbitraryResult<InputValue>
pub fn input_value(&mut self) -> ArbitraryResult<InputValue>
Create an arbitrary InputValue
pub fn input_value_for_type(&mut self, ty: &Ty) -> ArbitraryResult<InputValue>
sourcepub fn input_values_def(&mut self) -> ArbitraryResult<Vec<InputValueDef>>
pub fn input_values_def(&mut self) -> ArbitraryResult<Vec<InputValueDef>>
Create an arbitrary list of InputValueDef
sourcepub fn input_value_def(&mut self) -> ArbitraryResult<InputValueDef>
pub fn input_value_def(&mut self) -> ArbitraryResult<InputValueDef>
Create an arbitrary InputValueDef
source§impl<'a> DocumentBuilder<'a>
impl<'a> DocumentBuilder<'a>
sourcepub fn interface_type_definition(&mut self) -> ArbitraryResult<InterfaceTypeDef>
pub fn interface_type_definition(&mut self) -> ArbitraryResult<InterfaceTypeDef>
Create an arbitrary InterfaceTypeDef
sourcepub fn implements_interfaces(&mut self) -> ArbitraryResult<HashSet<Name>>
pub fn implements_interfaces(&mut self) -> ArbitraryResult<HashSet<Name>>
Create an arbitrary HashSet
of implemented interfaces
source§impl<'a> DocumentBuilder<'a>
impl<'a> DocumentBuilder<'a>
sourcepub fn name(&mut self) -> ArbitraryResult<Name>
pub fn name(&mut self) -> ArbitraryResult<Name>
Create an arbitrary Name
sourcepub fn type_name(&mut self) -> ArbitraryResult<Name>
pub fn type_name(&mut self) -> ArbitraryResult<Name>
Create an arbitrary type Name
sourcepub fn name_with_index(&mut self, index: usize) -> ArbitraryResult<Name>
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>
impl<'a> DocumentBuilder<'a>
sourcepub fn object_type_definition(&mut self) -> ArbitraryResult<ObjectTypeDef>
pub fn object_type_definition(&mut self) -> ArbitraryResult<ObjectTypeDef>
Create an arbitrary ObjectTypeDef
source§impl<'a> DocumentBuilder<'a>
impl<'a> DocumentBuilder<'a>
sourcepub fn operation_definition(&mut self) -> ArbitraryResult<Option<OperationDef>>
pub fn operation_definition(&mut self) -> ArbitraryResult<Option<OperationDef>>
Create an arbitrary OperationDef
taking the last SchemaDef
source§impl<'a> DocumentBuilder<'a>
impl<'a> DocumentBuilder<'a>
sourcepub fn scalar_type_definition(&mut self) -> ArbitraryResult<ScalarTypeDef>
pub fn scalar_type_definition(&mut self) -> ArbitraryResult<ScalarTypeDef>
Create an arbitrary ScalarTypeDef
source§impl<'a> DocumentBuilder<'a>
impl<'a> DocumentBuilder<'a>
sourcepub fn schema_definition(&mut self) -> ArbitraryResult<SchemaDef>
pub fn schema_definition(&mut self) -> ArbitraryResult<SchemaDef>
Create an arbitrary SchemaDef
source§impl<'a> DocumentBuilder<'a>
impl<'a> DocumentBuilder<'a>
sourcepub fn selection_set(&mut self) -> ArbitraryResult<SelectionSet>
pub fn selection_set(&mut self) -> ArbitraryResult<SelectionSet>
Create an arbitrary SelectionSet
sourcepub fn selection(
&mut self,
index: usize,
excludes: &mut Vec<Name>
) -> ArbitraryResult<Selection>
pub fn selection(
&mut self,
index: usize,
excludes: &mut Vec<Name>
) -> ArbitraryResult<Selection>
Create an arbitrary Selection
source§impl<'a> DocumentBuilder<'a>
impl<'a> DocumentBuilder<'a>
sourcepub fn ty(&mut self) -> ArbitraryResult<Ty>
pub fn ty(&mut self) -> ArbitraryResult<Ty>
Create an arbitrary Ty
sourcepub fn choose_ty(&mut self, existing_types: &[Ty]) -> ArbitraryResult<Ty>
pub fn choose_ty(&mut self, existing_types: &[Ty]) -> ArbitraryResult<Ty>
Choose an arbitrary existing Ty
given a slice of existing types
sourcepub fn choose_named_ty(&mut self, existing_types: &[Ty]) -> ArbitraryResult<Ty>
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>
impl<'a> DocumentBuilder<'a>
sourcepub fn union_type_definition(&mut self) -> ArbitraryResult<UnionTypeDef>
pub fn union_type_definition(&mut self) -> ArbitraryResult<UnionTypeDef>
Create an arbitrary UnionTypeDef
source§impl<'a> DocumentBuilder<'a>
impl<'a> DocumentBuilder<'a>
sourcepub fn variable_definitions(&mut self) -> ArbitraryResult<Vec<VariableDef>>
pub fn variable_definitions(&mut self) -> ArbitraryResult<Vec<VariableDef>>
Create an arbitrary list of VariableDef
sourcepub fn variable_definition(&mut self) -> ArbitraryResult<VariableDef>
pub fn variable_definition(&mut self) -> ArbitraryResult<VariableDef>
Create an arbitrary VariableDef
source§impl<'a> DocumentBuilder<'a>
impl<'a> DocumentBuilder<'a>
sourcepub fn new(u: &'a mut Unstructured<'a>) -> Result<Self>
pub fn new(u: &'a mut Unstructured<'a>) -> Result<Self>
Create an instance of DocumentBuilder
sourcepub fn with_document(
u: &'a mut Unstructured<'a>,
document: Document
) -> Result<Self>
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
sourcepub fn input_exhausted(&self) -> bool
pub fn input_exhausted(&self) -> bool
Returns whether the provided Unstructured
is now empty