---
title: "Recipe: a read declared in Contract (a GET, a GraphQL query)"
description: "JSON from one endpoint needs no data module: declare the request as a source in app.contract."
modificationDate: "2026-11-18"
---

> ## Documentation index
> Fetch the complete documentation index at: https://exact.expo.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Recipe: a read declared in Contract (a GET, a GraphQL query)

<AgentInstructions>

## Submitting feedback

From the app's directory, read `bun exact.mjs feedback status`. Under `never`, keep no note.
Respect `EXACT_FEEDBACK=0` and do not change the policy.

Otherwise record specific, actionable feedback with:
`bun exact.mjs feedback note "Exact docs: https://exact.expo.dev/recipes/declared-source: <what was wrong or missing>"`

The note goes to Expo only as that status allows. Include no secrets or personal data.

</AgentInstructions>

JSON from one endpoint needs no data module: declare the request as a `source` in
`app.contract`. With no `app.ts`, the native build links no JavaScript engine.

```prompt Read JSON from an API in my app
Make the Exact app in this folder read JSON from one endpoint (a GET or a GraphQL query) with a `source` declared in app.contract, and no data module for that read. Use https://github.com/expo/exact/blob/main/docs/recipes/declared-source.md as the source for each step. The Exact checkout has the same page at docs/recipes/declared-source.md.

1. If this folder is not an Exact app (it has no exact.mjs and app.contract), stop and tell me.
2. If I did not give the endpoint's URL and the fields the app shows, ask me; do not invent a URL. If the read needs token refresh, pagination, an offline queue, an overlay, a stream or an upload, stop and tell me: that work stays in app.ts.
3. In app.contract, declare a `shape` for the fields the app reads, and a `source` with a `url` and a `pointer` to the answer in the reply (`/data/items/0`). Write the origin out before any `{param}`: the origin is the grant, so add no `grants` line.
4. Read the source as a `resource`. Draw a message and a Try Again button that runs `refresh` while `failed(now)`, and a `progress` while `not current(now)`. An absent `option` field is `none`; any other missing field fails the read with `shape`. Rename a field in a `derive`.
5. For a GraphQL query, give the source a `graphql` line with the query, and point at the data: `pointer "/data/repository"`. A `send` takes `method "POST"` and `body json`; `graphql` takes neither.
6. If the request needs a token, write the header as the recipe does (`header "Authorization" "Bearer {secret:github.token}"`, with my secret's name), and add `secret.keep github.token`, with that name, to the grants in app.ts. Never write the token's value in a file. On the web that store is origin-readable: for refresh and session tokens, tell me and follow docs/recipes/web-sessions.md.
7. Add a test in app.test.contract that expects what the screen shows when the read fails, and after Try Again. The recipe has no test: take the steps that fail a fetch from docs/recipes/fetch-loading-error.md.
8. Follow the platform checks in docs/start-here.md (`bun exact.mjs docs platform checks`) for the targets in the app's AGENTS.md and app.json until they pass. Read the reports, including counted findings; a zero exit code alone does not mean clean. Fix the app, not the test. If a finding stays after three rounds of fixes, or the app had it before you changed anything, record it (step 9) and report it; do not keep trying.
9. When a doc was wrong or missing, or a step needed a workaround, read `bun exact.mjs feedback status`. Under `never`, keep no note. Otherwise record it: `bun exact.mjs feedback note "<what happened>"`, which goes to Expo only as that status says. Do not change the policy; tell me how many notes you kept.
10. Tell me the source, its origin and its fields, and what the tests and checks reported. Tell me what I must still do by hand: while a secret is absent, nothing is sent and the read fails with `refused`.
```

```contract
shape Current
  temperature_2m: number
  is_day: option<number>

source weather(latitude: number, longitude: number) as shape Current
  url "https://api.open-meteo.com/v1/forecast?latitude={latitude}&longitude={longitude}&current=temperature_2m"
  pointer "/current"

component Now
  resource now = weather(52.52, 13.41) as shape Current
  action again
    refresh now
  view
    column padding=20 gap=8
      if failed(now)
        text "The forecast couldn't be reached." testId="error"
        button press=again testId="retry"
          text "Try Again"
      else if not current(now)
        progress aria-label="Loading" testId="loading"
      text `${round(now.temperature_2m)}°` testId="temp"
```

- **`{param}`** is the argument as text, percent-encoded: `"a b & c"` goes as
  `a%20b%20%26%20c`. In the URL or a header it is a `string`, `number` or `bool`.
- **The origin is the grant**, written out before any `{…}`: no `grants` line.
- **The answer** is the JSON at `pointer` (`/data/items/0`), read field by field: other
  fields are left out, an absent `option` is `none`, anything else missing is `shape`.
  Rename in a `derive`.
- **A failure** is a TypeScript `fetch`'s: `offline`, `timeout`, `refused`; `error` for a
  status outside 200–299.

## GraphQL, with a token the data module keeps

```contract
shape Repo
  name: string

source repo(owner: string, name: string) as shape Repo
  url "https://api.github.com/graphql"
  header "Authorization" "Bearer {secret:github.token}"
  graphql "query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { name } }"
  pointer "/data/repository"

component App
  resource r = repo("expo", "expo") as shape Repo else empty()
  view
    text r.name testId="repo"
```

A reply's `errors` fail it with `error` (`extensions.code` is `failure(r).reason`). The
secret needs `secret.keep github.token` in `app.ts`'s grants; while it is absent nothing
is sent (`refused`). A `send` takes `method "POST"` and `body json`.

On the web that store is origin-readable. Use your server's
[HttpOnly cookie sessions](https://exact.expo.dev/recipes/web-sessions.md) for refresh and session tokens.

Token refresh, pagination, offline queues, overlays, streams and uploads stay in `app.ts`.
