September 29, 2026

Apollo Mock: LLM-generated data for your Kotlin applications

Martin Bonnin

Martin Bonnin

Building or testing a GraphQL client usually means dealing with data you don’t control yet: a backend that isn’t finished, a staging environment that’s flaky or rate-limited, or a dataset that simply doesn’t have the edge cases you need for a given test. 

The usual workarounds — hand-written fixtures, faker calls wired up field by field, or a hardcoded JSON blob that quietly drifts out of sync with the schema — all work, but they all cost maintenance time that scales with the size of your schema.

Apollo Mock takes a more direct approach: point it at a GraphQL schema, and it uses an LLM to generate a full set of fake entities that match that schema, once, as plain JSON files on disk. From there, a small GraphQL server resolves any query against that data. 

The LLM only runs at generation time, not per-request, so once the data is generated, serving it is fast, deterministic, and doesn’t depend on an API key or a model being available.

Quickstart

1. Apply the Gradle plugin

1plugins {2  id("com.apollographql.mock") version "<version>"3}45apolloMock {6  service("shop") {7    // The place where your schema is8    srcDir("src/main/graphql")9  }10}

By default, generation runs against a local Ollama model — no API key needed. Anthropic’s API is also supported, and is generally a better fit for larger or more nuanced schemas:

1apolloMock {2  service("shop") {3    srcDir("src/main/graphql")4    provider.set("anthropic")5    apiKey.set(System.getenv("ANTHROPIC_API_KEY"))6  }7}

2. Generate the data

Assuming a schema like this, under src/main/graphql/schema.graphqls:

1type Query {2  products: [Product!]!3  product(id: ID!): Product4  categories: [Category!]!5}67type Product {8  id: ID!9  name: String!10  description: String11  price: Float!12  category: Category!13}1415type Category {16  id: ID!17  name: String!18}

./gradlew generateShopMockData generates one JSON file per fake entity under src/main/graphql/mock-data/entity, keyed by GraphQL type.

For an example:

1{2    "name": "Wireless Noise-Canceling Headphones",3    "description": "Premium over-ear headphones with 30-hour battery life and adaptive noise cancellation.",4    "price": 249.99,5    "currency": "USD",6    "inStock": true,7    "id": "product-1",8    "category": {9        "__typename": "Category",10        "id": "category-1"11    },12    "reviews": [13        {14            "__typename": "Review",15            "id": "review-2"16        },17        {18            "__typename": "Review",19            "id": "review-3"20        },21        {22            "__typename": "Review",23            "id": "review-4"24        }25    ]26}

Re-running the task after a schema change keeps existing entities and their ids stable: removed fields are dropped, newly added fields are filled in, and everything else is left alone — which matters if tests elsewhere depend on those ids.

3. Serve it

Add the server module and call serve from a small main:

1dependencies {2  implementation("com.apollographql.mock:server:<version>")3}45import apollo.mock.server.serve67fun main() {8  serve(9      schemaPath = "src/main/graphql/schema.graphqls",10      dataPath = "src/main/graphql/mock-data",11  )12}

Running it starts a GraphQL endpoint at http://localhost:4000/graphql, along with a sandbox at http://localhost:4000/ to explore the schema and try queries interactively:

curl -s http://localhost:4000/graphql \
  -H "Content-Type: application/json" \
  -d '{"query": "{ products { name price category { name } } }"}'

That’s the whole loop: a schema in, a Gradle task to generate data against it, and a couple of lines of Kotlin to serve it. From here, an ApolloClient (or any GraphQL client, generated code or not) can point at localhost:4000 the same way it would point at a real backend.

What’s next

This is the first release of Apollo Mock, we’re excited to hear your feedback and what you’re building with it.

If not using Kotlin, you can use the cli directly. Find all the documentation on the docs website.

If you have any questions or feedback, please reach out to us on GitHub or Discord.

Written by

Martin Bonnin

Martin Bonnin

Read more by Martin Bonnin