Learn how to configure GraphQL schemas in MockQL to create realistic mock APIs for testing your applications.
MockQL uses a top-down approach for schema creation. Start with the main Query type and define each type it uses, building your API structure like a tree.
type Query { listAllCategories: categoryConnection } type categoryConnection { categories: [category] } type category { sample_value: String @mock(type:"commerce.productDescription") }
This creates a query that returns a connection containing a list of categories, each with a mocked product description.
type Query { listAllCategories: categoryConnection } type categoryConnection { categories: [category] } type category { level1: level2 } type level2 { level3: level4 } type level4 { value: String @mock(type: "commerce.productDescription") }
Creates a nested structure where each level references the next, allowing deep data hierarchies.
type Query { listAllCategories: categoryConnection } type categoryConnection { sample_value: String @mock(type:"commerce.productDescription") // New field }
type Query { customQuery: mycustomType // Define a new custom type } type mycustomType { sample_url: [String] @mock(type:"image.url", count: 5) sample_value: String @mock(type:"commerce.productDescription") }
type Query { listAllCategories: categoryConnection } type categoryConnection { categories: [overrideCategory] // Using a custom type } type overrideCategory { // Create an entirely new type overrided_type_data: [String] @mock(type:"person.fullName", count: 2) nested_value: [mycustomType] } type mycustomType { sample_url: [String] @mock(type:"image.url", count: 5) sample_value: String @mock(type:"commerce.productDescription") }
When overriding types, you must recreate all fields with mock directives as there's no merging between your mock types and backend data.
// Basic usage - generates a fake product description field: String @mock(type: "commerce.productDescription") // Array with count parameter - generates 5 random image URLs sample_url: [String] @mock(type: "image.url", count: 5) // Using arrayElement to select from predefined values status: String @mock(type: "helpers.arrayElement", values: ["ACTIVE", "INACTIVE"]) // Custom weighted choices rarity: String @mock(type: "custom.weightedChoice", weightedValues: [["Common", 0.7], ["Rare", 0.2], ["Legendary", 0.1]]) // Number ranges with min/max score: Int @mock(type: "number.int", min: 1, max: 100) // Pattern-based generation phone: String @mock(type: "helpers.regexpify", pattern: "\+1-[0-9]{3}-[0-9]{3}-[0-9]{4}") // Nullable fields description: String @mock(type: "lorem.paragraph", nullable: true, nullProbability: 0.3)
The @mock directive generates fake data based on the type and parameters you provide.
MockQL supports all Faker.js categories including: string, number, internet, person, date, image, commerce, company, location, phone, system, lorem, finance, datatype, color, database, hacker, airline, animal, music, and word.
type Query { listAllCategories: categoryConnection } type categoryConnection { categories: [customCategory] nextToken: String @mock(type: "datatype.uuid") totalCount: Int @mock(type: "number.int", min: 10, max: 100) } type customCategory { category_id: String @mock(type: "string.uuid") category_name: String @mock(type: "commerce.productName") description: String @mock(type: "commerce.productDescription") status: String @mock(type: "helpers.arrayElement", values: ["ACTIVE", "INACTIVE", "PENDING"]) popularity_score: Float @mock(type: "number.float", min: 0, max: 10) }
query GetCategories { listAllCategories { categories { category_id category_name description status popularity_score } nextToken totalCount } }
{ "listAllCategories": { "categories": [ { "category_id": "fae12d5b-3af7-4965-8c4f-21e58d3a6b4c", "category_name": "Handcrafted Metal Chair", "description": "Ergonomic design with premium materials", "status": "ACTIVE", "popularity_score": 8.7 }, { "category_id": "a9c53e8d-6b2f-47d1-9f8a-3c6e4b2d5a1f", "category_name": "Rustic Wooden Table", "description": "Natural wood grain with artisanal craftsmanship", "status": "PENDING", "popularity_score": 6.2 } ], "nextToken": "eyJsYXN0RXZhbHVhdGVkS2V5Ijp7ImlkIjoxMDB9fQ==", "totalCount": 42 } }
You cannot reuse backend types for custom queries. When defining a new query path, you must create entirely new types with mock directives.
// DON'T DO THIS - Won't work type Query { myCustomQuery: ExistingBackendType // WRONG } // INSTEAD DO THIS type Query { myCustomQuery: MyCustomType // Create new types } type MyCustomType { field1: String @mock(type: "commerce.productName") }
Use String with mock directives instead of enums:
type category { status: String @mock(type: "helpers.arrayElement", values: ["ACTIVE", "INACTIVE"]) }
The editor provides code completion for mock directives. Press Alt+M to insert a mock directive template, or type @mock to trigger suggestions.
// Phone number
\+1-[0-9]3-[0-9]3-[0-9]4
// Email pattern
[a-z]10\.[a-z]10@[a-z]10\.[a-z]5
// UUID v4
[0-9a-f]8-[0-9a-f]4-4[0-9a-f]3-[89ab][0-9a-f]3-[0-9a-f]12
Always define schemas from top (Query) to bottom (fields) for proper structure.
Create custom types for new queries rather than reusing existing types.
Clear, descriptive names improve readability and maintainability.
Choose mock types that match expected real data for better testing.
Take advantage of auto-completion and keyboard shortcuts (Alt+M) for faster schema creation.
Switch to the Explorer tab frequently to test your schema changes and ensure they work as expected.