Skip to content

Commit

Permalink
refactor(core): Refactor hasNext/stale on OperationResult to be requi…
Browse files Browse the repository at this point in the history
…red (#3061)
  • Loading branch information
kitten authored Mar 16, 2023
1 parent 7222ee1 commit 2fc9842
Show file tree
Hide file tree
Showing 23 changed files with 266 additions and 56 deletions.
7 changes: 7 additions & 0 deletions .changeset/four-boxes-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@urql/exchange-graphcache': major
'@urql/svelte': major
'@urql/core': major
---

Update `OperationResult.hasNext` and `OperationResult.stale` to be required fields. If you have a custom exchange creating results, you'll have to add these fields or use the `makeResult`, `mergeResultPatch`, or `makeErrorResult` helpers.
9 changes: 7 additions & 2 deletions exchanges/auth/src/authExchange.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ import {

import { vi, expect, it } from 'vitest';
import { print } from 'graphql';
import { queryOperation } from '../../../packages/core/src/test-utils';
import {
queryResponse,
queryOperation,
} from '../../../packages/core/src/test-utils';
import { authExchange } from './authExchange';

const makeExchangeArgs = () => {
const operations: Operation[] = [];
const result = vi.fn(
(operation: Operation): OperationResult => ({ operation })
(operation: Operation): OperationResult => ({ ...queryResponse, operation })
);

return {
Expand Down Expand Up @@ -247,7 +250,9 @@ it('triggers authentication when an operation did error', async () => {
await new Promise(resolve => setTimeout(resolve));

result.mockReturnValueOnce({
...queryResponse,
operation: queryOperation,
data: undefined,
error: new CombinedError({
graphQLErrors: [{ message: 'Oops' }],
}),
Expand Down
3 changes: 3 additions & 0 deletions exchanges/context/src/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ExchangeIO,
} from '@urql/core';

import { queryResponse } from '../../../packages/core/src/test-utils';
import { contextExchange } from './context';

const queryOne = gql`
Expand Down Expand Up @@ -48,6 +49,7 @@ it(`calls getContext`, () => {
const response = vi.fn(
(forwardOp: Operation): OperationResult => {
return {
...queryResponse,
operation: forwardOp,
data: queryOneData,
};
Expand Down Expand Up @@ -83,6 +85,7 @@ it(`calls getContext async`, async () => {
const response = vi.fn(
(forwardOp: Operation): OperationResult => {
return {
...queryResponse,
operation: forwardOp,
data: queryOneData,
};
Expand Down
1 change: 1 addition & 0 deletions exchanges/execute/src/execute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ describe('on success response', () => {
operation: queryOperation,
data: mockHttpResponseData,
hasNext: false,
stale: false,
});
});
});
Expand Down
Loading

0 comments on commit 2fc9842

Please sign in to comment.