naystack - v1.5.10
    Preparing search index...

    Function initGraphQLServer

    • Builds the Apollo GraphQL server and Next.js GET/POST route handlers. Call this at the top level of your GraphQL route file (e.g. app/api/(graphql)/route.ts) and export the returned GET and POST.

      Uses type-graphql to build the schema from the resolver classes you provide (created with QueryLibrary and FieldLibrary). The default authChecker authorizes requests where context.userId is truthy. The default getContext reads the Authorization: Bearer header or the refresh cookie — pass a custom one to override.

      In production (NODE_ENV=production), introspection is disabled and the Apollo production landing page is shown. In development, the Apollo Sandbox is available.

      Parameters

      • options: {
            authChecker?: AuthChecker<any>;
            getContext?: (req: NextRequest) => any;
            plugins?: ApolloServerPlugin<BaseContext>[];
            resolvers: NonEmptyArray<Function>;
        }

        Configuration object.

        • OptionalauthChecker?: AuthChecker<any>

          Optional custom type-graphql AuthChecker. Default: authorized if context.userId is truthy.

        • OptionalgetContext?: (req: NextRequest) => any

          Optional function to build context from the request. Default: reads Bearer token or refresh cookie. Signature: (req: NextRequest) => Promise<Context> | Context. Must return at least { userId: number | null }.

        • Optionalplugins?: ApolloServerPlugin<BaseContext>[]

          Optional Apollo Server plugins (e.g. logging, tracing, caching).

        • resolvers: NonEmptyArray<Function>

          Array of type-graphql resolver classes (from QueryLibrary / FieldLibrary). Required.

      Returns Promise<
          {
              GET: (request: NextRequest) => Promise<Response>;
              POST: (request: NextRequest) => Promise<Response>;
          },
      >

      Promise of { GET, POST } — export these as your route's handlers.

      // app/api/(graphql)/route.ts
      import { initGraphQLServer } from "naystack/graphql";
      import { UserResolvers, UserFieldResolvers } from "./User/graphql";
      import { ChatResolvers } from "./Chat/graphql";

      export const { GET, POST } = await initGraphQLServer({
      resolvers: [UserResolvers, UserFieldResolvers, ChatResolvers],
      });