Expand description
Generator trait and registry used by ResponseBuilder
to produce values for GraphQL types, plus the built-in generators for the
standard GraphQL scalars.
§Built-in defaults
Generators::default pre-registers a generator for each of the five
standard GraphQL scalars:
| Type | Generator | Default range |
|---|---|---|
Boolean | BooleanGenerator | true or false |
Int | IntGenerator | 0..=100 |
Float | FloatGenerator | -1.0..=1.0 |
String | StringGenerator | 1–10 alphanumeric chars |
ID | IdGenerator | 0..=100, stringified |
Each per-type struct is public, so a custom generator can construct one
directly (for example, to call a configured IntGenerator inline) or
register a tuned instance via
ResponseBuilder::with_generator
to override the default range.
§Accessing defaults from a custom generator
Every Generator::generate call receives a &mut Generators<R> — the
same registry the builder is using, including any defaults from
Generators::default and any overrides registered with
ResponseBuilder::with_generator.
A custom generator can delegate back to the registry in two ways:
Generators::generate_scalar— fill a leaf field by named scalar type, falling back to a defaultStringGeneratorif nothing is registered. This is the common path for composite generators that only want to customize a few fields and let defaults handle the rest.Generators::try_generate— dispatch to any registered generator (composite or leaf) by type name, returningNoneif none is registered. Useful when a custom generator wants to compose results from other registered types.
Structs§
- Boolean
Generator - Generates a random boolean.
- Float
Generator - Generates a random float in the given inclusive range.
- Generators
- Registry of
Generators keyed by GraphQL type name. - IdGenerator
- Generates a random integer ID in the given inclusive range, serialized as a string.
- IntGenerator
- Generates a random integer in the given inclusive range.
- String
Generator - Generates a random alphanumeric string with length in the given inclusive range.
Traits§
- Generator
- A pluggable generator for the value of a named GraphQL type.