Skip to content

Commit 4fd09e7

Browse files
committed
fix(vue): fix variables typing
- Revert the definitions of MaybeRefObj, UseQueryArgs, and UseSubscriptionArgs introduced in d07602d to resolve issue urql-graphql#3733 - Rename MaybeRef, MaybeRefObj, unwrap to MaybeRefOrGetter, MaybeRefOrGetterObj, and toValue for consistency with Vue 3.3+ - Replace deep unwrapping (introduced in 068df71) of variables with a simple toValue - Revert test changes introduced in 068df71 - Fix 'reacts to variables changing' test by wrapping variables in reactive() since deep unwrapping is no longer performed
1 parent 25d114d commit 4fd09e7

File tree

7 files changed

+133
-449
lines changed

7 files changed

+133
-449
lines changed

packages/vue-urql/src/useMutation.test.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { OperationResult, OperationResultSource } from '@urql/core';
2-
import { readonly } from 'vue';
2+
import { reactive } from 'vue';
33
import { vi, expect, it, beforeEach, describe } from 'vitest';
44

55
vi.mock('./useClient.ts', async () => {
@@ -30,13 +30,15 @@ describe('useMutation', () => {
3030
() => subject.source as OperationResultSource<OperationResult>
3131
);
3232

33-
const mutation = useMutation(gql`
34-
mutation {
35-
test
36-
}
37-
`);
33+
const mutation = reactive(
34+
useMutation(gql`
35+
mutation {
36+
test
37+
}
38+
`)
39+
);
3840

39-
expect(readonly(mutation)).toMatchObject({
41+
expect(mutation).toMatchObject({
4042
data: undefined,
4143
stale: false,
4244
fetching: false,
@@ -48,18 +50,18 @@ describe('useMutation', () => {
4850

4951
const promise = mutation.executeMutation({ test: true });
5052

51-
expect(mutation.fetching.value).toBe(true);
52-
expect(mutation.stale.value).toBe(false);
53-
expect(mutation.error.value).toBe(undefined);
53+
expect(mutation.fetching).toBe(true);
54+
expect(mutation.stale).toBe(false);
55+
expect(mutation.error).toBe(undefined);
5456

5557
expect(clientMutation).toHaveBeenCalledTimes(1);
5658

5759
subject.next({ data: { test: true }, stale: false });
58-
59-
await promise;
60-
expect(mutation.fetching.value).toBe(false);
61-
expect(mutation.stale.value).toBe(false);
62-
expect(mutation.error.value).toBe(undefined);
63-
expect(mutation.data.value).toHaveProperty('test', true);
60+
await promise.then(function () {
61+
expect(mutation.fetching).toBe(false);
62+
expect(mutation.stale).toBe(false);
63+
expect(mutation.error).toBe(undefined);
64+
expect(mutation.data).toEqual({ test: true });
65+
});
6466
});
6567
});

packages/vue-urql/src/useMutation.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ import type {
1515
} from '@urql/core';
1616

1717
import { useClient } from './useClient';
18-
import type { MaybeRef } from './utils';
19-
import { createRequestWithArgs, useRequestState } from './utils';
18+
import {
19+
createRequestWithArgs,
20+
type MaybeRefOrGetter,
21+
useRequestState,
22+
} from './utils';
2023

2124
/** State of the last mutation executed by {@link useMutation}.
2225
*
@@ -132,7 +135,7 @@ export function useMutation<T = any, V extends AnyVariables = AnyVariables>(
132135
}
133136

134137
export function callUseMutation<T = any, V extends AnyVariables = AnyVariables>(
135-
query: MaybeRef<DocumentInput<T, V>>,
138+
query: MaybeRefOrGetter<DocumentInput<T, V>>,
136139
client: Ref<Client> = useClient()
137140
): UseMutationResponse<T, V> {
138141
const data: Ref<T | undefined> = shallowRef();
@@ -156,7 +159,7 @@ export function callUseMutation<T = any, V extends AnyVariables = AnyVariables>(
156159

157160
return pipe(
158161
client.value.executeMutation<T, V>(
159-
createRequestWithArgs({ query, variables }),
162+
createRequestWithArgs<T, V>({ query, variables }),
160163
context || {}
161164
),
162165
onPush(result => {

0 commit comments

Comments
 (0)