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 DocumentBuilder<'_>
impl DocumentBuilder<'_>
Sourcepub fn arguments(
&mut self,
constness: Constness,
) -> ArbitraryResult<Vec<Argument>>
pub fn arguments( &mut self, constness: Constness, ) -> 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, constness: Constness) -> ArbitraryResult<Argument>
pub fn argument(&mut self, constness: Constness) -> 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 DocumentBuilder<'_>
impl DocumentBuilder<'_>
Sourcepub fn description(&mut self) -> ArbitraryResult<Description>
pub fn description(&mut self) -> ArbitraryResult<Description>
Create an arbitrary Description
Source§impl DocumentBuilder<'_>
impl DocumentBuilder<'_>
Sourcepub fn directives(
&mut self,
directive_location: DirectiveLocation,
) -> ArbitraryResult<IndexMap<Name, Directive>>
pub fn directives( &mut self, directive_location: DirectiveLocation, ) -> ArbitraryResult<IndexMap<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<IndexSet<DirectiveLocation>>
pub fn directive_locations( &mut self, ) -> ArbitraryResult<IndexSet<DirectiveLocation>>
Create an arbitrary IndexSet
of DirectiveLocation
Source§impl DocumentBuilder<'_>
impl DocumentBuilder<'_>
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<IndexSet<EnumValueDefinition>>
pub fn enum_values_definition( &mut self, ) -> Result<IndexSet<EnumValueDefinition>>
Create an arbitrary EnumValueDefinition
Source§impl DocumentBuilder<'_>
impl DocumentBuilder<'_>
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 DocumentBuilder<'_>
impl DocumentBuilder<'_>
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 DocumentBuilder<'_>
impl DocumentBuilder<'_>
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 DocumentBuilder<'_>
impl DocumentBuilder<'_>
Sourcepub fn input_value(
&mut self,
constness: Constness,
) -> ArbitraryResult<InputValue>
pub fn input_value( &mut self, constness: Constness, ) -> 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 DocumentBuilder<'_>
impl DocumentBuilder<'_>
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<IndexSet<Name>>
pub fn implements_interfaces(&mut self) -> ArbitraryResult<IndexSet<Name>>
Create an arbitrary IndexSet
of implemented interfaces
Source§impl DocumentBuilder<'_>
impl DocumentBuilder<'_>
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 DocumentBuilder<'_>
impl DocumentBuilder<'_>
Sourcepub fn object_type_definition(&mut self) -> ArbitraryResult<ObjectTypeDef>
pub fn object_type_definition(&mut self) -> ArbitraryResult<ObjectTypeDef>
Create an arbitrary ObjectTypeDef
Source§impl DocumentBuilder<'_>
impl DocumentBuilder<'_>
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 DocumentBuilder<'_>
impl DocumentBuilder<'_>
Sourcepub fn scalar_type_definition(&mut self) -> ArbitraryResult<ScalarTypeDef>
pub fn scalar_type_definition(&mut self) -> ArbitraryResult<ScalarTypeDef>
Create an arbitrary ScalarTypeDef
Source§impl DocumentBuilder<'_>
impl DocumentBuilder<'_>
Sourcepub fn schema_definition(&mut self) -> ArbitraryResult<SchemaDef>
pub fn schema_definition(&mut self) -> ArbitraryResult<SchemaDef>
Create an arbitrary SchemaDef
Source§impl DocumentBuilder<'_>
impl DocumentBuilder<'_>
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 DocumentBuilder<'_>
impl DocumentBuilder<'_>
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 DocumentBuilder<'_>
impl DocumentBuilder<'_>
Sourcepub fn union_type_definition(&mut self) -> ArbitraryResult<UnionTypeDef>
pub fn union_type_definition(&mut self) -> ArbitraryResult<UnionTypeDef>
Create an arbitrary UnionTypeDef
Source§impl DocumentBuilder<'_>
impl DocumentBuilder<'_>
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
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for DocumentBuilder<'a>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the foreground set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red()
and
green()
, which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg()
:
use yansi::{Paint, Color};
painted.fg(Color::White);
Set foreground color to white using white()
.
use yansi::Paint;
painted.white();
Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the background set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red()
and
on_green()
, which have the same functionality but
are pithier.
§Example
Set background color to red using fg()
:
use yansi::{Paint, Color};
painted.bg(Color::Red);
Set background color to red using on_red()
.
use yansi::Paint;
painted.on_red();
Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute
value
.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold()
and
underline()
, which have the same functionality
but are pithier.
§Example
Make text bold using attr()
:
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);
Make text bold using using bold()
.
use yansi::Paint;
painted.bold();
Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi
Quirk
value
.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask()
and
wrap()
, which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk()
:
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);
Enable wrapping using wrap()
.
use yansi::Paint;
painted.wrap();
Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition
value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted
only when both stdout
and stderr
are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);