Skip to content

t1k:nakama:mock

FieldValue
Modulebase
Version1.11.11
Effortlow
Tools—

Keywords: contract, mock, mock gameplay, MOCK_GAMEPLAY_ENDPOINTS, stub, test data

/t1k:nakama:mock

When MOCK_GAMEPLAY_ENDPOINTS=true, all gameplay RPCs return static mock responses instead of calling the real gRPC service. This enables frontend development without a running Gameplay backend.

Set env var MOCK_GAMEPLAY_ENDPOINTS=true in config.yml.tmpl or docker-compose.

Per endpoint, mock data resolves in priority order:

  1. TypeScript mock file: <mockDataDir>/<service>/<op>.ts — parsed from orion-contracts
  2. Contract JSON: <contractsDir>/<service>/client/<op>.response.json — examples[0]
  3. Inline fallback: Hardcoded JSON string in Go code

parseTSMockFile() converts TypeScript exports to JSON:

  1. Strip JS comments (string-aware to preserve URLs)
  2. Extract object/array literal after first = { or = [
  3. Replace new Date('...') → "..."
  4. Replace TypeScript enum references → string values
  5. Convert single-quoted strings → double-quoted
  6. Quote unquoted object keys
  7. Remove trailing commas
  8. Validate via json.Compact
rpcs := []rpc{
{
"service_v1_operation_name",
load("service/operation-name",
"service/client/operation-name.response.json",
`{"fallback":"data"}`),
},
}
  • Mock RPC name matches real RPC name exactly
  • TS mock file path follows <service>/<operation>.ts convention
  • Contract path follows <service>/client/<operation>.response.json
  • Inline fallback provides minimal valid JSON structure
  • Any new enum values added to tsEnumValues map
  • Mock works without contract files (fallback chain verified)