Storybook: How do I use Apollo Dev Tools with Storybook?

Created on 2 Dec 2017  路  4Comments  路  Source: storybookjs/storybook

The "Apollo" tab will appear in the Chrome console if there exists a global window.__APOLLO_CLIENT__ object in your app.

My __APOLLO_CLIENT__ is created, but it gets attached to the storybook-preview-iframe, so the devtools don't connect. Any ideas on how to connect this to the global window?

https://github.com/apollographql/apollo-client-devtools

graphql compatibility with other tools question / support

Most helpful comment

Managed to solve this one 馃憤 This might be good to put a pointer to somewhere, and/or hopefully Google just picks this up for anyone searching for an iframe issue with other React tools

The key is just bumping the client object up to the iframe parent as part of .storybook/config.js

class DevtoolsIFrameFix extends React.Component {
  constructor() {
    super()
    if (window.parent !== window) {
      window.parent.__APOLLO_CLIENT__ = window.__APOLLO_CLIENT__
    }
  }

  render() {
    return React.Children.only(this.props.children)
  }
}

addDecorator(story => (
  <ThemeProvider theme={Theme}>
    <ApolloProvider client={client}>
      <DevtoolsIFrameFix>
        <Global>{story()}</Global>
      </DevtoolsIFrameFix>
    </ApolloProvider>
  </ThemeProvider>
))

All 4 comments

Managed to solve this one 馃憤 This might be good to put a pointer to somewhere, and/or hopefully Google just picks this up for anyone searching for an iframe issue with other React tools

The key is just bumping the client object up to the iframe parent as part of .storybook/config.js

class DevtoolsIFrameFix extends React.Component {
  constructor() {
    super()
    if (window.parent !== window) {
      window.parent.__APOLLO_CLIENT__ = window.__APOLLO_CLIENT__
    }
  }

  render() {
    return React.Children.only(this.props.children)
  }
}

addDecorator(story => (
  <ThemeProvider theme={Theme}>
    <ApolloProvider client={client}>
      <DevtoolsIFrameFix>
        <Global>{story()}</Global>
      </DevtoolsIFrameFix>
    </ApolloProvider>
  </ThemeProvider>
))

Can't say that this would work; __APOLLO_CLIENT__ is defined in the console, so it's applied correctly, but the Apollo tab doesn't show up in the devtools.

I have the same problem when i watch the story inside storybook, Dev tools doesn't show up. But it works if you open the story in another tab with "Open canvas in new tab"-button then the apollo tab in there.

I have the same problem when i watch the story inside storybook, Dev tools doesn't show up. But it works if you open the story in another tab with "Open canvas in new tab"-button then the apollo tab in there.

I agree with this except I only seem to get querys (not mutations). Both appear in the dev tools in my app, but when I render the Mutation component in storybook, and trigger the mutation, the function runs but does not appear in the Apollo client dev tools.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

arunoda picture arunoda  路  3Comments

purplecones picture purplecones  路  3Comments

MrOrz picture MrOrz  路  3Comments

tirli picture tirli  路  3Comments

Jonovono picture Jonovono  路  3Comments