{"id":40576,"library":"apollo-server-nextjs","title":"apollo-server-nextjs","description":"A lightweight Apollo Server integration for Next.js API routes. Current version 3.10.3 supports Node >=12, GraphQL 15/16, and Next.js 12+. Provides a simple `ApolloServerNext` class that plugs into Next.js pages/api handlers, handling CORS, body parsing, and error formatting. Unlike `apollo-server-micro` or standalone solutions, it's optimized for Next.js's serverless environment. Ships TypeScript types.","status":"active","version":"3.10.3","language":"javascript","source_language":"en","source_url":"https://github.com/apuyou/apollo-server-nextjs","tags":["javascript","GraphQL","Apollo","Server","Lambda","Javascript","Next.js","typescript"],"install":[{"cmd":"npm install apollo-server-nextjs","lang":"bash","label":"npm"},{"cmd":"yarn add apollo-server-nextjs","lang":"bash","label":"yarn"},{"cmd":"pnpm add apollo-server-nextjs","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency for GraphQL execution","package":"graphql","optional":false},{"reason":"peer dependency for Next.js API routes","package":"next","optional":false}],"imports":[{"note":"Named export only; not default exported.","wrong":"import ApolloServerNext from 'apollo-server-nextjs'","symbol":"ApolloServerNext","correct":"import { ApolloServerNext } from 'apollo-server-nextjs'"},{"note":"ESM-only; CommonJS require will fail.","wrong":"const { startServerAndCreateNextHandler } = require('apollo-server-nextjs')","symbol":"startServerAndCreateNextHandler","correct":"import { startServerAndCreateNextHandler } from 'apollo-server-nextjs'"},{"note":"Type import for config object if using TypeScript.","wrong":null,"symbol":"ApolloServerNextConfig","correct":"import type { ApolloServerNextConfig } from 'apollo-server-nextjs'"}],"quickstart":{"code":"import { ApolloServerNext, startServerAndCreateNextHandler } from 'apollo-server-nextjs';\nimport { NextApiRequest, NextApiResponse } from 'next';\n\nconst typeDefs = `#graphql\n  type Query {\n    hello: String\n  }\n`;\n\nconst resolvers = {\n  Query: {\n    hello: () => 'Hello world!',\n  },\n};\n\nconst server = new ApolloServerNext({\n  typeDefs,\n  resolvers,\n});\n\nexport default startServerAndCreateNextHandler(server);\n\n// Optional config: export const config = { api: { bodyParser: false } };","lang":"typescript","description":"Creates a minimal GraphQL API endpoint in a Next.js API route using ApolloServerNext and the handler helper."},"warnings":[{"fix":"Upgrade to Next.js >=12 and GraphQL >=15.","message":"Version 3.x drops support for Next.js <12 and GraphQL <15.","severity":"breaking","affected_versions":"<3.0.0"},{"fix":"Add `export const config = { api: { bodyParser: false } };` in the API route file.","message":"The handler assumes body parsing is disabled; you must set `bodyParser: false` in Next.js config if using built-in body parsing.","severity":"gotcha","affected_versions":">=3.0.0"},{"fix":"Use a custom `context` function to set CORS headers or wrap handler with a CORS middleware.","message":"CORS headers are not set by default; you must configure them via `context` or middleware.","severity":"gotcha","affected_versions":"all"},{"fix":"Use `startServerAndCreateNextHandler(server)` instead.","message":"The old `ApolloServerNextHandler` pattern from v2 is removed.","severity":"deprecated","affected_versions":"<3.0.0"},{"fix":"Set `formatError` in ApolloServerNext config to avoid exposing stack traces.","message":"Error formatting default includes stack traces in production if not overridden.","severity":"gotcha","affected_versions":">=3.0.0"}],"env_vars":null,"search_vec":"'12':19,24 '15/16':21 '3.10.3':16 'api':12 'apollo':2,7,45,64 'apollo-server-micro':44 'apollo-server-nextj':1 'apolloservernext':28 'bodi':38 'class':29 'cor':37 'current':14 'environ':58 'error':41 'format':42 'graphql':20,63 'handl':36 'handler':35 'integr':9 'javascript':62,67 'lambda':66 'lightweight':6 'micro':47 'next.js':11,23,33,55,68 'nextj':4 'node':18 'optim':53 'pages/api':34 'pars':39 'plug':31 'provid':25 'rout':13 'server':3,8,46,65 'serverless':57 'ship':59 'simpl':27 'solut':50 'standalon':49 'support':17 'type':61 'typescript':60,69 'unlik':43 'version':15","created_at":"2026-06-04T18:48:14.143713+00:00","updated_at":"2026-06-04T18:48:14.143713+00:00","problems":[{"fix":"Use `context: async ({ req, res }) => ({ req, res })`.","cause":"The `context` function receives `{ req, res }` but destructuring incorrectly.","error":"TypeError: Cannot destructure property 'req' of 'ctx' as it is undefined."},{"fix":"Use `import { ApolloServerNext } from 'apollo-server-nextjs'` and configure your project for ESM.","cause":"Using CommonJS `require` instead of ESM import.","error":"ApolloServerNext is not a constructor"},{"fix":"Export `startServerAndCreateNextHandler(server)` directly; do not wrap in another function.","cause":"Forgetting to return the handler or misusing `res.json()`.","error":"Response is not a function"},{"fix":"Ensure `typeDefs` includes a `type Query { ... }` definition.","cause":"Missing `typeDefs` or empty schema.","error":"GraphQLError: Query root type must be provided."}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/apuyou/apollo-server-nextjs#readme","github":"https://github.com/apuyou/apollo-server-nextjs","docs":null,"changelog":null,"pypi":null,"npm":"apollo-server-nextjs","openapi_spec":null,"status_page":null,"smithery":null,"categories":["api","serverless"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-04","next_check":"2026-09-02","install_tag":null}}