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

  1. Create a Mock API — Select "GraphQL" as the type when creating a new Mock API.
  2. Import SDL Schema — Paste your GraphQL SDL or provide a URL. moqapi validates the schema and stores it in R2.
  3. Automatic Resolvers — Every Query and Mutation field gets a mock resolver that generates realistic data.
  4. 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.

Example SDL Schemagraphql
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 addresses
  • name → full person names
  • avatar / image → image URLs
  • phone → phone numbers
  • url / website → valid URLs
  • price / amount → currency values
  • title → sentence-like strings
  • body / content / description → paragraph text

Type-Based Fallbacks

  • String → random words
  • Int → random integers
  • Float → decimal numbers
  • Boolean → true/false
  • ID → 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.

cURLbash
curl -X POST https://moqapi.dev/api/invoke/{projectId}/my-graphql-api \
  -H "Content-Type: application/json" \
  -d '{"query": "{ users { id name email } }"}'
JavaScript / TypeScript (fetch)typescript
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' });
Apollo Clienttypescript
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' },
});
Python (requests)python
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"},
)
Responsejson
{
  "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.

Introspection Querygraphql
{
  __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.