There are two types of mocks used by the Pioneer
- GraphQL (query-node) mocks
- Local node mocks
To test most of the extrinsics requires existing on-chain data. To create some on-chain objects use the yarn run node-mocks
script or use the polkadot apps wallet application to create them beforehand.
Available commands:
yarn node-mocks members:create
– generate memberships using query-node mocks datayarn node-mocks set-budget
- Set membership Working Group budgetyarn node-mocks opening:create
- Create an openingyarn node-mocks opening:fill
- Fill existing openingyarn node-mocks transfer
- Transfer tokens between accounts
To show help:
yarn node-mocks --help
You can also connect to the node using Polkadot apps wallet to interact with the node.
To mock the query-node server we use Mirage JS in tests, storybook data and for local development.
All MirageJS & query-node mocks are stored inside the @/mocks
.
In order to properly mock an Entity
you should:
- Prepare mocked data
- Write a generator that re-creates seed raw data as JSON file.
- See generators for examples.
- Write a MirageJS seed function
- A seed function will create proper MirageJS database entries from raw data.
- It should add only the data used by queries. Other information can be omitted.
- A seed function may create related objects and/or add additional mock information.
- Optionally: Some relations doesn't translate well in MirageJS GraphQL implementation. See
fixAssiociations()
for details.
- Run the
yarn query-node-mocks
to recreate mocks - Add GraphQL query resolvers
- Resolvers are used to handle the passed GraphQL query and return the data in a similar fashion to Hydra's GraphQL server.
- In most cases you'd only need to add a general query resolver for each type of queries:
getWhereResolver('Entity')
- returns a resolver that handles multiple results are returned (many), also used for paginated results, e.g.forumPosts
,memberships
getUniqueResolver('Entity')
– returns a resolver that handles unique results (one), e.g.forumPostByUniqueInput
,membershipByUniqueInput
getConnectionResolver('Entity')
- return a resolver for relay-style pagination results, e.g.forumPostsConneciton
,membershipsConnection
-
"Mirage: The xxx model has multiple possible inverse associations for xxx.xxx association"
See
fixAssociations()
for similar errors and fix. -
No data fetched from the query
See if proper query resolver is present in the
@/mocks/server.ts
file. -
No associated data in the mocked response
This might be a case when seeding, instead of passing a MirageJS object a simple object was passed.
// Wrong: server.schema.create('Parent', { name: 'foo', child: { name: 'baz' } }) // Correct: server.schema.create('Parent', { name: 'foo', child: server.schema.create('Child', { name: 'baz' }) }) // Also OK if Child's 'id' is known: server.schema.create('Parent', { name: 'foo', childId: '7' })