···11+---
22+'@urql/exchange-graphcache': patch
33+---
44+55+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
···268268 expect(console.error).not.toHaveBeenCalled();
269269 });
270270271271+ it('should not allow subsequent reads when first result was null (with resolvers)', () => {
272272+ const QUERY_WRITE = gql`
273273+ query writeTodos {
274274+ __typename
275275+ todos {
276276+ __typename
277277+ ...ValidRead
278278+ }
279279+ }
280280+281281+ fragment ValidRead on Todo {
282282+ id
283283+ }
284284+ `;
285285+286286+ const QUERY_READ = gql`
287287+ query getTodos {
288288+ __typename
289289+ todos {
290290+ __typename
291291+ ...MissingRead
292292+ }
293293+ todos {
294294+ __typename
295295+ id
296296+ }
297297+ }
298298+299299+ fragment MissingRead on Todo {
300300+ id
301301+ text
302302+ }
303303+ `;
304304+305305+ const store = new Store({
306306+ schema,
307307+ resolvers: {
308308+ Query: {
309309+ todos: (_parent, _args, cache) => cache.resolve('Query', 'todos'),
310310+ },
311311+ },
312312+ });
313313+314314+ let { data } = query(store, { query: QUERY_READ });
315315+ expect(data).toEqual(null);
316316+317317+ write(
318318+ store,
319319+ { query: QUERY_WRITE },
320320+ {
321321+ todos: [
322322+ {
323323+ __typename: 'Todo',
324324+ id: '0',
325325+ },
326326+ ],
327327+ __typename: 'Query',
328328+ }
329329+ );
330330+331331+ ({ data } = query(store, { query: QUERY_READ }));
332332+ expect(data).toEqual({
333333+ __typename: 'Query',
334334+ todos: [null],
335335+ });
336336+337337+ expect(console.warn).not.toHaveBeenCalled();
338338+ expect(console.error).not.toHaveBeenCalled();
339339+ });
340340+271341 it('should not mix references', () => {
272342 const QUERY_WRITE = gql`
273343 query writeTodos {
+1-1
exchanges/graphcache/src/operations/query.ts
···609609 return hasChanged ? data : prevData;
610610 } else if (result === null || result === undefined) {
611611 return result;
612612- } else if (!isOwnedData && prevData === null) {
612612+ } else if (isOwnedData && prevData === null) {
613613 return null;
614614 } else if (isDataOrKey(result)) {
615615 const data = (prevData || InMemoryData.makeData(prevData)) as Data;