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

Feature/angular query #6195

Merged
merged 45 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
3aad836
feat(angular-query): add Angular Query
arnoud-dv Oct 31, 2023
60fa4dd
Merge remote-tracking branch 'upstream/main' into feature/angular-query
arnoud-dv Nov 1, 2023
1b8efb6
feat(angular-query): integration test
arnoud-dv Nov 2, 2023
36f6138
fix(angular-query): PR feedback on QueryClientService injection
arnoud-dv Nov 2, 2023
78d1fbb
fix(angular-query): PR feedback
arnoud-dv Nov 3, 2023
8109ee8
chore(angular-query): update unit tests
arnoud-dv Nov 3, 2023
edfbfec
feat(angular-query): custom inject functions
arnoud-dv Nov 5, 2023
d6cf953
Merge remote-tracking branch 'upstream/main' into feature/angular-query
arnoud-dv Nov 6, 2023
d9e8e06
feat(angular-query): docs
arnoud-dv Nov 6, 2023
2d88bc8
Merge remote-tracking branch 'upstream/main' into feature/angular-query
arnoud-dv Nov 6, 2023
f4565d2
fix(angular-query): replace React context mention with Angular injector
arnoud-dv Nov 7, 2023
2014834
Merge remote-tracking branch 'upstream/main' into feature/angular-query
arnoud-dv Nov 7, 2023
8f35de3
fix(angular-query): re-add missing angular-query-experimental package…
arnoud-dv Nov 7, 2023
bb4d8c3
feat: updated angular version
eneajaho Nov 10, 2023
df1204e
feat: code improvements, DX improvements, fixed small doc example to …
eneajaho Nov 10, 2023
3c3a5f8
Update docs/angular/overview.md
eneajaho Nov 11, 2023
053d672
version fixes
eneajaho Nov 12, 2023
7963aea
feat: use proxy object to create single signals (computed) for query …
eneajaho Nov 12, 2023
d921be4
fix: docs
eneajaho Nov 12, 2023
89c22b8
Update packages/angular-query-experimental/src/query-proxy.ts
eneajaho Nov 13, 2023
526b917
Update packages/angular-query-experimental/src/query-proxy.ts
eneajaho Nov 13, 2023
f31ce9f
fix: add missing import
eneajaho Nov 13, 2023
bc05aa0
revert: use helper method for injectQueryClient
eneajaho Nov 13, 2023
e6a318d
Add Angular-CLI apps for testing
arnoud-dv Nov 13, 2023
4cd35cb
Add Angular-CLI apps for testing
eneajaho Nov 13, 2023
0c2a6ef
fix: useValue instead of useFactory
eneajaho Nov 13, 2023
e13d286
Merge pull request #1 from eneajaho/feature/angular-fixes
arnoud-dv Nov 13, 2023
42a78cf
fix(angular-query): examples
arnoud-dv Nov 13, 2023
d75774b
Merge remote-tracking branch 'upstream/main' into feature/angular-query
arnoud-dv Nov 13, 2023
7a84e8a
chore(angular-query): remove build script from angular 17 integration
arnoud-dv Nov 14, 2023
127480c
fix(angular-query): add sandbox config
arnoud-dv Nov 14, 2023
484417f
build working for angular-query-devtools-experimental
Nov 19, 2023
e52e456
fix(angular-query): improve development workflow
arnoud-dv Nov 19, 2023
e0e600b
Merge pull request #1 from arnoud-dv/pnpm-build-setup-fix
ducin Nov 19, 2023
63d8d7f
Merge pull request #3 from ducin/pnpm-build-setup-fix
arnoud-dv Nov 19, 2023
10931d4
fix(angular-query): downgrade vitest
arnoud-dv Nov 19, 2023
831d298
fix(angular-query): eslint and unit test typing fix
arnoud-dv Nov 19, 2023
a2cc2a4
Merge remote-tracking branch 'upstream/main' into feature/angular-query
arnoud-dv Nov 19, 2023
ce11402
fix(angular-query): test:ci fixes
arnoud-dv Nov 21, 2023
c6eccc6
fix(angular-query): relative workspace path to build dir
arnoud-dv Nov 22, 2023
aa38cd6
Merge remote-tracking branch 'upstream/main' into feature/angular-query
arnoud-dv Nov 28, 2023
b98bd3f
Merge remote-tracking branch 'upstream/main' into feature/angular-query
arnoud-dv Nov 29, 2023
9c2c79d
fix(angular-query): configure workspaces for top directories only
arnoud-dv Nov 30, 2023
c35419b
chore(angular-query): remove dead code found by Knip
arnoud-dv Nov 30, 2023
2af306d
Merge branch 'main' into feature/angular-query
TkDodo Dec 1, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .codesandbox/ci.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
"installCommand": "install:csb",
"buildCommand": "build:all",
"sandboxes": [
"/examples/angular/basic",
"/examples/react/basic-typescript",
"/examples/solid/basic-typescript",
"/examples/svelte/basic",
"/examples/vue/basic"
],
"packages": ["packages/**"],
"packages": ["packages/**", "!packages/angular*", "packages/angular-query-devtools-experimental/build", "packages/angular-query-experimental/build"],
"node": "18"
}
55 changes: 55 additions & 0 deletions docs/angular/devtools.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
id: devtools
title: Devtools
---

