Skip to content

Commit ebbf640

Browse files
committed
fixup
1 parent 16ee78f commit ebbf640

File tree

5 files changed

+11
-312
lines changed

5 files changed

+11
-312
lines changed

.size-limits.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (CJS)": 41903,
3-
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production) (CJS)": 41423,
4-
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\"": 32087,
5-
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production)": 31494
2+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (CJS)": 44114,
3+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production) (CJS)": 39603,
4+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\"": 34137,
5+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production)": 29489
66
}

config/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
"verbatimModuleSyntax": true,
1111
"resolveJsonModule": true
1212
},
13-
"include": ["./**/*.ts", "./**/*.cts"]
13+
"include": ["./**/*.ts", "./**/*.cts", "./**/*.cjs"]
1414
}

src/react/hooks/__tests__/useQuery.test.tsx

Lines changed: 0 additions & 305 deletions
Original file line numberDiff line numberDiff line change
@@ -3612,136 +3612,6 @@ describe("useQuery Hook", () => {
36123612
await expect(takeSnapshot).not.toRerender();
36133613
});
36143614

3615-
it('calls `onCompleted` with partial data but avoids calling `onError` when using an `errorPolicy` set to "ignore"', async () => {
3616-
const query = gql`
3617-
{
3618-
hello
3619-
}
3620-
`;
3621-
const mocks = [
3622-
{
3623-
request: { query },
3624-
result: {
3625-
data: { hello: null },
3626-
errors: [new GraphQLError('Could not fetch "hello"')],
3627-
},
3628-
},
3629-
];
3630-
3631-
const cache = new InMemoryCache();
3632-
const wrapper = ({ children }: any) => (
3633-
<MockedProvider mocks={mocks} cache={cache}>
3634-
{children}
3635-
</MockedProvider>
3636-
);
3637-
3638-
const onError = jest.fn();
3639-
const onCompleted = jest.fn();
3640-
using _disabledAct = disableActEnvironment();
3641-
const { takeSnapshot } = await renderHookToSnapshotStream(
3642-
() => useQuery(query, { onError, onCompleted, errorPolicy: "ignore" }),
3643-
{ wrapper }
3644-
);
3645-
3646-
{
3647-
const result = await takeSnapshot();
3648-
3649-
expect(result).toEqualQueryResult({
3650-
data: undefined,
3651-
called: true,
3652-
loading: true,
3653-
networkStatus: NetworkStatus.loading,
3654-
previousData: undefined,
3655-
variables: {},
3656-
});
3657-
}
3658-
3659-
{
3660-
const result = await takeSnapshot();
3661-
3662-
expect(result).toEqualQueryResult({
3663-
data: { hello: null },
3664-
called: true,
3665-
loading: false,
3666-
networkStatus: NetworkStatus.ready,
3667-
previousData: undefined,
3668-
variables: {},
3669-
});
3670-
}
3671-
3672-
expect(onCompleted).toHaveBeenCalledTimes(1);
3673-
expect(onCompleted).toHaveBeenCalledWith({ hello: null });
3674-
expect(onError).not.toHaveBeenCalled();
3675-
3676-
await expect(takeSnapshot).not.toRerender();
3677-
});
3678-
3679-
it('calls `onError` when returning GraphQL errors while using an `errorPolicy` set to "all"', async () => {
3680-
const query = gql`
3681-
{
3682-
hello
3683-
}
3684-
`;
3685-
const mocks = [
3686-
{
3687-
request: { query },
3688-
result: {
3689-
errors: [new GraphQLError("error")],
3690-
},
3691-
},
3692-
];
3693-
3694-
const cache = new InMemoryCache();
3695-
const wrapper = ({ children }: any) => (
3696-
<MockedProvider mocks={mocks} cache={cache}>
3697-
{children}
3698-
</MockedProvider>
3699-
);
3700-
3701-
const onError = jest.fn();
3702-
using _disabledAct = disableActEnvironment();
3703-
const { takeSnapshot } = await renderHookToSnapshotStream(
3704-
() => useQuery(query, { onError, errorPolicy: "all" }),
3705-
{ wrapper }
3706-
);
3707-
3708-
{
3709-
const result = await takeSnapshot();
3710-
3711-
expect(result).toEqualQueryResult({
3712-
data: undefined,
3713-
called: true,
3714-
loading: true,
3715-
networkStatus: NetworkStatus.loading,
3716-
previousData: undefined,
3717-
variables: {},
3718-
});
3719-
}
3720-
3721-
{
3722-
const result = await takeSnapshot();
3723-
3724-
expect(result).toEqualQueryResult({
3725-
data: undefined,
3726-
error: new ApolloError({ graphQLErrors: [{ message: "error" }] }),
3727-
// TODO: Why does this only populate when errorPolicy is "all"?
3728-
errors: [{ message: "error" }],
3729-
called: true,
3730-
loading: false,
3731-
networkStatus: NetworkStatus.error,
3732-
previousData: undefined,
3733-
variables: {},
3734-
});
3735-
}
3736-
3737-
expect(onError).toHaveBeenCalledTimes(1);
3738-
expect(onError).toHaveBeenCalledWith(
3739-
new ApolloError({ graphQLErrors: [new GraphQLError("error")] })
3740-
);
3741-
3742-
await expect(takeSnapshot).not.toRerender();
3743-
});
3744-
37453615
it('returns partial data when returning GraphQL errors while using an `errorPolicy` set to "all"', async () => {
37463616
const query = gql`
37473617
{
@@ -3804,181 +3674,6 @@ describe("useQuery Hook", () => {
38043674
await expect(takeSnapshot).not.toRerender();
38053675
});
38063676

3807-
it('calls `onError` but not `onCompleted` when returning partial data with GraphQL errors while using an `errorPolicy` set to "all"', async () => {
3808-
const query = gql`
3809-
{
3810-
hello
3811-
}
3812-
`;
3813-
const mocks = [
3814-
{
3815-
request: { query },
3816-
result: {
3817-
data: { hello: null },
3818-
errors: [new GraphQLError('Could not fetch "hello"')],
3819-
},
3820-
},
3821-
];
3822-
3823-
const cache = new InMemoryCache();
3824-
const wrapper = ({ children }: any) => (
3825-
<MockedProvider mocks={mocks} cache={cache}>
3826-
{children}
3827-
</MockedProvider>
3828-
);
3829-
3830-
const onError = jest.fn();
3831-
const onCompleted = jest.fn();
3832-
using _disabledAct = disableActEnvironment();
3833-
const { takeSnapshot } = await renderHookToSnapshotStream(
3834-
() => useQuery(query, { onError, onCompleted, errorPolicy: "all" }),
3835-
{ wrapper }
3836-
);
3837-
3838-
{
3839-
const result = await takeSnapshot();
3840-
3841-
expect(result).toEqualQueryResult({
3842-
data: undefined,
3843-
called: true,
3844-
loading: true,
3845-
networkStatus: NetworkStatus.loading,
3846-
previousData: undefined,
3847-
variables: {},
3848-
});
3849-
}
3850-
3851-
{
3852-
const result = await takeSnapshot();
3853-
3854-
expect(result).toEqualQueryResult({
3855-
data: { hello: null },
3856-
error: new ApolloError({
3857-
graphQLErrors: [{ message: 'Could not fetch "hello"' }],
3858-
}),
3859-
errors: [{ message: 'Could not fetch "hello"' }],
3860-
called: true,
3861-
loading: false,
3862-
networkStatus: NetworkStatus.error,
3863-
previousData: undefined,
3864-
variables: {},
3865-
});
3866-
}
3867-
3868-
expect(onError).toHaveBeenCalledTimes(1);
3869-
expect(onError).toHaveBeenCalledWith(
3870-
new ApolloError({
3871-
graphQLErrors: [new GraphQLError('Could not fetch "hello"')],
3872-
})
3873-
);
3874-
expect(onCompleted).not.toHaveBeenCalled();
3875-
3876-
await expect(takeSnapshot).not.toRerender();
3877-
});
3878-
3879-
it("calls `onError` a single time when refetching returns a successful result", async () => {
3880-
const query = gql`
3881-
{
3882-
hello
3883-
}
3884-
`;
3885-
const mocks = [
3886-
{
3887-
request: { query },
3888-
result: {
3889-
errors: [new GraphQLError("error")],
3890-
},
3891-
},
3892-
{
3893-
request: { query },
3894-
result: {
3895-
data: { hello: "world" },
3896-
},
3897-
delay: 10,
3898-
},
3899-
];
3900-
3901-
const cache = new InMemoryCache();
3902-
const wrapper = ({ children }: any) => (
3903-
<MockedProvider mocks={mocks} cache={cache}>
3904-
{children}
3905-
</MockedProvider>
3906-
);
3907-
3908-
const onError = jest.fn();
3909-
using _disabledAct = disableActEnvironment();
3910-
const { takeSnapshot, getCurrentSnapshot } =
3911-
await renderHookToSnapshotStream(
3912-
() =>
3913-
useQuery(query, {
3914-
onError,
3915-
notifyOnNetworkStatusChange: true,
3916-
}),
3917-
{ wrapper }
3918-
);
3919-
3920-
{
3921-
const result = await takeSnapshot();
3922-
3923-
expect(result).toEqualQueryResult({
3924-
data: undefined,
3925-
called: true,
3926-
loading: true,
3927-
networkStatus: NetworkStatus.loading,
3928-
previousData: undefined,
3929-
variables: {},
3930-
});
3931-
}
3932-
3933-
{
3934-
const result = await takeSnapshot();
3935-
3936-
expect(result).toEqualQueryResult({
3937-
data: undefined,
3938-
error: new ApolloError({ graphQLErrors: [{ message: "error" }] }),
3939-
called: true,
3940-
loading: false,
3941-
networkStatus: NetworkStatus.error,
3942-
previousData: undefined,
3943-
variables: {},
3944-
});
3945-
}
3946-
3947-
expect(onError).toHaveBeenCalledTimes(1);
3948-
3949-
void getCurrentSnapshot().refetch();
3950-
3951-
{
3952-
const result = await takeSnapshot();
3953-
3954-
expect(result).toEqualQueryResult({
3955-
data: undefined,
3956-
called: true,
3957-
loading: true,
3958-
networkStatus: NetworkStatus.refetch,
3959-
previousData: undefined,
3960-
variables: {},
3961-
});
3962-
}
3963-
3964-
{
3965-
const result = await takeSnapshot();
3966-
3967-
expect(result).toEqualQueryResult({
3968-
data: { hello: "world" },
3969-
called: true,
3970-
loading: false,
3971-
networkStatus: NetworkStatus.ready,
3972-
previousData: undefined,
3973-
variables: {},
3974-
});
3975-
}
3976-
3977-
expect(onError).toHaveBeenCalledTimes(1);
3978-
3979-
await expect(takeSnapshot).not.toRerender();
3980-
});
3981-
39823677
it("should persist errors on re-render if they are still valid", async () => {
39833678
const query = gql`
39843679
{

src/testing/core/mocking/__tests__/mockLink.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { gql } from "graphql-tag";
22

33
import { execute } from "../../../../link/core/execute.js";
4-
import { enableFakeTimers, ObservableStream, spyOnConsole } from "../../../internal/index.js";
4+
import {
5+
enableFakeTimers,
6+
ObservableStream,
7+
spyOnConsole,
8+
} from "../../../internal/index.js";
59
import { MockedResponse, MockLink } from "../mockLink.js";
610

711
describe("MockedResponse.newData", () => {

src/testing/core/mocking/mockLink.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ export function mockSingleLink(
267267
// support for NaN in addition to undefined. More values may be handled in the
268268
// future. This is not added to the primary stringifyForDisplay helper since it
269269
// is used for the cache and other purposes. We need this for debuggging only.
270-
export function stringifyForDebugging(value: any, space = 0): string {
270+
function stringifyForDebugging(value: any, space = 0): string {
271271
const undefId = makeUniqueId("undefined");
272272
const nanId = makeUniqueId("NaN");
273273

0 commit comments

Comments
 (0)