Configuration object.
OptionalauthChecker?: AuthChecker<any>Optional custom type-graphql AuthChecker. Default: authorized if context.userId is truthy.
OptionalgetContext?: (req: NextRequest) => anyOptional 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).
Array of type-graphql resolver classes (from QueryLibrary / FieldLibrary). Required.
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],
});
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 returnedGETandPOST.Uses
type-graphqlto build the schema from the resolver classes you provide (created withQueryLibraryandFieldLibrary). The defaultauthCheckerauthorizes requests wherecontext.userIdis truthy. The defaultgetContextreads theAuthorization: Bearerheader 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.