profile
viewpoint

Ask questionsTypeError: Cannot read property 'id' of undefined at getRequestCacheKey

Hi! Just upgrading to 2.0.0 and I've tried to cut down to as basic a case as I can, but still having problems :(

Using:

{
    "react": "^16.7.0",
    "react-relay": "^2.0.0",
    "relay-runtime": "^2.0.0",
    "relay-compiler": "^1.6.2",
}

Simple query:

const TopbarFragmentWrapperQuery = graphql`
  query TopbarFragmentWrapperQuery {
    loggedInUserInfo {
      user {
        name {
          firstName
        }
      }
    }
  }
`;

Simple render:

const TopbarFragmentWrapper = withRouter(({ environment, history, location, mobile }) => (
  <QueryRenderer
    environment={environment}
    query={TopbarFragmentWrapperQuery}
    variables={{}}
    render={({ error, props }) => {
      if (error) {
        return <div>{error.message}</div>;
      } else if (props) {
        return (
          <ComponentGoesHere />
        );
      }
    }}
  />
));

Receiving error:

ReactRelayQueryRenderer.js?36f2:258 Uncaught TypeError: Cannot read property 'id' of undefined
    at getRequestCacheKey (ReactRelayQueryRenderer.js?36f2:258)
    at new ReactRelayQueryRenderer (ReactRelayQueryRenderer.js?36f2:67)
    at constructClassInstance (react-dom.development.js?3156:12628)
    at updateClassComponent (react-dom.development.js?3156:14480)
    at beginWork (react-dom.development.js?3156:15335)
    at performUnitOfWork (react-dom.development.js?3156:18150)
    at workLoop (react-dom.development.js?3156:18190)
    at HTMLUnknownElement.callCallback (react-dom.development.js?3156:149)
    at Object.invokeGuardedCallbackDev (react-dom.development.js?3156:199)
    at invokeGuardedCallback (react-dom.development.js?3156:256)
    at replayUnitOfWork (react-dom.development.js?3156:17437)
    at renderRoot (react-dom.development.js?3156:18309)
    at performWorkOnRoot (react-dom.development.js?3156:19165)
    at performWork (react-dom.development.js?3156:19077)
    at performSyncWork (react-dom.development.js?3156:19051)
    at requestWork (react-dom.development.js?3156:18920)

Sorry, I'm not sure what other information will be helpful and just wondered if that error message triggers anyone to point me in the right direction?

Looks like it's coming from this line: requestCacheKey = getRequestCacheKey(request.params, props.variables);

Where request.params doesn't exist on the request object at that point.

facebook/relay

Answer questions Stephen2

After re running yarn or npm install

Did you rerun relay-compiler from CLI to regenerate .graphql.js files?

useful!
source:https://uonfu.com/
Github User Rank List