Labsco
apollographql logo

apollo-server

โ˜… 90

by apollographql ยท part of apollographql/skills

Complete guide for building GraphQL servers with Apollo Server 5.x across frameworks. Covers schema definition, resolvers, context setup, and error handling with TypeScript support Supports standalone mode for prototyping and integrations with Express, Fastify, Koa, and serverless environments Includes resolver patterns, authentication/authorization, plugins, DataLoader for N+1 prevention, and performance optimization techniques Provides reference documentation for data sources, error...

๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅโœ“ VerifiedFreeQuick setup
๐Ÿงฉ One of 7 skills in the apollographql/skills package โ€” works on its own, and pairs well with its siblings.

Complete guide for building GraphQL servers with Apollo Server 5.x across frameworks. Covers schema definition, resolvers, context setup, and error handling with TypeScript support Supports standalone mode for prototyping and integrations with Express, Fastify, Koa, and serverless environments Includes resolver patterns, authentication/authorization, plugins, DataLoader for N+1 prevention, and performance optimization techniques Provides reference documentation for data sources, error...

Inspect the full instructions your agent will receiveExpand

This is the exact playbook injected into your agent when the skill activates โ€” shown here so you can audit it before installing. You don't need to read it to use the skill.

by apollographql

Complete guide for building GraphQL servers with Apollo Server 5.x across frameworks. Covers schema definition, resolvers, context setup, and error handling with TypeScript support Supports standalone mode for prototyping and integrations with Express, Fastify, Koa, and serverless environments Includes resolver patterns, authentication/authorization, plugins, DataLoader for N+1 prevention, and performance optimization techniques Provides reference documentation for data sources, error... npx skills add https://github.com/apollographql/skills --skill apollo-server Download ZIPGitHub90

Apollo Server 5.x Guide

Apollo 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.

Schema Definition

Scalar Types

  • Int - 32-bit integer

  • Float - Double-precision floating-point

  • String - UTF-8 string

  • Boolean - true/false

  • ID - Unique identifier (serialized as String)

Type Definitions

Copy & paste โ€” that's it
type User {
 id: ID!
 name: String!
 email: String
 posts: [Post!]!
}

type Post {
 id: ID!
 title: String!
 content: String
 author: User!
}

input CreatePostInput {
 title: String!
 content: String
}

type Query {
 user(id: ID!): User
 users: [User!]!
}

type Mutation {
 createPost(input: CreatePostInput!): Post!
}

Enums and Interfaces

Copy & paste โ€” that's it
enum Status {
 DRAFT
 PUBLISHED
 ARCHIVED
}

interface Node {
 id: ID!
}

type Article implements Node {
 id: ID!
 title: String!
}

Resolvers Overview

Resolvers follow the signature: (parent, args, contextValue, info)

  • parent: Result from parent resolver (root resolvers receive undefined)

  • args: Arguments passed to the field

  • contextValue: Shared context object (auth, dataSources, etc.)

  • info: Field-specific info and schema details (rarely used)

Copy & paste โ€” that's it
const resolvers = {
 Query: {
 user: async (_, { id }, { dataSources }) => {
 return dataSources.usersAPI.getUser(id);
 },
 },
 User: {
 posts: async (parent, _, { dataSources }) => {
 return dataSources.postsAPI.getPostsByAuthor(parent.id);
 },
 },
 Mutation: {
 createPost: async (_, { input }, { dataSources, user }) => {
 if (!user) throw new GraphQLError("Not authenticated");
 return dataSources.postsAPI.create({ ...input, authorId: user.id });
 },
 },
};

Reference Files

Detailed documentation for specific topics:

Key Rules

Schema Design

  • Use ! (non-null) for fields that always have values

  • Prefer input types for mutations over inline arguments

  • Use interfaces for polymorphic types

  • Keep schema descriptions for documentation

Resolver Best Practices

  • Keep resolvers thin - delegate to services/data sources

  • Always handle errors explicitly

  • Use DataLoader for batching related queries

  • Return partial data when possible (GraphQL's strength)

Performance

  • Use @defer and @stream for large responses

  • Implement DataLoader to solve N+1 queries

  • Consider persisted queries for production

  • Use caching headers and CDN where appropriate

Ground Rules

  • ALWAYS use Apollo Server 5.x patterns (not v4 or earlier)

  • ALWAYS type your context with TypeScript generics

  • ALWAYS use GraphQLError from graphql package for errors

  • NEVER expose stack traces in production errors

  • PREFER startStandaloneServer for prototyping only

  • USE an integration with a server framework like Express, Koa, Fastify, Next, etc. for production apps

  • IMPLEMENT authentication in context, authorization in resolvers