question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[feature/Apollo] Error on page refresh: Cannot match against 'undefined' or 'null'.

See original GitHub issue

On the [feature/apollo] branch, I have a very basic component that receives data from a GraphQL query. When I go to this page, the query returns all of the data I would expect.

import React from 'react';
import PropTypes from 'prop-types';
import { graphql } from 'react-apollo';

import getChannelsandUsersQuery from './getChannelsandUsersQuery.graphql';

class SendMessageForm extends React.Component {
  render() {
    return (
      <div>
        Test
      </div>
    );
  }
}

export default graphql(getChannelsandUsersQuery)(SendMessageForm);

If I refresh the page, the app throws a big error:

Error: GraphQL error: Cannot match against 'undefined' or 'null'.
    at new ApolloError (C:\Users\asdf\Desktop\asdf\node_modules\apollo-client\src\errors\ApolloError.js:32:28)
    at C:\Users\asdf\Desktop\asdf\node_modules\apollo-client\src\core\QueryManager.js:281:41
    at C:\Users\asdf\Desktop\asdf\node_modules\apollo-client\src\core\QueryManager.js:726:25
    at Array.forEach (native)
    at C:\Users\asdf\Desktop\asdf\node_modules\apollo-client\src\core\QueryManager.js:723:27
    at Array.forEach (native)
    at QueryManager.broadcastQueries (C:\Users\asdf\Desktop\asdf\node_modules\apollo-client\src\core\QueryManager.js:720:42)
    at QueryManager.broadcastNewStore (C:\Users\asdf\Desktop\asdf\node_modules\apollo-client\src\core\QueryManager.js:71:14)
    at C:\Users\asdf\Desktop\asdf\node_modules\apollo-client\src\ApolloClient.js:45:44
    at C:\Users\asdf\Desktop\asdf\node_modules\redux-thunk\lib\index.js:14:16
    at Object.dispatch (C:\Users\asdf\Desktop\asdf\node_modules\redux\lib\applyMiddleware.js:45:18)
    at C:\Users\asdf\Desktop\asdf\node_modules\apollo-client\src\core\QueryManager.js:657:33
    at <anonymous>
    at process._tickDomainCallback (internal/process/next_tick.js:208:7)

I am still on the new side to react/graphql and this is a real head scratcher, can someone point me in the right direction so that refreshes do not break the app?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
tim-softcommented, Jul 12, 2017

There appears to be some disconnect between server and client apollo

Just adding stuff to the middleware context causes problems with SSR, but adding the same context beneath allows queries to run without crashing. I’ll need to keep digging as I don’t understand why this helps

//server.js
// Register API middleware
// -----------------------------------------------------------------------------
const graphqlMiddleware = expressGraphQL(async req => ({
  schema,
  context: {
   // Add some stuff
  },
  graphiql: __DEV__,
  rootValue: { request: req },
  pretty: __DEV__,
}));

//
// Register server-side rendering middleware
// -----------------------------------------------------------------------------
app.get('*', async (req, res, next) => {
  try {
    const css = new Set();

    const apolloClient = createApolloClient({
      schema,
      rootValue: { request: req },
      context: {
        // Add the same context stuff here
      }
    });
0reactions
ulanicommented, May 27, 2021

@tim-soft thank you very much for crating this issue! Unfortunately, we have close it due to inactivity. Feel free to re-open it or join our Discord channel for discussion.

NOTE: The main branch has been updated with React Starter Kit v2, using JAM-style architecture.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: Cannot match against 'undefined' or 'null'
this error should only arise if the array or object being destructured or its children is undefined or null . Exactly. In your...
Read more >
Uncaught TypeError: Cannot match against 'undefined' or 'null'.
i try run atom on safe mode,same error: Failed to load the tool-bar package. Cannot match against 'undefined' or 'null'. Hide Stack Trace...
Read more >
Auth0 client is null in React Component on page refresh
The error is Unhandled Rejection (TypeError): Cannot read property 'getTokenSilently' of undefined Works fine after the page is loaded.
Read more >
How to Build an Image Compressor Website using React - Morioh
In this article, I will help you create your own image compressor website using ... match the imageAccept list, or the server returned...
Read more >
On a page refresh, my app gives me a TypeError: uid null (react)
It works fine and retrieves details from the auth however when the page is refreshed, it gives this error: TypeError: Cannot read property...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found