Relay: TypeError: Cannot read property 'identifier' of undefined

Created on 24 Dec 2019  路  6Comments  路  Source: facebook/relay

Call stack

RelayModernStore.check
/Users/vidy/www/acme-admin-ui1/node_modules/relay-runtime/lib/store/RelayModernStore.js:133:55
RelayModernEnvironment._checkSelectorAndHandleMissingFields
/Users/vidy/www/acme-admin-ui1/node_modules/relay-runtime/lib/store/RelayModernEnvironment.js:229:30
RelayModernEnvironment.check
/Users/vidy/www/acme-admin-ui1/node_modules/relay-runtime/lib/store/RelayModernEnvironment.js:175:17
QueryResourceImpl._fetchAndSaveQuery
/Users/vidy/www/acme-admin-ui1/node_modules/react-relay/lib/relay-experimental/QueryResource.js:308:36
QueryResourceImpl.prepare
/Users/vidy/www/acme-admin-ui1/node_modules/react-relay/lib/relay-experimental/QueryResource.js:227:25
(anonymous function)
/Users/vidy/www/acme-admin-ui1/node_modules/react-relay/lib/relay-experimental/useLazyLoadQueryNode.js:52:26
wrapPrepareQueryResource
/Users/vidy/www/acme-admin-ui1/node_modules/react-relay/lib/relay-experimental/ProfilerContext.js:20:12
useLazyLoadQueryNode
/Users/vidy/www/acme-admin-ui1/node_modules/react-relay/lib/relay-experimental/useLazyLoadQueryNode.js:51:45
useLazyLoadQuery
/Users/vidy/www/acme-admin-ui1/node_modules/react-relay/lib/relay-experimental/useLazyLoadQuery.js:19:14
module.exports../src/layouts/BasicLayout.tsx.__webpack_exports__.default
./src/layouts/BasicLayout.tsx:119
  116 | };
  117 | 
  118 | export default ({ children }) => {
> 119 |   const menu = useLazyLoadQuery<BasicLayoutQuery>(
  120 |     graphql`
  121 |       query BasicLayoutQuery {
  122 |         applicationMenu

Where and why we have this error

lib/store/RelayModernStore.js

check = function check(operation, options) {
    var _this = this;

    var _this$_optimisticSour2, _ref5, _ref6;

    var selector = operation.root;
    var source = (_this$_optimisticSour2 = this._optimisticSource) !== null && _this$_optimisticSour2 !== void 0 ? _this$_optimisticSour2 : this._recordSource;
    var globalInvalidationEpoch = this._globalInvalidationEpoch;

    console.log(operation);  // an object as blow without key `request`

    var rootEntry = this._roots.get(operation.request.identifier);
    //...
}
{
  dataID: 'client:root',
  node: {
    kind: 'Operation',
    name: 'BasicLayoutQuery',
    argumentDefinitions: [],
    selections: [ [Object] ]
  },
  variables: {}
}

Library version

"react-relay": "^8.0.0",
"relay-compiler": "^8.0.0",
"relay-config": "^8.0.0",

Most helpful comment

add react-relay@experimental and [email protected] on your package to fix it

All 6 comments

This is a problem with esm, csm format of generated files

Typescript plugin needs to be upgraded to fix this

@sibelius , hi, the bundled QueryResource of v8 is not correct, this line var hasFullQuery = environment.check(operation.root) is supposed to be ar hasFullQuery = environment.check(operation).

/react-relay/lib/relay-experimental/QueryResource.js

_proto._fetchAndSaveQuery = function _fetchAndSaveQuery(cacheKey, operation, fetchObservable, fetchPolicy, renderPolicy, observer) {
    var _this2 = this;

    var environment = this._environment; // NOTE: Running `check` will write missing data to the store using any
    // missing data handlers specified on the environment;
    // We run it here first to make the handlers get a chance to populate
    // missing data.

    var hasFullQuery = environment.check(operation.root);
    var canPartialRender = hasFullQuery || renderPolicy === 'partial';
    var shouldFetch;
    var shouldAllowRender;
   //....
 }

@sibelius the hooks part of react-relay v8.0.0 on npm is on a1a40b68, which lacks 39363fedcfe408be8d3750393227126d099a9b5c
This api difference in this two version causes the runtime error

The experimental version of react-relay works well with relay-runtime 8.0.0, thanks

add react-relay@experimental and [email protected] on your package to fix it

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mike-marcacci picture mike-marcacci  路  3Comments

brad-decker picture brad-decker  路  3Comments

piotrblasiak picture piotrblasiak  路  3Comments

scotmatson picture scotmatson  路  3Comments

jstejada picture jstejada  路  3Comments