{"id":"b1f38efa-2792-45d8-a97f-d59ccd264904","shortId":"TWgREh","kind":"skill","title":"apollo-server","tagline":"Guide for building GraphQL servers with Apollo Server 5.x. Use this skill when: (1) setting up a new Apollo Server project, (2) writing resolvers or defining GraphQL schemas, (3) implementing authentication or authorization, (4) creating plugins or custom data sources, (5) troubl","description":"# Apollo Server 5.x Guide\n\nApollo Server is an open-source GraphQL server that works with any GraphQL schema. Apollo Server 5 is framework-agnostic and runs standalone or integrates with Express, Fastify, and serverless environments.\n\n## Quick Start\n\n### Step 1: Install\n\n```bash\nnpm install @apollo/server graphql\n```\n\nFor Express integration:\n\n```bash\nnpm install @apollo/server @as-integrations/express5 express graphql cors\n```\n\n### Step 2: Define Schema\n\n```typescript\nconst typeDefs = `#graphql\n  type Book {\n    title: String\n    author: String\n  }\n\n  type Query {\n    books: [Book]\n  }\n`;\n```\n\n### Step 3: Write Resolvers\n\n```typescript\nconst resolvers = {\n  Query: {\n    books: () => [\n      { title: \"The Great Gatsby\", author: \"F. Scott Fitzgerald\" },\n      { title: \"1984\", author: \"George Orwell\" },\n    ],\n  },\n};\n```\n\n### Step 4: Start Server\n\n**Standalone (Recommended for prototyping):**\n\nThe standalone server is great for prototyping, but for production services, we recommend integrating Apollo Server with a more fully-featured web framework such as Express, Koa, or Fastify. Swapping from the standalone server to a web framework later is straightforward.\n\n```typescript\nimport { ApolloServer } from \"@apollo/server\";\nimport { startStandaloneServer } from \"@apollo/server/standalone\";\n\nconst server = new ApolloServer({ typeDefs, resolvers });\n\nconst { url } = await startStandaloneServer(server, {\n  listen: { port: 4000 },\n});\n\nconsole.log(`Server ready at ${url}`);\n```\n\n**Express:**\n\n```typescript\nimport { ApolloServer } from \"@apollo/server\";\nimport { expressMiddleware } from \"@as-integrations/express5\";\nimport { ApolloServerPluginDrainHttpServer } from \"@apollo/server/plugin/drainHttpServer\";\nimport express from \"express\";\nimport http from \"http\";\nimport cors from \"cors\";\n\nconst app = express();\nconst httpServer = http.createServer(app);\n\nconst server = new ApolloServer({\n  typeDefs,\n  resolvers,\n  plugins: [ApolloServerPluginDrainHttpServer({ httpServer })],\n});\n\nawait server.start();\n\napp.use(\n  \"/graphql\",\n  cors(),\n  express.json(),\n  expressMiddleware(server, {\n    context: async ({ req }) => ({ token: req.headers.authorization }),\n  }),\n);\n\nawait new Promise<void>((resolve) => httpServer.listen({ port: 4000 }, resolve));\nconsole.log(\"Server ready at http://localhost:4000/graphql\");\n```\n\n## Schema Definition\n\n### Scalar Types\n\n- `Int` - 32-bit integer\n- `Float` - Double-precision floating-point\n- `String` - UTF-8 string\n- `Boolean` - true/false\n- `ID` - Unique identifier (serialized as String)\n\n### Type Definitions\n\n```graphql\ntype User {\n  id: ID!\n  name: String!\n  email: String\n  posts: [Post!]!\n}\n\ntype Post {\n  id: ID!\n  title: String!\n  content: String\n  author: User!\n}\n\ninput CreatePostInput {\n  title: String!\n  content: String\n}\n\ntype Query {\n  user(id: ID!): User\n  users: [User!]!\n}\n\ntype Mutation {\n  createPost(input: CreatePostInput!): Post!\n}\n```\n\n### Enums and Interfaces\n\n```graphql\nenum Status {\n  DRAFT\n  PUBLISHED\n  ARCHIVED\n}\n\ninterface Node {\n  id: ID!\n}\n\ntype Article implements Node {\n  id: ID!\n  title: String!\n}\n```\n\n## Resolvers Overview\n\nResolvers follow the signature: `(parent, args, contextValue, info)`\n\n- **parent**: Result from parent resolver (root resolvers receive undefined)\n- **args**: Arguments passed to the field\n- **contextValue**: Shared context object (auth, dataSources, etc.)\n- **info**: Field-specific info and schema details (rarely used)\n\n```typescript\nconst resolvers = {\n  Query: {\n    user: async (_, { id }, { dataSources }) => {\n      return dataSources.usersAPI.getUser(id);\n    },\n  },\n  User: {\n    posts: async (parent, _, { dataSources }) => {\n      return dataSources.postsAPI.getPostsByAuthor(parent.id);\n    },\n  },\n  Mutation: {\n    createPost: async (_, { input }, { dataSources, user }) => {\n      if (!user) throw new GraphQLError(\"Not authenticated\");\n      return dataSources.postsAPI.create({ ...input, authorId: user.id });\n    },\n  },\n};\n```\n\n## Context Setup\n\nContext is created per-request and passed to all resolvers.\n\n```typescript\ninterface MyContext {\n  token?: string;\n  user?: User;\n  dataSources: {\n    usersAPI: UsersDataSource;\n    postsAPI: PostsDataSource;\n  };\n}\n\nconst server = new ApolloServer<MyContext>({\n  typeDefs,\n  resolvers,\n});\n\n// Standalone\nconst { url } = await startStandaloneServer(server, {\n  context: async ({ req }) => ({\n    token: req.headers.authorization || \"\",\n    user: await getUser(req.headers.authorization || \"\"),\n    dataSources: {\n      usersAPI: new UsersDataSource(),\n      postsAPI: new PostsDataSource(),\n    },\n  }),\n});\n\n// Express middleware\nexpressMiddleware(server, {\n  context: async ({ req, res }) => ({\n    token: req.headers.authorization,\n    user: await getUser(req.headers.authorization),\n    dataSources: {\n      usersAPI: new UsersDataSource(),\n      postsAPI: new PostsDataSource(),\n    },\n  }),\n});\n```\n\n## Reference Files\n\nDetailed documentation for specific topics:\n\n- [Resolvers](references/resolvers.md) - Resolver patterns and best practices\n- [Context and Auth](references/context-and-auth.md) - Authentication and authorization\n- [Plugins](references/plugins.md) - Server and request lifecycle hooks\n- [Data Sources](references/data-sources.md) - RESTDataSource and DataLoader\n- [Error Handling](references/error-handling.md) - GraphQLError and error formatting\n- [Troubleshooting](references/troubleshooting.md) - Common issues and solutions\n\n## Key Rules\n\n### Schema Design\n\n- Use **!** (non-null) for fields that always have values\n- Prefer input types for mutations over inline arguments\n- Use interfaces for polymorphic types\n- Keep schema descriptions for documentation\n\n### Resolver Best Practices\n\n- Keep resolvers thin - delegate to services/data sources\n- Always handle errors explicitly\n- Use DataLoader for batching related queries\n- Return partial data when possible (GraphQL's strength)\n\n### Performance\n\n- Use `@defer` and `@stream` for large responses\n- Implement DataLoader to solve N+1 queries\n- Consider persisted queries for production\n- Use caching headers and CDN where appropriate\n\n## Ground Rules\n\n- ALWAYS use Apollo Server 5.x patterns (not v4 or earlier)\n- ALWAYS type your context with TypeScript generics\n- ALWAYS use `GraphQLError` from `graphql` package for errors\n- NEVER expose stack traces in production errors\n- PREFER `startStandaloneServer` for prototyping only\n- USE an integration with a server framework like Express, Koa, Fastify, Next, etc. for production apps\n- IMPLEMENT authentication in context, authorization in resolvers","tags":["apollo","server","skills","apollographql","agent-skills","graphql"],"capabilities":["skill","source-apollographql","skill-apollo-server","topic-agent-skills","topic-apollo","topic-graphql"],"categories":["skills"],"synonyms":[],"warnings":[],"endpointUrl":"https://skills.sh/apollographql/skills/apollo-server","protocol":"skill","transport":"skills-sh","auth":{"type":"none","details":{"cli":"npx skills add apollographql/skills","source_repo":"https://github.com/apollographql/skills","install_from":"skills.sh"}},"qualityScore":"0.736","qualityRationale":"deterministic score 0.74 from registry signals: · indexed on github topic:agent-skills · official publisher · 71 github stars · SKILL.md body (6,566 chars)","verified":false,"liveness":"unknown","lastLivenessCheck":null,"agentReviews":{"count":0,"score_avg":null,"cost_usd_avg":null,"success_rate":null,"latency_p50_ms":null,"narrative_summary":null,"summary_updated_at":null},"enrichmentModel":"deterministic:skill-github:v1","enrichmentVersion":1,"enrichedAt":"2026-05-18T18:57:02.095Z","embedding":null,"createdAt":"2026-04-18T20:33:43.758Z","updatedAt":"2026-05-18T18:57:02.095Z","lastSeenAt":"2026-05-18T18:57:02.095Z","tsv":"'+1':663 '-8':316 '/express5':105,239 '/graphql':275 '1':18,88 '1984':145 '2':26,110 '3':33,128 '32':304 '4':38,150 '4000':221,291 '4000/graphql':298 '5':12,45,49,69,683 'agnost':73 'alway':601,632,679,690,697 'apollo':2,10,23,47,52,67,171,681 'apollo-serv':1 'apollo/server':93,101,203,232 'apollo/server/plugin/drainhttpserver':243 'apollo/server/standalone':207 'apolloserv':201,211,230,266,497 'apolloserverplugindrainhttpserv':241,270 'app':257,262,732 'app.use':274 'appropri':676 'archiv':377 'arg':397,409 'argument':410,611 'articl':383 'as-integr':102,236 'async':281,437,445,453,507,527 'auth':419,559 'authent':35,463,561,734 'author':37,121,140,146,347,563,737 'authorid':467 'await':216,272,285,503,512,533 'bash':90,98 'batch':639 'best':555,623 'bit':305 'book':118,125,126,135 'boolean':318 'build':6 'cach':671 'cdn':674 'common':586 'consid':665 'console.log':222,293 'const':114,132,208,214,256,259,263,433,494,501 'content':345,353 'context':280,417,469,471,506,526,557,693,736 'contextvalu':398,415 'cor':108,253,255,276 'creat':39,473 'createpost':365,452 'createpostinput':350,367 'custom':42 'data':43,571,644 'dataload':576,637,659 'datasourc':420,439,447,455,489,515,536 'datasources.postsapi.create':465 'datasources.postsapi.getpostsbyauthor':449 'datasources.usersapi.getuser':441 'defer':652 'defin':30,111 'definit':300,327 'deleg':628 'descript':619 'design':593 'detail':429,545 'document':546,621 'doubl':309 'double-precis':308 'draft':375 'earlier':689 'email':335 'enum':369,373 'environ':84 'error':577,582,634,704,711 'etc':421,729 'explicit':635 'expos':706 'express':80,96,106,183,227,245,247,258,522,725 'express.json':277 'expressmiddlewar':234,278,524 'f':141 'fastifi':81,186,727 'featur':178 'field':414,424,599 'field-specif':423 'file':544 'fitzgerald':143 'float':307,312 'floating-point':311 'follow':393 'format':583 'framework':72,180,195,723 'framework-agnost':71 'fulli':177 'fully-featur':176 'gatsbi':139 'generic':696 'georg':147 'getus':513,534 'graphql':7,31,59,65,94,107,116,328,372,647,701 'graphqlerror':461,580,699 'great':138,161 'ground':677 'guid':4,51 'handl':578,633 'header':672 'hook':570 'http':249,251 'http.createserver':261 'httpserver':260,271 'httpserver.listen':289 'id':320,331,332,341,342,358,359,380,381,386,387,438,442 'identifi':322 'implement':34,384,658,733 'import':200,204,229,233,240,244,248,252 'info':399,422,426 'inlin':610 'input':349,366,454,466,605 'instal':89,92,100 'int':303 'integ':306 'integr':78,97,104,170,238,719 'interfac':371,378,483,613 'issu':587 'keep':617,625 'key':590 'koa':184,726 'larg':656 'later':196 'lifecycl':569 'like':724 'listen':219 'localhost':297 'middlewar':523 'mutat':364,451,608 'mycontext':484 'n':662 'name':333 'never':705 'new':22,210,265,286,460,496,517,520,538,541 'next':728 'node':379,385 'non':596 'non-nul':595 'npm':91,99 'null':597 'object':418 'open':57 'open-sourc':56 'orwel':148 'overview':391 'packag':702 'parent':396,400,403,446 'parent.id':450 'partial':643 'pass':411,478 'pattern':553,685 'per':475 'per-request':474 'perform':650 'persist':666 'plugin':40,269,564 'point':313 'polymorph':615 'port':220,290 'possibl':646 'post':337,338,340,368,444 'postsapi':492,519,540 'postsdatasourc':493,521,542 'practic':556,624 'precis':310 'prefer':604,712 'product':166,669,710,731 'project':25 'promis':287 'prototyp':156,163,715 'publish':376 'queri':124,134,356,435,641,664,667 'quick':85 'rare':430 'readi':224,295 'receiv':407 'recommend':154,169 'refer':543 'references/context-and-auth.md':560 'references/data-sources.md':573 'references/error-handling.md':579 'references/plugins.md':565 'references/resolvers.md':551 'references/troubleshooting.md':585 'relat':640 'req':282,508,528 'req.headers.authorization':284,510,514,531,535 'request':476,568 'res':529 'resolv':28,130,133,213,268,288,292,390,392,404,406,434,481,499,550,552,622,626,739 'respons':657 'restdatasourc':574 'result':401 'return':440,448,464,642 'root':405 'rule':591,678 'run':75 'scalar':301 'schema':32,66,112,299,428,592,618 'scott':142 'serial':323 'server':3,8,11,24,48,53,60,68,152,159,172,191,209,218,223,264,279,294,495,505,525,566,682,722 'server.start':273 'serverless':83 'servic':167 'services/data':630 'set':19 'setup':470 'share':416 'signatur':395 'skill':16 'skill-apollo-server' 'solut':589 'solv':661 'sourc':44,58,572,631 'source-apollographql' 'specif':425,548 'stack':707 'standalon':76,153,158,190,500 'start':86,151 'startstandaloneserv':205,217,504,713 'status':374 'step':87,109,127,149 'straightforward':198 'stream':654 'strength':649 'string':120,122,314,317,325,334,336,344,346,352,354,389,486 'swap':187 'thin':627 'throw':459 'titl':119,136,144,343,351,388 'token':283,485,509,530 'topic':549 'topic-agent-skills' 'topic-apollo' 'topic-graphql' 'trace':708 'troubl':46 'troubleshoot':584 'true/false':319 'type':117,123,302,326,329,339,355,363,382,606,616,691 'typedef':115,212,267,498 'typescript':113,131,199,228,432,482,695 'undefin':408 'uniqu':321 'url':215,226,502 'use':14,431,594,612,636,651,670,680,698,717 'user':330,348,357,360,361,362,436,443,456,458,487,488,511,532 'user.id':468 'usersapi':490,516,537 'usersdatasourc':491,518,539 'utf':315 'v4':687 'valu':603 'web':179,194 'work':62 'write':27,129 'x':13,50,684","prices":[{"id":"de85bbce-93bd-49ea-b070-67768e88ef58","listingId":"b1f38efa-2792-45d8-a97f-d59ccd264904","amountUsd":"0","unit":"free","nativeCurrency":null,"nativeAmount":null,"chain":null,"payTo":null,"paymentMethod":"skill-free","isPrimary":true,"details":{"org":"apollographql","category":"skills","install_from":"skills.sh"},"createdAt":"2026-04-18T20:33:43.758Z"}],"sources":[{"listingId":"b1f38efa-2792-45d8-a97f-d59ccd264904","source":"github","sourceId":"apollographql/skills/apollo-server","sourceUrl":"https://github.com/apollographql/skills/tree/main/skills/apollo-server","isPrimary":false,"firstSeenAt":"2026-04-18T22:17:25.477Z","lastSeenAt":"2026-05-18T18:57:02.095Z"},{"listingId":"b1f38efa-2792-45d8-a97f-d59ccd264904","source":"skills_sh","sourceId":"apollographql/skills/apollo-server","sourceUrl":"https://skills.sh/apollographql/skills/apollo-server","isPrimary":true,"firstSeenAt":"2026-04-18T20:33:43.758Z","lastSeenAt":"2026-05-07T22:40:35.609Z"}],"details":{"listingId":"b1f38efa-2792-45d8-a97f-d59ccd264904","quickStartSnippet":null,"exampleRequest":null,"exampleResponse":null,"schema":null,"openapiUrl":null,"agentsTxtUrl":null,"citations":[],"useCases":[],"bestFor":[],"notFor":[],"kindDetails":{"org":"apollographql","slug":"apollo-server","github":{"repo":"apollographql/skills","stars":71,"topics":["agent-skills","apollo","graphql"],"license":"mit","html_url":"https://github.com/apollographql/skills","pushed_at":"2026-05-14T17:14:05Z","description":"Apollo GraphQL Agent Skills","skill_md_sha":"f20bb6a891659d1062db7a5d14dd24686fba4345","skill_md_path":"skills/apollo-server/SKILL.md","default_branch":"main","skill_tree_url":"https://github.com/apollographql/skills/tree/main/skills/apollo-server"},"layout":"multi","source":"github","category":"skills","frontmatter":{"name":"apollo-server","license":"MIT","description":"Guide for building GraphQL servers with Apollo Server 5.x. Use this skill when: (1) setting up a new Apollo Server project, (2) writing resolvers or defining GraphQL schemas, (3) implementing authentication or authorization, (4) creating plugins or custom data sources, (5) troubleshooting Apollo Server errors or performance issues.","compatibility":"Node.js v20+, TypeScript 4.7+. Works with Express v4/v5, standalone, Fastify, and serverless."},"skills_sh_url":"https://skills.sh/apollographql/skills/apollo-server"},"updatedAt":"2026-05-18T18:57:02.095Z"}}