title: Unhandled GraphQL subscription error ReferenceError: document is not defined
body: <p>I'm trying to setup a subscription with my React Native app and Rails Graphql server but I get the following error mess</p>
  
  <blockquote>
    <p>Unhandled GraphQL subscription error ReferenceError: document is not defined</p>
  </blockquote>
  
  <p>I'm suspecting one of the library that I use is using document but not sure which one and the exemple I followed was a setup for a React app instead of React Native.</p>
  
  <p>I followed this guide: <a href="https://haughtcodeworks.com/blog/software-development/graphql-rails-react-standalone/" rel="nofollow noreferrer">https://haughtcodeworks.com/blog/software-development/graphql-rails-react-standalone/</a></p>
  
  <p>Here is my app.js setup</p>
  
  <p>...</p>
  
  <pre><code>const httpLink = createHttpLink({
    uri: `${global.URL}/graphql`,
  })
  
  const cable = ActionCable.createConsumer('ws://localhost:3000/cable')
  
  const hasSubscriptionOperation = ({ query: { definitions } }) =&gt; {
    return definitions.some(
      ({ kind, operation }) =&gt; kind === 'OperationDefinition' &amp;&amp; operation === 'subscription',
    )
  }
  
  const link = ApolloLink.split(
    hasSubscriptionOperation,
    new ActionCableLink({cable}),
    httpLink
  )
  const client = new ApolloClient({
    link: link,
    cache: new InMemoryCache()
  })
  
  return (
    &lt;ApolloProvider client={client}&gt;
      &lt;Root /&gt;
    &lt;/ApolloProvider&gt;
  )
  </code></pre>
  
  <p>I'm open to sharing more of my code but since I'm not sure where the error could come from I would need some guidance first. </p>