facebookexperimental / Recoil

Recoil is an experimental state management library for React apps. It provides several capabilities that are difficult to achieve with React alone, while being compatible with the newest features of React.
https://recoiljs.org/
MIT License
19.61k stars 1.19k forks source link

Cannot read properties of undefined (reading 'operationKind') SOLUTION? MAYBE? #2223

Open raelBernardino opened 1 year ago

raelBernardino commented 1 year ago

I tried utilizing Recoil's recoil-relay to be able to link Recoil atoms/selectors to Relay's store. Upon following Recoil's recoil-relay steps for doing so (click here), I was receiving this error:

image

Upon further investigation, it seems that graphQLSelectorFamily function in the recoil-relay module wasn't properly extracting the field "operationKind" correctly. Original: image

When I console logged the query parameter being passed into this function, it revealed that params.operationKind is a child of "default". This is what it should look like according to the console.log => query.default.params.operationKind. But that's not how it's being called in the recoil-relay package (query.params.operationKind).

Fix: image

My log of query: image

raelBernardino commented 1 year ago

I'd like some confirmation from any contributors to recoil-relay to confirm that this is a valid fix/patch to the issue.

raelBernardino commented 1 year ago

Alternatively I left the node_modules alone and passed in the query field for the graphQLSelector like this: image

drarmstr commented 1 year ago

Actually, someone else has this issue with this fix: https://github.com/facebookexperimental/Recoil/issues/1998#issuecomment-1275625029

So, might be related to how default exports are being built.

Still, this seems like a common issue, so might be reasonable for a workaround that optionally checks for default as a fallback....