-
Notifications
You must be signed in to change notification settings - Fork 26
feat(nova-react-test-utils): add support for mocking data in relay resolvers #168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(nova-react-test-utils): add support for mocking data in relay resolvers #168
Conversation
…to sjwilczy/RelayResolversSupport
packages/nova-react-test-utils/src/relay/storybook-nova-decorator-relay.tsx
Show resolved
Hide resolved
packages/nova-react-test-utils/src/relay/storybook-nova-decorator-relay.tsx
Show resolved
Hide resolved
| for (const item of resolverData) { | ||
| context.mock.storeById(item.id, item); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we can somehow make this nicer. If you forget to do this it won't work, but perhaps if we generate these resolvers it might not be too bad.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added more docs to explain this pattern and I am open to suggestions on how to improve it. But at least as first iteration it looks good to me and happy to follow up if we detect nicer patterns while using it in 1JS
Summary
Enhanced the Nova Relay decorator to support providing mock data to Relay resolvers through the existing
resolversparameter. This enables per-story customization of Relay resolver behavior in Storybook, allowing the sameresolversconfiguration to mock both server GraphQL operations and Relay resolver data.Key Changes
Core Implementation:
getNovaRelayDecoratorto pass story-levelresolversto Relay environment creationcreateNovaRelayEnvironmentwithgetResolverContextForEnvironment()function that creates resolver context withresolve,storeById, andresolveByIdmethodsEnvironmentMockResolversContext<TypeMap>type for type-safe resolver context access (and TypeMap can still be used to make it resolve data types correctly)Examples & Documentation:
feedback-resolvers.tswithdisplayLabelfield resolversuggested-friends-resolvers.tsdemonstratingresolveByIdpattern with nested objects and@weaktypesAs
resolverContextexist only in newer relay versions, as an additional change we bump it to latest in the repo