Function: entityGraph()
entityGraph<
TEntityFields,TEntityRelations>(arbitraries,relations,constraints?):Arbitrary<EntityGraphValue<TEntityFields,TEntityRelations>>
Defined in: packages/fast-check/src/arbitrary/entityGraph.ts:112
Generates interconnected entities with relationships based on a schema definition.
This arbitrary creates structured data where entities can reference each other through defined relationships. The generated values automatically include links between entities, making it ideal for testing graph structures, relational data, or interconnected object models.
The output is an object where each key corresponds to an entity type and the value is an array of entities of that type. Entities contain both their data fields and relationship links.
Type Parameters
| Type Parameter |
|---|
TEntityFields |
TEntityRelations extends EntityGraphRelations<TEntityFields> |
Parameters
| Parameter | Type | Description |
|---|---|---|
arbitraries | EntityGraphArbitraries<TEntityFields> | Defines the data fields for each entity type (non-relational properties) |
relations | TEntityRelations | Defines how entities reference each other (relational properties) |
constraints | EntityGraphContraints<TEntityFields> | Optional configuration to customize generation behavior |
Returns
Arbitrary<EntityGraphValue<TEntityFields, TEntityRelations>>
Examples
// Generate a simple directed graph where nodes link to other nodes
fc.entityGraph(
{ node: { id: fc.stringMatching(/^[A-Z][a-z]*$/) } },
{ node: { linkTo: { arity: 'many', type: 'node' } } },
)
// Produces: { node: [{ id: "Abc", linkTo: [<node#1>, <node#0>] }, ...] }
// Generate employees with managers and teams
fc.entityGraph(
{
employee: { name: fc.string() },
team: { name: fc.string() }
},
{
employee: {
manager: { arity: '0-1', type: 'employee' }, // Optional manager
team: { arity: '1', type: 'team' } // Required team
},
team: {}
}
)
Remarks
Since 4.5.0