naystack - v1.5.10
    Preparing search index...

    Function useAuthMutation

    • 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.input to the GraphQL endpoint.

      Parameters

      • mutation: TypedDocumentNode<T, V>

        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).

      Returns readonly [(input: V["input"]) => Promise<FetchResult<T>>, MutationResult<T>]

      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>;
      }