Last updated
Naming Conventions Applied
- Types: PascalCase (User, PostConnection, UserRole)
- Fields: camelCase (createdAt, authorId, isActive)
- Enum values: SCREAMING_SNAKE_CASE (DRAFT, PUBLISHED, ADMIN)
- Input types: PascalCase + "Input" suffix (CreatePostInput)
- Payload types: PascalCase + "Payload" suffix (CreatePostPayload)
- Connection types: PascalCase + "Connection" suffix (PostConnection)
- Queries: camelCase verb + noun (getUser → user, listPosts → posts)
- Mutations: camelCase verb + noun (createPost, updateUser, deleteComment)
Examples
Example 1: Generate Schema from JSON Sample
Input JSON:
{
"id": "user_123",
"name": "Alice",
"email": "alice@example.com",
"age": 28,
"isActive": true,
"createdAt": "2025-01-15T10:30:00Z",
"profile": {
"bio": "Software engineer",
"avatar": "https://example.com/avatar.jpg",
"location": "San Francisco"
},
"tags": ["developer", "open-source"]
}
Generated GraphQL schema:
type User {
id: ID!
name: String!
email: String!
age: Int!
isActive: Boolean!
createdAt: DateTime!
profile: UserProfile!
tags: [String!]!
}
type UserProfile {
bio: String
avatar: String
location: String
}
type Query {
user(id: ID!): User
users(first: Int, after: String): UserConnection!
}
type UserConnection {
edges: [UserEdge!]!
pageInfo: PageInfo!
totalCount: Int!
}
type UserEdge {
node: User!
cursor: String!
}
type PageInfo {
hasNextPage: Boolean!
hasPreviousPage: Boolean!
startCursor: String
endCursor: String
}
Example 2: Generate Schema from SQL Table
Input SQL:
CREATE TABLE posts (
id BIGINT PRIMARY KEY AUTO_INCREMENT,
title VARCHAR(255) NOT NULL,
content TEXT NOT NULL,
slug VARCHAR(255) UNIQUE NOT NULL,
status ENUM('draft', 'published', 'archived') DEFAULT 'draft',
author_id BIGINT NOT NULL REFERENCES users(id),
published_at TIMESTAMP,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP NOT NULL DEFAULT NOW()
);
Generated GraphQL schema:
enum PostStatus {
DRAFT
PUBLISHED
ARCHIVED
}
type Post {
id: ID!
title: String!
content: String!
slug: String!
status: PostStatus!
author: User!
publishedAt: DateTime
createdAt: DateTime!
updatedAt: DateTime!
}
type Query {
post(id: ID!): Post
postBySlug(slug: String!): Post
posts(
status: PostStatus
authorId: ID
first: Int
after: String
): PostConnection!
}
type Mutation {
createPost(input: CreatePostInput!): CreatePostPayload!
updatePost(id: ID!, input: UpdatePostInput!): UpdatePostPayload!
deletePost(id: ID!): DeletePostPayload!
}
input CreatePostInput {
title: String!
content: String!
slug: String!
status: PostStatus = DRAFT
authorId: ID!
publishedAt: DateTime
}
input UpdatePostInput {
title: String
content: String
slug: String
status: PostStatus
publishedAt: DateTime
}
Example 3: Mutation Payload Pattern
The generator follows the mutation payload pattern for consistent error handling:
type CreatePostPayload {
post: Post
errors: [UserError!]!
}
type UpdatePostPayload {
post: Post
errors: [UserError!]!
}
type DeletePostPayload {
deletedId: ID
errors: [UserError!]!
}
type UserError {
field: String
message: String!
code: String!
}