GraphQL Mocking — Mock API from SDL Schema
Import a GraphQL SDL schema and instantly get a fully-functional mock GraphQL endpoint. moqapi parses your schema, generates smart mock data using field-name heuristics and Faker.js, and supports introspection queries out of the box.
01 — How It Works
- Create a Mock API — Select "GraphQL" as the type when creating a new Mock API.
- Import SDL Schema — Paste your GraphQL SDL or provide a URL. moqapi validates the schema and stores it in R2.
- Automatic Resolvers — Every Query and Mutation field gets a mock resolver that generates realistic data.
- Test in Playground — Use the built-in GraphQL playground to execute queries and see responses.
02 — Importing a Schema
Click "Import SDL" in the editor header. You can paste a schema directly or provide a URL.
type Query {
users: [User!]!
user(id: ID!): User
posts(limit: Int): [Post!]!
}
type Mutation {
createUser(name: String!, email: String!): User!
deleteUser(id: ID!): Boolean!
}
type User {
id: ID!
name: String!
email: String!
avatar: String
posts: [Post!]!
createdAt: String!
}
type Post {
id: ID!
title: String!
body: String!
author: User!
published: Boolean!
}03 — Smart Mock Data
moqapi uses field-name heuristics to generate realistic data:
Field Name → Faker Mapping
email→ realistic email addressesname→ full person namesavatar / image→ image URLsphone→ phone numbersurl / website→ valid URLsprice / amount→ currency valuestitle→ sentence-like stringsbody / content / description→ paragraph text
Type-Based Fallbacks
String→ random wordsInt→ random integersFloat→ decimal numbersBoolean→ true/falseID→ UUIDs[Type]→ arrays of 3-5 items
04 — Querying Your Mock Endpoint
Your mock GraphQL endpoint is available at https://moqapi.dev/api/invoke/{projectId}/{base-path}. You can find the exact URL in your project's Mock API editor.
curl -X POST https://moqapi.dev/api/invoke/{projectId}/my-graphql-api \
-H "Content-Type: application/json" \
-d '{"query": "{ users { id name email } }"}'const ENDPOINT = 'https://moqapi.dev/api/invoke/{projectId}/my-graphql-api';
async function gql<T>(query: string, variables?: Record<string, unknown>): Promise<T> {
const res = await fetch(ENDPOINT, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ query, variables }),
});
const { data, errors } = await res.json();
if (errors?.length) throw new Error(errors[0].message);
return data as T;
}
// Fetch all users
const { users } = await gql<{ users: { id: string; name: string; email: string }[] }>(`
query GetUsers {
users { id name email }
}
`);
// Create a user (mutation)
const { createUser } = await gql(`
mutation CreateUser($name: String!, $email: String!) {
createUser(name: $name, email: $email) { id name email }
}
`, { name: 'Alice', email: 'alice@example.com' });import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
const client = new ApolloClient({
uri: 'https://moqapi.dev/api/invoke/{projectId}/my-graphql-api',
cache: new InMemoryCache(),
});
// Query
const { data } = await client.query({
query: gql`
query GetUsers {
users { id name email avatar }
}
`,
});
// Mutation
await client.mutate({
mutation: gql`
mutation CreateUser($name: String!, $email: String!) {
createUser(name: $name, email: $email) { id }
}
`,
variables: { name: 'Alice', email: 'alice@example.com' },
});import requests
ENDPOINT = "https://moqapi.dev/api/invoke/{projectId}/my-graphql-api"
def gql(query, variables=None):
res = requests.post(ENDPOINT, json={"query": query, "variables": variables or {}})
res.raise_for_status()
payload = res.json()
if "errors" in payload:
raise Exception(payload["errors"][0]["message"])
return payload["data"]
# Fetch users
data = gql("{ users { id name email } }")
print(data["users"])
# Mutation with variables
data = gql(
"mutation CreateUser($name: String!, $email: String!) { createUser(name: $name, email: $email) { id } }",
{"name": "Alice", "email": "alice@example.com"},
){
"data": {
"users": [
{ "id": "a1b2c3d4", "name": "Jane Cooper", "email": "jane@example.com" },
{ "id": "e5f6g7h8", "name": "Marcus Chen", "email": "marcus@example.com" },
{ "id": "i9j0k1l2", "name": "Sarah Park", "email": "sarah@example.com" }
]
}
}05 — Introspection Support
Full __schema and __type introspection is supported, so tools like GraphiQL, Apollo Studio, and Postman can auto-discover your schema.
{
__schema {
queryType { name }
types {
name
kind
fields { name type { name kind } }
}
}
}// How Mock Data Works
Unlike REST resource mock APIs which store records in the database, GraphQL mock APIs generate data automatically at query time. Every time you execute a query, moqapi analyzes the schema types and field names to produce realistic fake data using Faker.js. There is no "Generate Mock Data" button — simply import your schema, click any operation in the playground, and execute. Each request produces fresh mock data.