Skip to content

Commit 6594c9a

Browse files
the-gigi-apollothe-gigimabuyo
authored
[dxm-362] add docs for @cacheTag (#3353)
ref DXM-362 add docs for @cacheTag --------- Co-authored-by: Gigi Sayfan <[email protected]> Co-authored-by: Michelle Mabuyo <[email protected]>
1 parent 3f21cbf commit 6594c9a

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

docs/source/schema-design/federated-schemas/reference/directives.mdx

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,72 @@ The default value is `true`.
11641164
</tbody>
11651165
</table>
11661166

1167+
## Managing cache invalidation
1168+
1169+
### `@cacheTag`
1170+
1171+
<MinVersionBadge version="Federation v2.12" />
1172+
1173+
```graphql
1174+
directive @cacheTag(format: String!) repeatable on FIELD_DEFINITION | OBJECT
1175+
```
1176+
1177+
Assigns cache tags to cached data in the Apollo Router for [active cache invalidation](/graphos/routing/performance/caching/response-caching/invalidation#active-invalidation). Use cache tags to remove specific cached entries on demand when data changes, instead of waiting for time-to-live (TTL) expiration.
1178+
1179+
```graphql {6-7, 10}
1180+
extend schema
1181+
@link(url: "https://specs.apollo.dev/federation/v2.12",
1182+
import: ["@key", "@cacheTag"])
1183+
1184+
type Query {
1185+
users: [User!]! @cacheTag(format: "users-list")
1186+
user(id: ID!): User @cacheTag(format: "user-{$args.id}")
1187+
}
1188+
1189+
type User @key(fields: "id") @cacheTag(format: "user-{$key.id}") {
1190+
id: ID!
1191+
name: String!
1192+
}
1193+
```
1194+
1195+
#### Arguments
1196+
1197+
<table class="field-table">
1198+
<thead>
1199+
<tr>
1200+
<th>Name /<br/>Type</th>
1201+
<th>Description</th>
1202+
</tr>
1203+
</thead>
1204+
1205+
<tbody>
1206+
1207+
<tr class="required">
1208+
<td>
1209+
1210+
##### `format`
1211+
1212+
`String!`
1213+
1214+
</td>
1215+
<td>
1216+
1217+
**Required.** A string template that defines the cache tag. Can include interpolated variables:
1218+
- For root fields: `{$args.fieldName}` to interpolate field arguments
1219+
- For entities: `{$key.fieldName}` to interpolate entity key fields
1220+
1221+
Interpolated variables must be either a scalar or enum type.
1222+
1223+
<MinVersionBadge version="Router v2.8.2" />
1224+
1225+
</td>
1226+
</tr>
1227+
1228+
</tbody>
1229+
</table>
1230+
1231+
For details on applying cache invalidation with cache tags, see [Response cache invalidation](/graphos/routing/performance/caching/response-caching/invalidation#by-cache-tag).
1232+
11671233
## Connectors
11681234

11691235
<MinVersionBadge version="Federation v2.10" />

0 commit comments

Comments
 (0)