ai-infrastructure-hugg…
Hugging Face Inference SDK patterns for TypeScript/Node.js — InferenceClient setup, chat completion, text generation, streaming, embeddings, image generation,…
GraphQL server for Fastify with Mercurius — loaders, subscriptions, federation, JIT compilation
$ npx -y skills add agents-inc/skills --skill api-graphql-mercurius --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/api-graphql-mercuriusContext preview
The summary Claude sees to decide when to auto-load this skill.
GraphQL server for Fastify with Mercurius — loaders, subscriptions, federation, JIT compilation
name: api-graphql-mercurius description: GraphQL server for Fastify with Mercurius — loaders, subscriptions, federation, JIT compilation
> **Quick Guide:** Use Mercurius as a Fastify plugin for GraphQL APIs with built-in loader batching (solves N+1), JIT query compilation, subscriptions via WebSocket, and federation support. Register with `app.register(mercurius, { schema, resolvers, loaders })`. Loaders are Mercurius's killer feature: define them per-type to batch field resolution automatically. Use `jit: 1` to enable query compilation for production performance.
---
<critical_requirements>
> **All code must follow project conventions in CLAUDE.md** (kebab-case, named exports, import ordering, `import type`, named constants)
**(You MUST define loaders for any field that fetches related data — loaders solve the N+1 problem automatically through batching)**
**(You MUST use named constants for all numeric values — JIT thresholds, query depth limits, port numbers)**
**(You MUST return an array from loaders matching the exact length and order of the `queries` parameter)**
**(You MUST use `fastify.graphql.pubsub.publish()` inside mutations to trigger subscriptions — not external pubsub directly)**
</critical_requirements>
---
**Auto-detection:** Mercurius, mercurius, app.graphql, fastify.graphql, mercurius loaders, mercurius subscription, pubsub.publish, pubsub.subscribe, @mercuriusjs/federation, @mercuriusjs/gateway, mercurius-codegen, MercuriusContext, graphql-jit, withFilter, preParsing, preValidation, preExecution, onResolution
**When to use:**
**When NOT to use:**
**Key patterns covered:**
---
**Detailed Resources:**
---
<philosophy>
**Fastify-native GraphQL.** Mercurius is not a standalone server bolted onto Fastify — it is a Fastify plugin that deeply integrates with Fastify's lifecycle, encapsulation model, and plugin system. This means your GraphQL API inherits Fastify's performance characteristics and plugin architecture naturally.
**Loaders over DataLoader.** Instead of requiring a separate DataLoader library, Mercurius provides a built-in loader system. Loaders are defined per-type/per-field and receive batched queries automatically. This is simpler than manually instantiating DataLoader instances per-request and is the primary mechanism for solving the N+1 problem.
**JIT for production.** Mercurius uses graphql-jit to compile frequently-executed queries into optimized V8 functions. After a configurable threshold of executions, subsequent runs of the same query bypass the GraphQL execution engine entirely — delivering significant performance gains for repeated queries.
**Federation as a plugin.** Federation support is split into separate packages (`@mercuriusjs/federation` for services, `@mercuriusjs/gateway` for composition), keeping the core library lean for non-federated use cases.
</philosophy>
---
<patterns>
Register Mercurius as a Fastify plugin with schema (SDL string), resolvers, and optional loaders.
import Fastify from "fastify";
import mercurius from "mercurius";
const JIT_THRESHOLD = 1;
const SERVER_PORT = 3000;
const app = Fastify({ logger: true });
const schema = `
type Query {
user(id: ID!): User
users: [User!]!
}
type User {
id: ID!
name: String!
posts: [Post!]!
}
type Post {
id: ID!
title: String!
}
`;
app.register(mercurius, {
schema,
resolvers,
loaders,
jit: JIT_THRESHOLD,
graphiql: process.env.NODE_ENV !== "production",
});**Why good:** JIT threshold as named constant, GraphiQL disabled in production, loaders passed at registration level alongside resolvers
> Full registration with context, error handling, and all options: [examples/core.md](examples/core.md)
---
Loaders are Mercurius's primary mechanism for batch data fetching. Define them per-type per-field. Each loader receives an array of `queries` (batched requests) and must return an array of results in the same order.
const loaders = {
User: {
async posts(
queries: Array<{ obj: User; params: Record<string, unknown> }>,
context: MercuriusContext,
) {
const userIds = queries.map(({ obj }) => obj.id);
const allPosts = await fetchPostsByUserIds(userIds);
// Return array matching queries order
return quThe official skills marketplace for Agents Inc. 150+ skills covering everything from React and Prisma to Redis, ElevenLabs, and infrastructure tooling. Pick the skills that match your stack and install them via Claude Code. Need more control?
Repo: agents-inc/skills
Hugging Face Inference SDK patterns for TypeScript/Node.js — InferenceClient setup, chat completion, text generation, streaming, embeddings, image generation,…
LiteLLM proxy server setup, TypeScript client patterns via OpenAI SDK, model routing, fallbacks, load balancing, spend tracking, virtual keys, and production…
Serverless GPU compute platform for AI model deployment — web endpoints, GPU functions, model serving, and TypeScript client patterns
Local LLM inference with the Ollama JavaScript client -- chat, streaming, tool calling, vision, embeddings, structured output, model management, and…
Replicate SDK patterns for TypeScript/Node.js -- client setup, predictions, streaming, webhooks, file handling, model versioning, deployments, and training
Together AI SDK patterns for TypeScript — client setup, chat completions, streaming, structured output, function calling, embeddings, image generation,…