- { errorMessages ?
: null}
-
+
+
+ {errorMessages ?
: null}
+ {successMessages ?
: null}
+
+
);
}
diff --git a/packages/ui/src/utils/operation.ts b/packages/ui/src/utils/operation.ts
index e4c0460b0..2d442ead4 100644
--- a/packages/ui/src/utils/operation.ts
+++ b/packages/ui/src/utils/operation.ts
@@ -7,18 +7,15 @@ import {
import useSwr, { SWRResponse } from 'swr';
import useSWRMutation, { SWRMutationResponse } from 'swr/mutation';
-function swrFetcher
(
- operationMetadata: {
- operation: TOperation,
- variables?: OperationVariables,
- },
-) {
- const executor = createExecutor(operationMetadata.operation, {
+function swrFetcher(operationMetadata: {
+ operation: string;
+ variables?: OperationVariables;
+}) {
+ const executor = createExecutor(operationMetadata.operation as TOperation, {
variables: operationMetadata.variables,
});
- if (typeof executor === 'function') {
- // @todo: fix this.
- // @ts-ignore
+
+ if (executor instanceof Function) {
return executor();
}
// If the executor is not a function, then just return it. This means the
@@ -27,18 +24,14 @@ function swrFetcher(
}
function swrMutator(
- operationMetadata: {
- operation: TOperation,
- },
+ operation: string,
args?: OperationVariables,
) {
- const executor = createExecutor(operationMetadata.operation, {
+ const executor = createExecutor(operation as TOperation, {
graphqlOperationType: 'mutation',
variables: args?.arg,
});
- if (typeof executor === 'function') {
- // @todo: fix this.
- // @ts-ignore
+ if (executor instanceof Function) {
return executor();
}
return executor;
@@ -49,7 +42,7 @@ export function useOperation(
variables?: OperationVariables,
): SWRResponse> {
return useSwr>(
- {operation, variables},
+ { operation, variables },
swrFetcher,
{
suspense: false,
@@ -59,11 +52,16 @@ export function useOperation(
export function useMutation(
operation: TOperation,
-): SWRMutationResponse> {
- return useSWRMutation>(
- {operation},
- // @todo: fix this.
- // @ts-ignore
- swrMutator,
- );
+): SWRMutationResponse<
+ OperationResult,
+ string,
+ string,
+ OperationVariables
+> {
+ return useSWRMutation<
+ OperationResult,
+ string,
+ string,
+ OperationVariables
+ >(operation, swrMutator);
}
diff --git a/tests/schema/specs/contact.spec.ts b/tests/schema/specs/contact.spec.ts
index b207a5e85..4d4a91c30 100644
--- a/tests/schema/specs/contact.spec.ts
+++ b/tests/schema/specs/contact.spec.ts
@@ -1,13 +1,20 @@
import gql from 'noop-tag';
-import { describe, expect, it } from "vitest";
+import { describe, expect, it } from 'vitest';
import { fetch } from '../lib.js';
describe('create contact', () => {
- it ('creates a new contact using a graphql mutation', async () => {
+ it('creates a new contact using a graphql mutation', async () => {
const result = await fetch(gql`
mutation {
- createContact(contact: {name: "John Doe", email: "john@doe.com", message: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. In pretium aliquam magna.", subject: "Lorem ipsum"}) {
+ createContact(
+ contact: {
+ name: "John Doe"
+ email: "john@doe.com"
+ message: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. In pretium aliquam magna."
+ subject: "Lorem ipsum"
+ }
+ ) {
errors {
key
field
@@ -36,13 +43,20 @@ describe('create contact', () => {
},
},
}
- `)
- })
+ `);
+ });
- it ('tries to create a new contact with an invalid e-mail address', async() => {
+ it('tries to create a new contact with an invalid e-mail address', async () => {
const result = await fetch(gql`
mutation {
- createContact(contact: {name: "Jane", email: "invalid_email", message: "Test message.", subject: "Test subject"}) {
+ createContact(
+ contact: {
+ name: "Jane"
+ email: "invalid_email"
+ message: "Test message."
+ subject: "Test subject"
+ }
+ ) {
errors {
key
field
@@ -57,7 +71,7 @@ describe('create contact', () => {
}
}
`);
- expect(result).toMatchInlineSnapshot(`
+ expect(result).toMatchInlineSnapshot(`
{
"data": {
"createContact": {
@@ -72,6 +86,6 @@ describe('create contact', () => {
},
},
}
- `)
+ `);
});
});