GraphQL Schema Designer
Prerequisites & Dependencies
- Node.js 18+ with npm or pnpm
- GraphQL tooling:
npm i graphql and npm i -D graphql-cli for validation
- Optional:
npm i @apollo/server for Node 16+ server setup, or npm i express-graphql for Express integration
- Text editor with GraphQL schema syntax highlighting
Execution Steps
- Define the root-level schema using SDL (Schema Definition Language): type
Query, Mutation, and custom types
- Create scalar types or enums for constrained domains (e.g.,
Status: PENDING | ACTIVE | ARCHIVED)
- Design
Query type with fields that fetch single records or lists, using arguments for filtering/pagination
- Design
Mutation type for create, update, and delete operations, specifying input types via input blocks
- Write resolver skeleton code that delegates to data sources (databases, APIs, in-memory stores)
- Add pagination support using
connection pattern or first/last + after/before cursor arguments
- Validate the schema:
graphql schema validate schema.graphql or integrate with Apollo Studio
- Generate resolver boilerplate and wire it to the Apollo Server or Express middleware
# schema.graphql
type Query {
hello: String
user(id: ID!): User
posts(
first: Int
after: String
): PostConnection
}
type Mutation {
createPost(input: CreatePostInput!): Post
updatePostStatus(id: ID!, status: Status!): Post
}
input CreatePostInput {
title: String!
content: String!
published: Boolean
}
type User {
id: ID!
name: String!
email: String!
posts: [Post!]!
}
type Post {
id: ID!
title: String!
content: String
published: Boolean!
author: User!
}
enum Status {
PENDING
ACTIVE
ARCHIVED
}
type PostConnection {
totalCount: Int!
edges: [PostEdge!]!
pageInfo: PageInfo!
}
type PostEdge {
cursor: String!
node: Post!
}
type PageInfo {
hasNextPage: Boolean!
hasPreviousPage: Boolean!
startCursor: String
endCursor: String
}
// resolver skeleton (Node.js with @apollo/server)
const { ApolloServer } = require('@apollo/server');
const { startServerAndCreateHandler } = require('@apollo/server/express4');
const startApolloServer = async () => {
const server = new ApolloServer({
typeDefs: './schema.graphql',
resolvers: {
Query: {
hello: () => 'World',
user: async (_, { id }) => { /* fetch from DB */ },
posts: async (_, { first, after }) => { /* fetch with pagination */ },
},
Mutation: {
createPost: async (_, { input }) => { /* create and return post */ },
},
},
});
await startServerAndCreateHandler(server).then((handler) => {
const express = require('express');
const app = express();
app.use('/graphql', handler);
app.listen(4000, () => console.log('🚀 Server ready at http://localhost:4000/graphql'));
});
};
startApolloServer();
1---2name: graphql-schema-designer3description: Design GraphQL type definitions, query/mutation schemas, and resolver boilerplate code.4metadata:5 source: skills/graphql-schema-designer/graphql-schema-designer.md6---78# GraphQL Schema Designer910## Prerequisites & Dependencies11- Node.js 18+ with npm or pnpm12- GraphQL tooling: `npm i graphql` and `npm i -D graphql-cli` for validation13- Optional: `npm i @apollo/server` for Node 16+ server setup, or `npm i express-graphql` for Express integration14- Text editor with GraphQL schema syntax highlighting1516## Execution Steps171. Define the root-level schema using SDL (Schema Definition Language): type `Query`, `Mutation`, and custom types182. Create scalar types or enums for constrained domains (e.g., `Status: PENDING | ACTIVE | ARCHIVED`)193. Design `Query` type with fields that fetch single records or lists, using arguments for filtering/pagination204. Design `Mutation` type for create, update, and delete operations, specifying input types via `input` blocks214. Write resolver skeleton code that delegates to data sources (databases, APIs, in-memory stores)225. Add pagination support using `connection` pattern or `first/last` + `after/before` cursor arguments236. Validate the schema: `graphql schema validate schema.graphql` or integrate with Apollo Studio247. Generate resolver boilerplate and wire it to the Apollo Server or Express middleware2526```graphql27# schema.graphql28type Query {29 hello: String30 user(id: ID!): User31 posts(32 first: Int33 after: String34 ): PostConnection35}3637type Mutation {38 createPost(input: CreatePostInput!): Post39 updatePostStatus(id: ID!, status: Status!): Post40}4142input CreatePostInput {43 title: String!44 content: String!45 published: Boolean46}4748type User {49 id: ID!50 name: String!51 email: String!52 posts: [Post!]!53}5455type Post {56 id: ID!57 title: String!58 content: String59 published: Boolean!60 author: User!61}6263enum Status {64 PENDING65 ACTIVE66 ARCHIVED67}6869type PostConnection {70 totalCount: Int!71 edges: [PostEdge!]!72 pageInfo: PageInfo!73}7475type PostEdge {76 cursor: String!77 node: Post!78}7980type PageInfo {81 hasNextPage: Boolean!82 hasPreviousPage: Boolean!83 startCursor: String84 endCursor: String85}86```8788```javascript89// resolver skeleton (Node.js with @apollo/server)90const { ApolloServer } = require('@apollo/server');91const { startServerAndCreateHandler } = require('@apollo/server/express4');9293const startApolloServer = async () => {94 const server = new ApolloServer({95 typeDefs: './schema.graphql',96 resolvers: {97 Query: {98 hello: () => 'World',99 user: async (_, { id }) => { /* fetch from DB */ },100 posts: async (_, { first, after }) => { /* fetch with pagination */ },101 },102 Mutation: {103 createPost: async (_, { input }) => { /* create and return post */ },104 },105 },106 });107108 await startServerAndCreateHandler(server).then((handler) => {109 const express = require('express');110 const app = express();111 app.use('/graphql', handler);112 app.listen(4000, () => console.log('🚀 Server ready at http://localhost:4000/graphql'));113 });114};115116startApolloServer();117```