naystack - v1.9.9
    Preparing search index...

    Function useAuthQuery

    • Hook to run a GraphQL query as the current user. Requests are sent with credentials: "include", so the server identifies the user from the refresh cookie (the Authorization header is deliberately not added on this path). The query auto-fires whenever variables is set and changes. Returns a refetch function and the Apollo query result.

      Defaults to fetchPolicy: "no-cache" (always fresh, safe for viewer-keyed data). Override per-query via options — e.g. { fetchPolicy: "cache-first" } for static reference data, or { fetchPolicy: "cache-and-network" } to show cached data instantly while refetching.

      Parameters

      • query: TypedDocumentNode<T, V>

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

      • Optionalvariables: V["input"]

        Optional initial variables (the input value). Automatically wrapped as { input: variables } before sending. The query fires when this is set and again whenever it changes (compared by value); omit it for a manually triggered query.

      • Optionaloptions: LazyQueryHookOptions<T, V>

        Optional Apollo LazyQueryHookOptions (e.g. fetchPolicy, notifyOnNetworkStatusChange). Merged into the underlying useLazyQuery.

      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 (wrapped as variables.input).
      • result — { data, loading, error, ... } from Apollo's useLazyQuery.
      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