naystack - v1.5.10
    Preparing search index...

    Function query

    • Runs a raw GraphQL query on the server using the registered Apollo client. Cookies are forwarded automatically so the backend can identify the user.

      Use this in Server Components, Server Actions, or route handlers when you need to run a query against the GraphQL endpoint (rather than calling a resolver directly with .call()/.authCall()).

      Supports Next.js ISR via revalidate and on-demand revalidation via tags.

      Parameters

      • _query: TypedDocumentNode<T, V>

        A TypedDocumentNode (e.g. from codegen) defining the query and its result type.

      • Optionaloptions: { noCookie?: boolean; revalidate?: number; tags?: string[]; variables?: V }

        Optional query options.

        • OptionalnoCookie?: boolean

          If true, the request is sent without cookies (unauthenticated).

        • Optionalrevalidate?: number

          Next.js revalidate in seconds; when set, enables caching with this TTL.

        • Optionaltags?: string[]

          Next.js cache tags for on-demand revalidation.

        • Optionalvariables?: V

          Variables object for the query (must match the document's variable types).

      Returns Promise<T>

      Promise resolving to the query result data (typed by the document).

      import { query } from "naystack/graphql/server";
      import { GetUserDocument } from "@/generated/graphql";

      // In a Server Component:
      const data = await query(GetUserDocument, {
      variables: { id: userId },
      revalidate: 60, // Cache for 60s (Next.js ISR)
      tags: ["user"], // For on-demand revalidation
      });
      return <Profile user={data.user} />;