MCPcopy Create free account
hub / github.com/TanStack/query / PostsQueries

Class PostsQueries

examples/angular/basic/src/app/services/posts/queries.ts:9–29  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7 providedIn: 'root',
8})
9export class PostsQueries {
10 readonly #api = inject(PostsAPI)
11
12 all = () => ['posts'] as const
13
14 list = () =>
15 queryOptions({
16 queryKey: [...this.all(), 'list'] as const,
17 queryFn: () => lastValueFrom(this.#api.getPosts()),
18 })
19
20 detail = (id: number) =>
21 queryOptions({
22 queryKey: [...this.all(), 'detail', id] as const,
23 queryFn: (context) => {
24 // Cancels the request when component is destroyed before the request finishes
25 const abort$ = fromEvent(context.signal, 'abort')
26 return lastValueFrom(this.#api.getPost(id).pipe(takeUntil(abort$)))
27 },
28 })
29}

Callers

nothing calls this directly

Calls 1

queryOptionsFunction · 0.90

Tested by

no test coverage detected