## Install and Import the Devtools

The devtools are a separate package that you need to install:

```bash
$ npm i @tanstack/angular-query-devtools-experimental
# or
$ pnpm add @tanstack/angular-query-devtools-experimental
# or
$ yarn add @tanstack/angular-query-devtools-experimental
```

You can import the devtools like this:

```typescript
import { AngularQueryDevtools } from '@tanstack/angular-query-devtools-experimental'
```

## Floating Mode

Floating Mode will mount the devtools as a fixed, floating element in your app and provide a toggle in the corner of the screen to show and hide the devtools. This toggle state will be stored and remembered in localStorage across reloads.

Place the following code as high in your Angular app as you can. The closer it is to the root of the page, the better it will work!

```typescript
import { AngularQueryDevtoolsComponent } from '@tanstack/angular-query-devtools-experimental'
import { Component } from '@angular/core';

@Component({
selector: 'app-root',
standalone: true,
imports: [AngularQueryDevtoolsComponent],
template: `
<angular-query-devtools initialIsOpen />
`,
})
```

### Options

- `initialIsOpen: Boolean`
- Set this `true` if you want the dev tools to default to being open
- `buttonPosition?: "top-left" | "top-right" | "bottom-left" | "bottom-right"`
- Defaults to `bottom-left`
- The position of the TanStack logo to open and close the devtools panel
- `position?: "top" | "bottom" | "left" | "right"`
- Defaults to `bottom`
- The position of the Angular Query devtools panel
- `client?: QueryClient`,
- Use this to use a custom QueryClient. Otherwise, the QueryClient provided through provideAngularQuery() will be injected.
20 changes: 20 additions & 0 deletions docs/angular/installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
id: installation
title: Installation
---

> VERY IMPORTANT: This library is currently in an experimental stage. This means that breaking changes will happen in minor AND patch releases. Use at your own risk. If you choose to rely on this in production in an experimental stage, please lock your version to a patch-level version to avoid unexpected breakages.
### NPM

Angular Query is compatible with Angular v16+.

```bash
$ npm i @tanstack/angular-query-experimental
# or
$ pnpm add @tanstack/angular-query-experimental
# or
$ yarn add @tanstack/angular-query-experimental
```

> Wanna give it a spin before you download? Try out the [simple](../examples/angular/simple) or [basic](../examples/angular/basic) examples!
68 changes: 68 additions & 0 deletions docs/angular/overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
id: overview
title: Overview
---

> VERY IMPORTANT: This library is currently in an experimental stage. This means that breaking changes will happen in minor AND patch releases. Use at your own risk. If you choose to rely on this in production in an experimental stage, please lock your version to a patch-level version to avoid unexpected breakages.

The `@tanstack/angular-query-experimental` package offers a 1st-class API for using TanStack Query via Angular.

