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(core): Fix regression that broke cache-and-network (#3174)

authored by

Phil Pluckthun and committed by
GitHub
6d2e7362 a4d1aa15

+68 -1
+5
.changeset/moody-hats-attend.md
··· 1 + --- 2 + '@urql/core': patch 3 + --- 4 + 5 + Fix regression which would disallow `network-only` operations after `cache-and-network` completed.
+52
packages/core/src/client.test.ts
··· 648 648 expect(onOperation).toHaveBeenCalledTimes(1); 649 649 expect(onResult).toHaveBeenCalledTimes(3); 650 650 }); 651 + 652 + it('does not deduplicate cache-and-network’s follow-up operations', () => { 653 + const onOperation = vi.fn(); 654 + const onResult = vi.fn(); 655 + 656 + const operationOne = makeOperation('query', queryOperation, { 657 + ...queryOperation.context, 658 + requestPolicy: 'cache-and-network', 659 + }); 660 + 661 + const operationTwo = makeOperation('query', queryOperation, { 662 + ...queryOperation.context, 663 + requestPolicy: 'network-only', 664 + }); 665 + 666 + let shouldSend = true; 667 + const exchange: Exchange = () => ops$ => 668 + pipe( 669 + ops$, 670 + onPush(onOperation), 671 + map(op => ({ 672 + hasNext: false, 673 + stale: true, 674 + data: 'test', 675 + operation: op, 676 + })), 677 + filter(() => { 678 + if (shouldSend) { 679 + shouldSend = false; 680 + client.reexecuteOperation(operationTwo); 681 + return true; 682 + } else { 683 + return false; 684 + } 685 + }) 686 + ); 687 + 688 + const client = createClient({ 689 + url: 'test', 690 + exchanges: [exchange], 691 + }); 692 + 693 + const operationThree = makeOperation('query', queryOperation, { 694 + ...queryOperation.context, 695 + requestPolicy: 'network-only', 696 + }); 697 + 698 + pipe(client.executeRequestOperation(operationOne), subscribe(onResult)); 699 + pipe(client.executeRequestOperation(operationThree), subscribe(onResult)); 700 + 701 + expect(onOperation).toHaveBeenCalledTimes(2); 702 + }); 651 703 }); 652 704 653 705 describe('shared sources behavior', () => {
+11 -1
packages/core/src/client.ts
··· 663 663 result$, 664 664 // Store replay result 665 665 onPush(result => { 666 - if (!result.hasNext && !result.stale) 666 + if (result.stale) { 667 + // If the current result has queued up an operation of the same 668 + // key, then `stale` refers to it 669 + for (const operation of queue) { 670 + if (operation.key === result.operation.key) { 671 + dispatched.delete(operation.key); 672 + break; 673 + } 674 + } 675 + } else if (!result.hasNext) { 667 676 dispatched.delete(operation.key); 677 + } 668 678 replays.set(operation.key, result); 669 679 }), 670 680 // Cleanup active states on end of source