graphql
GraphQL
Schema design, queries, mutations, and tooling.
Schema Definition
# Type definitions
type User {
id: ID!
email: String!
name: String
posts: [Post!]!
createdAt: DateTime!
}
type Post {
id: ID!
title: String!
content: String
published: Boolean!
author: User!
tags: [Tag!]!
}
type Tag {
id: ID!
name: String!
posts: [Post!]!
}
# Input types
input CreateUserInput {
email: String!
name: String
}
input UpdateUserInput {
email: String
name: String
}
input PostFilter {
published: Boolean
authorId: ID
search: String
}
# Enums
enum Role {
ADMIN
USER
MODERATOR
}
enum SortOrder {
ASC
DESC
}
# Custom scalars
scalar DateTime
scalar JSON
# Interfaces
interface Node {
id: ID!
}
type User implements Node {
id: ID!
email: String!
}
# Unions
union SearchResult = User | Post | Tag
Queries
type Query {
# Single item
user(id: ID!): User
post(id: ID!): Post
# Lists with filtering and pagination
users(
filter: UserFilter
limit: Int = 20
offset: Int = 0
orderBy: SortOrder = DESC
): UserConnection!
posts(
filter: PostFilter
first: Int
after: String
): PostConnection!
# Search
search(query: String!): [SearchResult!]!
# Current user
me: User
}
# Cursor-based pagination
type UserConnection {
edges: [UserEdge!]!
pageInfo: PageInfo!
totalCount: Int!
}
type UserEdge {
node: User!
cursor: String!
}
type PageInfo {
hasNextPage: Boolean!
hasPreviousPage: Boolean!
startCursor: String
endCursor: String
}
Query Examples
# Basic query
query {
user(id: "1") {
name
email
}
}
# With variables
query GetUser($id: ID!) {
user(id: $id) {
name
email
posts {
title
published
}
}
}
# Fragment
fragment UserFields on User {
id
name
email
}
query {
user(id: "1") {
...UserFields
posts {
title
}
}
}
# Pagination
query GetPosts($first: Int!, $after: String) {
posts(first: $first, after: $after) {
edges {
node {
id
title
}
cursor
}
pageInfo {
hasNextPage
endCursor
}
}
}
Mutations
type Mutation {
createUser(input: CreateUserInput!): User!
updateUser(id: ID!, input: UpdateUserInput!): User!
deleteUser(id: ID!): Boolean!
createPost(input: CreatePostInput!): Post!
publishPost(id: ID!): Post!
login(email: String!, password: String!): AuthPayload!
}
type AuthPayload {
token: String!
user: User!
}
Mutation Examples
mutation CreateUser($input: CreateUserInput!) {
createUser(input: $input) {
id
email
name
}
}
# Variables:
# { "input": { "email": "alice@test.com", "name": "Alice" } }
mutation Login($email: String!, $password: String!) {
login(email: $email, password: $password) {
token
user {
id
name
}
}
}
Subscriptions
type Subscription {
postCreated: Post!
messageReceived(channelId: ID!): Message!
}
# Client usage
subscription OnPostCreated {
postCreated {
id
title
author {
name
}
}
}
Resolvers (Node.js)
const resolvers = {
Query: {
user: (_, { id }, context) => context.db.user.findUnique({ where: { id } }),
users: (_, { filter, limit, offset }, context) =>
context.db.user.findMany({ where: filter, take: limit, skip: offset }),
me: (_, __, context) => context.currentUser,
},
Mutation: {
createUser: (_, { input }, context) =>
context.db.user.create({ data: input }),
updateUser: (_, { id, input }, context) =>
context.db.user.update({ where: { id }, data: input }),
},
User: {
posts: (user, _, context) =>
context.db.post.findMany({ where: { authorId: user.id } }),
},
};
Error Handling
# Union-based errors
type CreateUserResult = CreateUserSuccess | ValidationError | EmailTakenError
type CreateUserSuccess {
user: User!
}
type ValidationError {
message: String!
field: String!
}
type EmailTakenError {
message: String!
suggestedEmail: String
}
type Mutation {
createUser(input: CreateUserInput!): CreateUserResult!
}
Reference
For Apollo, Relay, and testing patterns: references/tooling.md
More from 1mangesh1/dev-skills-collection
curl-http
HTTP request construction and API testing with curl and HTTPie. Use when user asks to "test API", "make HTTP request", "curl POST", "send request", "test endpoint", "debug API", "upload file", "check response time", "set auth header", "basic auth with curl", "send JSON", "test webhook", "check status code", "follow redirects", "rate limit testing", "measure API latency", "stress test endpoint", "mock API response", or any HTTP calls from the command line.
28database-indexing
Database indexing internals, index type selection, query plan analysis, and write-overhead tradeoffs across PostgreSQL, MySQL, and MongoDB. Use when user asks to "optimize queries", "create indexes", "fix slow queries", "read EXPLAIN output", "reduce query time", "index strategy", "database performance", "composite index", "covering index", "partial index", "index bloat", "unused indexes", or needs help diagnosing and resolving database performance problems.
13testing-strategies
Testing strategies, patterns, and methodologies across the full testing spectrum. Use when asked about unit tests, integration tests, e2e tests, test pyramid, mocking, test doubles, TDD, property-based testing, snapshot testing, test coverage, mutation testing, contract testing, performance testing, test data management, CI/CD testing, flaky tests, test anti-patterns, test organization, test isolation, test fixtures, test parameterization, or any testing strategy, approach, or methodology.
10secret-scanner
This skill should be used when the user asks to "scan for secrets", "find API keys", "detect credentials", "check for hardcoded passwords", "find leaked tokens", "scan for sensitive keys", "check git history for secrets", "audit repository for credentials", or mentions secret detection, credential scanning, API key exposure, token leakage, password detection, or security key auditing.
10terraform
Terraform infrastructure as code for provisioning, modules, state management, and workspaces. Use when user asks to "create infrastructure", "write Terraform", "manage state", "create module", "import resource", "plan changes", or any IaC tasks.
10kubernetes
Kubernetes and kubectl mastery for deployments, services, pods, debugging, and cluster management. Use when user asks to "deploy to k8s", "create deployment", "debug pod", "kubectl commands", "scale service", "check pod logs", "create ingress", or any Kubernetes tasks.
10