> For the complete documentation index, see [llms.txt](https://whitepaper.gmr.center/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://whitepaper.gmr.center/gmr-center/leet-lotto/the-graph-integration.md).

# The Graph Integration

[Visit The Graph](https://thegraph.com)

Every ticket, draw and prize moves through a dedicated subgraph for fast, queryable data.

### Data Flow

1. **Smart Contracts** emit events (`TicketBought`, `WinnerDeclared`).
2. **Subgraph Mapping** ingests events and writes to indexed entities.
3. **Frontend** uses `@tanstack/react-query` to hit the GraphQL endpoint and cache results.

```typescript
// ⚠️ Simplified example
export const useActiveLottos = () =>
  useQuery({
    queryKey: ["lottos", "active"],
    queryFn: getActiveLottos() // Graph query function
    refetchInterval: 30000, // 30 s
  });
```

#### Benefits

* <30 s dashboard refresh
* Zero over-fetching – only pull the fields you need
* Seamless optimistic updates on ticket purchase
