lifeiscontent / storybook-addon-apollo-client

MIT License
73 stars 19 forks source link

Support Storybook React Native #75

Closed Jonatthu closed 2 years ago

Jonatthu commented 2 years ago

Currently it throws an error:

ReferenceError: Can't find variable: document

Invariant Violation: "main" has not been registered. This can happen if:
* Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
* A module failed to load due to an error and `AppRegistry.registerComponent` wasn't called.
lifeiscontent commented 2 years ago

@Jonatthu none of the code here even mentions document, if you can provide a demo project so I can test, happy to help, but given I have yet to try this addon in a react native env, I'm not sure how to help without a lot of effort on my part.

marcosdiasdev commented 1 year ago

I can confirm it doesn't work on storybookjs/react-native.

I've installed the addon and added it to the addons list on main.js. The Storybook bootstrap script will add an import to the storybook.requires.js auto-generated file:

import "storybook-addon-apollo-client/register";

And then, it will fail to import from /register when trying to run Storybook:

Unable to resolve "storybook-addon-apollo-client/register" from ".storybook/storybook.requires.js"

I've tried adding "moduleResolution": "node16" to my "compilerOptions" on tsconfig.json as this addon is using package exports to map the register export, but I've had no success at all. Still the same error message.

@Jonatthu , did you manage to make this work?

lifeiscontent commented 1 year ago

@marcosdiasdev if you can put a demo project together, I can see what I can do to get it working

pfcodes commented 9 months ago

Was anyone ever able to get this to work?

lifeiscontent commented 9 months ago

@pfcodes i don't have time to work on it, but if you do, I can cut a release.

pfcodes commented 4 days ago

This is now working in Storybook 8.4 without any hacks needed. Looks like the Storybook team refactored the internals so React Native Storybook behaves a lot more like web. The "Apollo Client" tab doesn't render in the add-ons panel, but its a step forward.

lifeiscontent commented 3 days ago

@pfcodes if you could put a basic project starter together, I'd be happy to look into it! I only initially created this addon from using create-react-app (back when that was defacto for storybook integration) but plan on adding first class support for vite/etc soon. I just haven't personally been using apollo-client so I haven't had much of a reason to maintain it, and zero sponsorships to help.