A TypedDocumentNode for the mutation (e.g. from codegen or a gql template).
Optionaloptions: MutationHookOptions<T, V, DefaultContext, ApolloCache<any>>Optional Apollo MutationHookOptions (e.g. onCompleted, onError, refetchQueries).
Tuple: [mutate, result].
mutate(input) — runs the mutation with the given input. Returns a Promise with { data }.result — { data, loading, error } from Apollo.import { useAuthMutation } from "naystack/graphql/client";
import { CREATE_DEAL } from "@/lib/gql/mutations";
function CreateDealModal({ propertyId }: { propertyId: number }) {
const [createDeal, { loading }] = useAuthMutation(CREATE_DEAL);
const onSubmit = async (values: FormFields) => {
const response = await createDeal({
propertyId,
share: Number(values.share),
targetProfit: Number(values.targetProfit),
});
const dealId = response.data?.createDeal;
if (dealId) router.push(`/deals/${dealId}`);
};
return <form onSubmit={handleSubmit(onSubmit)}>...</form>;
}
Hook to run a GraphQL mutation with the current user's token. Returns a function you call with the mutation input.
The input is sent as
variables.inputto the GraphQL endpoint.