Mocks
MockPlugin replaces exact Type.field resolvers with fixed values for tests, storybook-style
fixtures and local development. Everything else keeps running normally.
mock(type_name, field_name, value) and mock_path("Type.field", value) are equivalent.
value accepts anything implementing Into<gql::Value>, including models via
gql::Value::external.
What a mock replaces
A mock replaces the field's resolver. That means:
- the original resolver does not run;
- its argument validator does not run;
- field-level
.auth(...)does not run.
Object-level and interface-level authorization is installed outside the plugin chain, so it still runs and cannot be bypassed by a mock. If a mocked field must also enforce a scope, use an object rule or a wrapping plugin placed before the mock.
Subscriptions
A mocked subscription keeps its real stream and returns the mock for every event. That is useful for client work: the transport and subscription lifecycle are real, while the payload is stable.
Per-environment installation
Mocks are installed at build time. Choose them from configuration before build():
Do not install mocks in production. They are not a runtime permission check.
Writing a custom mock plugin
For generated data or randomized fixtures, implement Plugin::wrap_resolve and return a value
without calling next:
