Skip to content

Conversation

@sjwilczynski
Copy link
Contributor

@sjwilczynski sjwilczynski commented Aug 4, 2025

Summary

Enhanced the Nova Relay decorator to support providing mock data to Relay resolvers through the existing resolvers parameter. This enables per-story customization of Relay resolver behavior in Storybook, allowing the same resolvers configuration to mock both server GraphQL operations and Relay resolver data.

Key Changes

Core Implementation:

  • Modified getNovaRelayDecorator to pass story-level resolvers to Relay environment creation
  • Enhanced createNovaRelayEnvironment with getResolverContextForEnvironment() function that creates resolver context with resolve, storeById, and resolveById methods
  • Added EnvironmentMockResolversContext<TypeMap> type for type-safe resolver context access (and TypeMap can still be used to make it resolve data types correctly)

Examples & Documentation:

  • Created simple example: feedback-resolvers.ts with displayLabel field resolver
  • Created complex example: suggested-friends-resolvers.ts demonstrating resolveById pattern with nested objects and @weak types
  • Updated README with new FAQ section explaining Relay resolver mocking capability

As resolverContext exist only in newer relay versions, as an additional change we bump it to latest in the repo

@sjwilczynski sjwilczynski marked this pull request as ready for review August 5, 2025 11:48
Comment on lines +73 to +75
for (const item of resolverData) {
context.mock.storeById(item.id, item);
}
Copy link
Member

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.

Copy link
Contributor Author

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

@sjwilczynski sjwilczynski merged commit af6253a into microsoft:main Aug 6, 2025
2 checks passed
@sjwilczynski sjwilczynski deleted the sjwilczy/RelayResolversSupport branch August 6, 2025 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants