# 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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://whitepaper.gmr.center/gmr-center/leet-lotto/the-graph-integration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