## Feedback very welcome
We are in the process of getting to a stable API for Angular Query. If you have any feedback, please contact us at the [TanStack Discord](https://tlinz.com/discord) server or [visit this discussion](https://github.com/TanStack/query/discussions/6293) on Github.

## Versions of Angular supported
The adapter works with signals, which means it only supports Angular 16+

## Example

```typescript
import { AngularQueryDevtoolsComponent } from '@tanstack/angular-query-devtools-experimental'
import { ChangeDetectionStrategy, Component, inject } from '@angular/core'
import { HttpClient } from '@angular/common/http'
import { CommonModule } from '@angular/common'
import { injectQuery } from '@tanstack/angular-query-experimental'
import { lastValueFrom } from 'rxjs'

type Response = {
name: string
description: string
subscribers_count: number
stargazers_count: number
forks_count: number
}

@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
selector: 'simple-example',
standalone: true,
template: `
@if (query.isPending()) {
Loading...
}
@if (query.error()) {
An error has occurred: {{ query.error().message }}
}
@if (query.data(); as data) {
<h1>{{ data.name }}</h1>
<p>{{ data.description }}</p>
<strong>👀 {{ data.subscribers_count }}</strong>
<strong>✨ {{ data.stargazers_count }}</strong>
<strong>🍴 {{ data.forks_count }}</strong>
}

<angular-query-devtools initialIsOpen />
`,
imports: [AngularQueryDevtoolsComponent],
})
export class SimpleExampleComponent {
http = inject(HttpClient)

query = injectQuery(() => ({
queryKey: ['repoData'],
queryFn: () =>
lastValueFrom(
this.http.get<Response>('https://api.github.com/repos/tannerlinsley/react-query')
),
}))
}
```
72 changes: 72 additions & 0 deletions docs/angular/quick-start.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
id: quick-start
title: Quick Start
---

> VERY IMPORTANT: This library is currently in an experimental stage. This means that breaking changes will happen in minor AND patch releases. Use at your own risk. If you choose to rely on this in production in an experimental stage, please lock your version to a patch-level version to avoid unexpected breakages.

[//]: # 'Example'

If you're looking for a fully functioning example, please have a look at our [basic codesandbox example](../examples/angular/basic)

### Provide the client to your App

```typescript
bootstrapApplication(AppComponent, {
providers: [provideAngularQuery(new QueryClient())],
})
```

### Component with query and mutation

```typescript
import {
injectMutation,
injectQuery,
injectQueryClient
} from '@tanstack/angular-query-experimental'
import { getTodos, postTodo } from '../my-api'

@Component({
standalone: true,
template: `
<div>
<ul>
@for (todo of query().data) {
<li>{{ todo.title }}</li>
}
</ul>

<button (click)="onAddTodo()">Add Todo</button>
</div>
`,
})
export class TodosComponent {
queryClient = injectQueryClient()

query = injectQuery(() => ({
queryKey: ['todos'],
queryFn: getTodos
}))

mutation = injectMutation((client) => ({
mutationFn: postTodo,
onSuccess: () => {
// Invalidate and refetch by using the client directly
client.invalidateQueries({ queryKey: ['todos'] })

// OR use the queryClient that is injected into the component
this.queryClient.invalidateQueries({ queryKey: ['todos'] })
}
}))

onAddTodo() {
this.mutation().mutate({
id: Date.now(),
title: 'Do Laundry',
})
}
}
```

[//]: # 'Example'
24 changes: 24 additions & 0 deletions docs/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,30 @@
]
}
]
},
{"framework": "angular", "menuItems":[
{
"label": "Getting Started",
"children": [
{
"label": "Overview",
"to": "angular/overview"
},
{
"label": "Installation",
"to": "angular/installation"
},
{
"label": "Quick Start",
"to": "angular/quick-start"
},
{
"label": "Devtools",
"to": "angular/devtools"
}
]
}
]
}
],
"users": [
Expand Down
11 changes: 11 additions & 0 deletions examples/angular/basic/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// @ts-check

/** @type {import('eslint').Linter.Config} */
const config = {
parserOptions: {
tsconfigRootDir: __dirname,
project: './tsconfig.json',
},
}

module.exports = config
6 changes: 6 additions & 0 deletions examples/angular/basic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Basic example

To run this example:

- `npm install` or `yarn` or `pnpm i`
- `npm run dev` or `yarn dev` or `pnpm dev`
12 changes: 12 additions & 0 deletions examples/angular/basic/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Angular Query basic example</title>
</head>
<body>
<basic-example />
<script type="module" src="src/index.ts"></script>
</body>
</html>
30 changes: 30 additions & 0 deletions examples/angular/basic/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "@tanstack/query-example-angular-basic",
"private": true,
"type": "module",
"version": "0.0.0",
"description": "",
"scripts": {
"start": "vite",
"dev": "vite",
"build": "vite build",
"serve": "vite preview"
},
"license": "MIT",
"dependencies": {
"@angular/common": "^17.0.2",
"@angular/compiler": "^17.0.2",
"@angular/core": "^17.0.2",
"@angular/language-service": "^17.0.2",
"@angular/platform-browser": "^17.0.2",
"@tanstack/angular-query-experimental": "^5.0.0",
"@tanstack/angular-query-devtools-experimental": "^5.0.0",
"axios": "^1.5.1",
"rxjs": "^7.8.1",
"zone.js": "^0.14.2"
},
"devDependencies": {
"typescript": "^5.2.2",
"vite": "^4.5.0"
}
}
13 changes: 13 additions & 0 deletions examples/angular/basic/public/emblem-light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions examples/angular/basic/sandbox.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"container": {
"node": "18"
}
}
Loading