Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Angular-query): add Angular auto-refetching example #8371

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

MatanShushan
Copy link

This pull request introduces an auto-refetching example, utilizing @tanstack/angular-query-experimental, similar to the existing React example.

Key Features:

  • Demonstrates auto-refetching capabilities in Angular with @tanstack/angular-query-experimental.
  • Implements a MockApiInterceptor to simulate API calls (GET, POST, DELETE) for task management via localStorage.
  • Integrates @tanstack/angular-query-experimental with Angular's dependency injection and HttpClient.
  • Provides a seamless testing experience without requiring a real backend.

How It Complements the Project:

  • Adds an Angular implementation to complement the existing React auto-refetching example.
  • Offers users of @tanstack/angular-query-experimental a practical and fully functional reference.

Testing:

  • The example has been tested locally using pnpm run dev in the examples/angular-auto-refetching directory.
  • Mock task data is preloaded into localStorage for demonstration.

Notes:

  • Feedback is welcome for further refinements or feature additions.

Implement an example showcasing auto-refetching in Angular using TanStack Query. Includes a mock API interceptor to simulate HTTP calls for tasks.
Implement an example showcasing auto-refetching in Angular using TanStack Query. Includes a mock API interceptor to simulate HTTP calls for tasks.
@MatanShushan MatanShushan changed the title feat(examples): add Angular auto-refetching example feat(Angular query): add Angular auto-refetching example Nov 28, 2024
@MatanShushan MatanShushan changed the title feat(Angular query): add Angular auto-refetching example feat(Angular-query): add Angular auto-refetching example Nov 28, 2024
Copy link

nx-cloud bot commented Nov 28, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 35cfce6. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


🟥 Failed Commands
nx affected --targets=test:sherif,test:knip,test:eslint,test:lib,test:types,test:build,build --parallel=3
✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

@arnoud-dv arnoud-dv self-assigned this Nov 30, 2024
Copy link

pkg-pr-new bot commented Nov 30, 2024

Open in Stackblitz

More templates

@tanstack/angular-query-devtools-experimental

npm i https://pkg.pr.new/@tanstack/angular-query-devtools-experimental@8371

@tanstack/angular-query-experimental

npm i https://pkg.pr.new/@tanstack/angular-query-experimental@8371

@tanstack/query-async-storage-persister

npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@8371

@tanstack/query-broadcast-client-experimental

npm i https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@8371

@tanstack/eslint-plugin-query

npm i https://pkg.pr.new/@tanstack/eslint-plugin-query@8371

@tanstack/query-core

npm i https://pkg.pr.new/@tanstack/query-core@8371

@tanstack/query-devtools

npm i https://pkg.pr.new/@tanstack/query-devtools@8371

@tanstack/query-persist-client-core

npm i https://pkg.pr.new/@tanstack/query-persist-client-core@8371

@tanstack/query-sync-storage-persister

npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@8371

@tanstack/react-query

npm i https://pkg.pr.new/@tanstack/react-query@8371

@tanstack/react-query-devtools

npm i https://pkg.pr.new/@tanstack/react-query-devtools@8371

@tanstack/react-query-next-experimental

npm i https://pkg.pr.new/@tanstack/react-query-next-experimental@8371

@tanstack/react-query-persist-client

npm i https://pkg.pr.new/@tanstack/react-query-persist-client@8371

@tanstack/solid-query

npm i https://pkg.pr.new/@tanstack/solid-query@8371

@tanstack/solid-query-devtools

npm i https://pkg.pr.new/@tanstack/solid-query-devtools@8371

@tanstack/solid-query-persist-client

npm i https://pkg.pr.new/@tanstack/solid-query-persist-client@8371

@tanstack/svelte-query

npm i https://pkg.pr.new/@tanstack/svelte-query@8371

@tanstack/svelte-query-devtools

npm i https://pkg.pr.new/@tanstack/svelte-query-devtools@8371

@tanstack/svelte-query-persist-client

npm i https://pkg.pr.new/@tanstack/svelte-query-persist-client@8371

@tanstack/vue-query

npm i https://pkg.pr.new/@tanstack/vue-query@8371

@tanstack/vue-query-devtools

npm i https://pkg.pr.new/@tanstack/vue-query-devtools@8371

commit: 35cfce6

examples/angular/auto-refetching/package.json Outdated Show resolved Hide resolved
withDevtools(),
),
// Registers the MockApiInterceptor for simulating API calls
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use a functional interceptor and withInterceptors instead? See the rxjs example

examples/angular/auto-refetching/src/app/app.config.ts Outdated Show resolved Hide resolved
import type { Observable } from 'rxjs'

@Injectable()
export class MockApiInterceptor implements HttpInterceptor {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Angular documentation recommends functional interceptors

Prefer withInterceptors and functional interceptors instead, as support for DI-provided interceptors may be phased out in a later release.

* Fetches all tasks from the API.
* Returns an observable containing an array of task strings.
*/
allTasks$ = () => this.#http.get<Array<string>>('/api/tasks')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency with mutationOptions in this same file it would be nice to use queryOptions here

examples/angular/auto-refetching/src/index.html Outdated Show resolved Hide resolved
examples/angular/auto-refetching/tsconfig.json Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants