Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(graphcache): Fix typo in owned data null resolution for resolvers (#3371)

authored by

Phil Pluckthun and committed by
GitHub
022c7d22 cc9586ff

+76 -1
+5
.changeset/real-ducks-speak.md
··· 1 + --- 2 + '@urql/exchange-graphcache': patch 3 + --- 4 + 5 + Fix a typo that caused an inverted condition, for checking owned data, to cause incorrect results when handling `null` values and encountering them first.
+70
exchanges/graphcache/src/operations/query.test.ts
··· 268 268 expect(console.error).not.toHaveBeenCalled(); 269 269 }); 270 270 271 + it('should not allow subsequent reads when first result was null (with resolvers)', () => { 272 + const QUERY_WRITE = gql` 273 + query writeTodos { 274 + __typename 275 + todos { 276 + __typename 277 + ...ValidRead 278 + } 279 + } 280 + 281 + fragment ValidRead on Todo { 282 + id 283 + } 284 + `; 285 + 286 + const QUERY_READ = gql` 287 + query getTodos { 288 + __typename 289 + todos { 290 + __typename 291 + ...MissingRead 292 + } 293 + todos { 294 + __typename 295 + id 296 + } 297 + } 298 + 299 + fragment MissingRead on Todo { 300 + id 301 + text 302 + } 303 + `; 304 + 305 + const store = new Store({ 306 + schema, 307 + resolvers: { 308 + Query: { 309 + todos: (_parent, _args, cache) => cache.resolve('Query', 'todos'), 310 + }, 311 + }, 312 + }); 313 + 314 + let { data } = query(store, { query: QUERY_READ }); 315 + expect(data).toEqual(null); 316 + 317 + write( 318 + store, 319 + { query: QUERY_WRITE }, 320 + { 321 + todos: [ 322 + { 323 + __typename: 'Todo', 324 + id: '0', 325 + }, 326 + ], 327 + __typename: 'Query', 328 + } 329 + ); 330 + 331 + ({ data } = query(store, { query: QUERY_READ })); 332 + expect(data).toEqual({ 333 + __typename: 'Query', 334 + todos: [null], 335 + }); 336 + 337 + expect(console.warn).not.toHaveBeenCalled(); 338 + expect(console.error).not.toHaveBeenCalled(); 339 + }); 340 + 271 341 it('should not mix references', () => { 272 342 const QUERY_WRITE = gql` 273 343 query writeTodos {
+1 -1
exchanges/graphcache/src/operations/query.ts
··· 609 609 return hasChanged ? data : prevData; 610 610 } else if (result === null || result === undefined) { 611 611 return result; 612 - } else if (!isOwnedData && prevData === null) { 612 + } else if (isOwnedData && prevData === null) { 613 613 return null; 614 614 } else if (isDataOrKey(result)) { 615 615 const data = (prevData || InMemoryData.makeData(prevData)) as Data;