Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

@mock Directive

@mock marks a GraphQL operation or field for AI-generated mock data.

directive @mock(hint: String) on QUERY | MUTATION | FIELD

Locations

@mock is valid on:

  • Query operation definitions
  • Mutation operation definitions
  • Field selections

@mock is not valid on fragment spreads, fragment definitions, inline fragments, or introspection fields.

Operation-Level Mocking

When @mock is applied to an operation definition, the entire response is generated by the configured LLM provider.

query GetInfo @mock(hint: "test data for development") {
  me {
    id
    name
  }
}

Field-Level Mocking

When @mock is applied to a field, that field and its full selection subtree are generated by the configured LLM provider.

query {
  me @mock(hint: "return a user named Alice") {
    id
    name
  }
}

Partial Mocking

When some fields are mocked and others are not, mockql fetches real upstream data for the non-mocked fields, generates mocked data for mocked fields, and merges the results.

query {
  topProducts(first: 5) {
    upc
    name
    reviews @mock(hint: "positive reviews from verified buyers") {
      id
      body
    }
  }
}

For the full working specification, see the repository source docs at docs/mock-specification.md.