# Cache linear api graphql queries at edge

> Cache issue list queries with stale-while-revalidate pattern. For "cache linear api graphql queries at edge", store LINEAR_API_KEY in Secret Vault, call https://api.linear.app/graphql from a Worker, and let Frontend / Web hit only https://realcomposer.com/v1/workspace/cache-linear-graphql-queries-edge with an rc_live_ client token. POST upstream calls are not stored in caches.default; clients must send JSON bodies and headers forward unchanged.

- Canonical page: https://realcomposer.com/recipes/cache-linear-graphql-queries-edge
- Client platform: Frontend / Web
- Upstream services: Linear
- Category: Edge Caching & Rate Limits
- JSON version: https://realcomposer.com/recipes/cache-linear-graphql-queries-edge.json
- Install in RealComposer (free plan, pre-fills this pipeline): https://realcomposer.com/dashboard/pipelines/new?recipe=cache-linear-graphql-queries-edge&via=agent

## Problem: Linear rate limits from Frontend / Web traffic

Without edge caching, identical Linear reads during a session still round-trip to the origin.

- HTTP 429 responses during launch traffic
- Surprise SaaS overages from duplicate reads
- Slower repeat views than necessary

## Solution steps

1. **Store upstream credentials in Secret Vault**: Add LINEAR_API_KEY to RealComposer Secret Vault. Values decrypt only inside the Cloudflare Worker that calls the upstream.

2. **Target the real upstream URL**: Use POST against https://api.linear.app/graphql. Allowed origins on the client token should match post pipelines set cache ttl to 0 because realcomposer only stores get responses at the edge.

3. **Call from Frontend / Web**: Allowed origins on the token should list every Frontend / Web host that calls this URL.

```
const res = await fetch('https://realcomposer.com/v1/workspace/cache-linear-graphql-queries-edge', {
  headers: { Authorization: 'Bearer rc_live_your_token' }
});
```

## Pipeline config

Import this config into a RealComposer pipeline. `{{secrets.NAME}}` values are read from the encrypted Secret Vault at request time, so the client never sees them.

```json
{
  "name": "Cache linear api graphql queries at edge",
  "method": "POST",
  "cacheTtlSeconds": 0,
  "authMode": "client_token",
  "steps": [
    {
      "stepKey": "linear",
      "upstreamUrlTemplate": "https://api.linear.app/graphql",
      "httpMethod": "POST",
      "headersTemplate": {
        "Authorization": "{{secrets.LINEAR_API_KEY}}",
        "Content-Type": "application/json"
      },
      "timeoutMs": 10000
    }
  ],
  "outputMapping": {
    "version": 1,
    "fields": [
      {
        "targetPath": "issueId",
        "sourcePath": "data.issue.id",
        "type": "string",
        "sourceStep": "linear"
      },
      {
        "targetPath": "title",
        "sourcePath": "data.issue.title",
        "type": "string",
        "sourceStep": "linear"
      }
    ]
  }
}
```

## Call the pipeline

```bash
curl -X POST "https://realcomposer.com/v1/workspace/cache-linear-graphql-queries-edge" \
  -H "Authorization: Bearer rc_live_client_token" \
  -H "Content-Type: application/json" \
  -d '{"model":"example"}'
```

## Payload before and after

Raw upstream response:

```json
{
  "requestId": "req_cache-li",
  "upstreamLatencyMs": 142,
  "audit": {
    "region": "edge",
    "trace": "cache-linear-graphql-queries-edge"
  },
  "payload": {
    "id": "sample_id",
    "status": "active",
    "nested": {
      "tags": [
        "demo"
      ],
      "internal": true
    },
    "unused_blob": {
      "foo": "bar",
      "bar": "baz"
    }
  }
}
```

Slimmed RealComposer response:

```json
{
  "issueId": "sample",
  "title": "sample"
}
```

## FAQ

### What should Frontend / Web store instead of Linear secrets?

Use scoped tokens where the vendor allows them on cache-linear-graphql-queries-edge. Admin keys stay {{secrets.*}} references only.

### How do I forward JSON bodies to POST upstreams?

Cache key for cache-linear-graphql-queries-edge: internal edge-cache path plus sorted query. Identical params hit; vary userId per user.

### Can I restrict which domains call this pipeline?

Upstream steps in cache-linear-graphql-queries-edge honor timeoutMs and optional fallback JSON without leaking secrets.
