naystack - v1.5.10
    Preparing search index...

    Function useAuthQuery

    • Hook to run a GraphQL query with the current user's token. The query auto-fires when both the token and variables are available. Returns a refetch function and the Apollo query result.

      Uses fetchPolicy: "no-cache" by default to always get fresh data.

      Parameters

      • query: TypedDocumentNode<T, V>

        A TypedDocumentNode for the query (e.g. from codegen or a gql template).

      • Optionalvariables: V

        Optional initial variables. Query fires automatically when this and token are set; change to refetch.

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

      Tuple: [refetch, result].

      • refetch(input) — runs the query again with the given input (passed as variables.input).
      • result{ data, loading, error } from Apollo.
      import { useAuthQuery } from "naystack/graphql/client";
      import { GET_SUMMARY } from "@/constants/graphql/queries";

      function SummaryCard({ type }: { type: string }) {
      const [getSummary, { loading, data }] = useAuthQuery(GET_SUMMARY);

      const handleFetch = async () => {
      const result = await getSummary({ type });
      if (result.data?.getSummary) setSummary(result.data.getSummary);
      };

      return <button onClick={handleFetch} disabled={loading}>Get Summary</button>;
      }
      const [refetch, { data, loading }] = useAuthQuery(GET_ORGANIZATION_DETAILS, { id: orgId });
      // Query fires automatically when orgId and token are available