urql-graphql / urql

The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
https://urql.dev/goto/docs
MIT License
8.57k stars 445 forks source link

null data has been returned after fetch done with valid data when using nested local resolver #3370

Closed jet2jet closed 11 months ago

jet2jet commented 11 months ago

Describe the bug

When using nested local resolver (resolver not under root Query), returned data may be null even though data has been fetched correctly.

If I changed the line below:

https://github.com/urql-graphql/urql/blob/%40urql/exchange-graphcache%406.3.2/exchanges/graphcache/src/operations/query.ts#L612

-  } else if (!isOwnedData && prevData === null) {
+  } else if (isOwnedData && prevData === null) {

... it seems to work correctly.
# I saw that in commit 6031d913732f5e480cdbc2e3c2c537dc7e5d6d42 skipNull was changed to isOwnedData, but in the only above line ! was added.

Reproduction

https://github.com/jet2jet/urql-local-resolver-test

  1. Run npm run start
  2. Open http://localhost:3000
  3. When Todo list is displayed, type Todo id to ID field and press Get
  4. Expect behavior: Todo detail data is retrieved and displayed
  5. Actual behavior: Todo is null... is displayed

Urql version

urql v4.0.5 @urql/exchange-graphcache v6.3.2

Validations

kitten commented 11 months ago

That's a really nice catch and a great diagnosis! I've confirmed that the line you mentioned contains a typo (which is more easily spotted when comparing it to resolveLink) and wrote a quick unit test next to the one that checks that resolveLink behaves correctly, to prevent this from regressing again. Cheers! ❤️