-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
base: main
Are you sure you want to change the base?
feat(Angular-query): add Angular auto-refetching example #8371
Conversation
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.
☁️ Nx Cloud ReportCI 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
✅ Successfully ran 1 targetSent with 💌 from NxCloud. |
…om:MatanShushan/query into feat/query-example-angular-auto-refetching
examples/angular/auto-refetching/.devcontainer/devcontainer.json
Outdated
Show resolved
Hide resolved
withDevtools(), | ||
), | ||
// Registers the MockApiInterceptor for simulating API calls | ||
{ |
There was a problem hiding this comment.
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
import type { Observable } from 'rxjs' | ||
|
||
@Injectable() | ||
export class MockApiInterceptor implements HttpInterceptor { |
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
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
Co-authored-by: Arnoud <[email protected]>
Co-authored-by: Arnoud <[email protected]>
Co-authored-by: Arnoud <[email protected]>
Co-authored-by: Arnoud <[email protected]>
Co-authored-by: Arnoud <[email protected]>
Co-authored-by: Arnoud <[email protected]>
Co-authored-by: Arnoud <[email protected]>
This pull request introduces an auto-refetching example, utilizing
@tanstack/angular-query-experimental
, similar to the existing React example.Key Features:
@tanstack/angular-query-experimental
.MockApiInterceptor
to simulate API calls (GET, POST, DELETE) for task management vialocalStorage
.@tanstack/angular-query-experimental
with Angular's dependency injection and HttpClient.How It Complements the Project:
@tanstack/angular-query-experimental
a practical and fully functional reference.Testing:
pnpm run dev
in theexamples/angular-auto-refetching
directory.localStorage
for demonstration.Notes: