-
Notifications
You must be signed in to change notification settings - Fork 72
chore(docs): Docs Site For Angular #182
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
Merged
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
47cab3f
Fixed issue where updated variables weren't getting picked up
maneesht 5f83600
Completed docs site for angular
maneesht 210063f
Undid changes
maneesht 3407c1c
Undid package.json changes
maneesht 4611d07
Undid package.json changes
maneesht eede42c
Removed unnecessary changes
maneesht 189b427
Removed unnecessary changes
maneesht 5f258c5
s/functions/Functions
maneesht 3bf9158
Cleaned up docs a bit more
maneesht e553d49
Removed all hook references
maneesht ee8bbc2
Update docs/angular/data-connect/functions/injectDataConnectMutation.mdx
cabljac File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
docs/angular/data-connect/functions/injectDataConnectMutation.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
title: injectDataConnectMutation | ||
--- | ||
|
||
`injectDataConnectMutation` is an injector designed to simplify handling mutations (creating, updating, deleting) with Firebase Data Connect. | ||
|
||
See [mutations](/angular/data-connect/mutations) for more information. | ||
|
||
## Features | ||
|
||
- Simplifies mutation handling for <b>create</b>, <b>update</b>, and <b>delete</b> operations using Firebase Data Connect. | ||
- Provides <b>type-safe</b> handling of mutations based on your Firebase Data Connect schema. | ||
- Automatically manages <b>pending</b>, <b>success</b>, and <b>error</b> states for mutations. | ||
- Supports <b>optimistic updates</b> and <b>caching</b> to improve user experience and performance. | ||
|
||
## Usage | ||
|
||
```ts | ||
import { injectDataConnectMutation } from "@tanstack-query-firebase/angular/data-connect"; | ||
import { createMovieRef } from "@your-package-name/your-connector"; | ||
|
||
class AddMovieComponent() { | ||
createMovie = injectDataConnectMutation( | ||
createMovieRef | ||
); | ||
addMovie() { | ||
createMovie.mutate({ | ||
title: 'John Wick', | ||
genre: "Action", | ||
imageUrl: "https://example.com/image.jpg", | ||
}); | ||
} | ||
return ( | ||
<button | ||
disabled={createMovie.isPending()} | ||
(click)="addMovie()" | ||
> | ||
{{createMovie.isPending() ? "Creating..." : "Create Movie"}} | ||
</button> | ||
); | ||
} | ||
``` |
43 changes: 43 additions & 0 deletions
43
docs/angular/data-connect/functions/injectDataConnectQuery.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--- | ||
title: injectDataConnectQuery | ||
--- | ||
|
||
`injectDataConnectQuery` is an injector designed to simplify data fetching and state management with Firebase Data Connect. | ||
|
||
See [querying](/angular/data-connect/querying) for more information. | ||
|
||
## Features | ||
|
||
- Provides <b>type-safe</b> handling of queries based on the Firebase Data Connect schema. | ||
- Simplifies data fetching using Firebase Data Connect. | ||
- Automatically manages <b>loading</b>, <b>success</b>, and <b>error</b> states. | ||
- Supports <b>refetching data</b> with integrated <b>caching</b>. | ||
|
||
## Usage | ||
|
||
```ts | ||
import { injectDataConnectQuery } from '@tanstack-query-firebase/angular/data-connect'; | ||
import { listMoviesRef } from "@your-package-name/your-connector"; | ||
|
||
// class | ||
export class MovieListComponent { | ||
movies = injectDataConnectQuery(listMoviesRef()); | ||
} | ||
|
||
// template | ||
@if (movies.isPending()) { | ||
Loading... | ||
} | ||
@if (movies.error()) { | ||
An error has occurred: {{ movies.error() }} | ||
} | ||
@if (movies.data(); as data) { | ||
@for (movie of data.movies; track movie.id) { | ||
<mat-card appearance="outlined"> | ||
<mat-card-content>{{movie.description}}</mat-card-content> | ||
</mat-card> | ||
} @empty { | ||
<h2>No items!</h2> | ||
} | ||
} | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
--- | ||
title: Firebase Data Connect | ||
--- | ||
|
||
Firebase Data Connect is a relational database service for mobile and web apps that lets you build and scale using a fully-managed PostgreSQL database powered by Cloud SQL. It provides secure schema, query and mutation management using GraphQL technology that integrates well with Firebase Authentication. | ||
|
||
To get started, ensure you have setup your Firebase project and have the Data Connect setup in your project. To learn more, | ||
follow the [Firebase Data Connect documentation](https://firebase.google.com/docs/data-connect/quickstart). | ||
|
||
## Setup | ||
|
||
Before using the Tanstack Query Firebase injectors for Data Connect, ensure you have configured your application using your chosen connector: | ||
|
||
```ts | ||
// app.config.ts | ||
export const appConfig: ApplicationConfig = { | ||
providers: [ | ||
... | ||
provideFirebaseApp(() => | ||
initializeApp(/*Replace with your firebase config*/) | ||
), | ||
provideDataConnect(() => getDataConnect(connectorConfig)), | ||
provideTanStackQuery(new QueryClient()), | ||
], | ||
}; | ||
``` | ||
|
||
## Importing | ||
|
||
The package exports are available via the `@tanstack-query-firebase/angular` package under the `data-connect` namespace: | ||
|
||
```ts | ||
import { injectDataConnectQuery } from "@tanstack-query-firebase/angular/data-connect"; | ||
``` | ||
|
||
## Basic Usage | ||
|
||
To use the Tanstack Query Firebase injectors, you can either use the generated SDKs, or the `injectDataConnectQuery` injector to fetch data from the database: | ||
|
||
### Using the Generated SDK | ||
|
||
The generated SDK reduces the boilerplate required to use Tanstack Query Firebase's injectors. Instead of having to provide a ref to `injectDataConnectQuery`, you simply need to call the generated | ||
injector function like so: | ||
|
||
```ts | ||
import { injectListMyPosts } from '@firebasegen/posts/angular' | ||
|
||
@Component({ | ||
... | ||
template: ` | ||
@if (posts.isPending()) { | ||
Loading... | ||
} | ||
@if (posts.error()) { | ||
An error has occurred: {{ posts.error() }} | ||
} | ||
@if (posts.data(); as data) { | ||
@for (post of data.posts; track post.id) { | ||
<mat-card appearance="outlined"> | ||
<mat-card-content>{{post.description}}</mat-card-content> | ||
</mat-card> | ||
} @empty { | ||
<h2>No items!</h2> | ||
} | ||
} | ||
`, | ||
}) | ||
export class PostListComponent { | ||
// Calls `injectDataConnectQuery` with the corresponding types. | ||
posts = injectListMyPosts(); | ||
} | ||
``` | ||
|
||
### Using `injectDataConnectQuery` | ||
|
||
Alternatively, you can use the `injectDataConnectQuery` injector. To use this, you need to pass the Response and Data generics: | ||
|
||
```ts | ||
import { injectDataConnectQuery } from "@tanstack-query-firebase/angular"; | ||
import { listMoviesRef } from "@firebasegen/posts"; | ||
|
||
@Component({ | ||
... | ||
template: ` | ||
@if (posts.isPending()) { | ||
Loading... | ||
} | ||
@if (posts.error()) { | ||
An error has occurred: {{ posts.error() }} | ||
} | ||
@if (posts.data(); as data) { | ||
@for (post of data.posts; track post.id) { | ||
<mat-card appearance="outlined"> | ||
<mat-card-content>{{post.description}}</mat-card-content> | ||
</mat-card> | ||
} @empty { | ||
<h2>No items!</h2> | ||
} | ||
} | ||
`, | ||
}) | ||
export class PostListComponent { | ||
// Calls `injectDataConnectQuery` with the corresponding types. | ||
// Alternatively: | ||
// injectDataConnectQuery(queryRef<ListMoviesData, ListMoviesResponse>(dc, 'ListMovies')) | ||
posts = injectDataConnectQuery(listMoviesRef()); | ||
} | ||
``` | ||
|
||
The injectors will automatically infer the data type from the connector and the query and automtically create a [query key](https://tanstack.com/query/latest/docs/framework/angular/guides/query-keys) for the query. | ||
|
||
## Learning more | ||
|
||
To learn more about the Data Connect functions, check out the following pages: | ||
|
||
- [Querying](/angular/data-connect/querying) | ||
- [Mutations](/angular/data-connect/mutations) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
--- | ||
title: Mutations | ||
description: Learn how to mutate data in Firebase Data Connect using the Tanstack Query Firebase injectors. | ||
--- | ||
|
||
## Mutating Data | ||
|
||
To mutate data in Firebase Data Connect, you can either use the generated injectors, or use the `injectDataConnectMutation` injector. | ||
|
||
```ts | ||
import { injectCreateMovie } from "@firebasegen/movies/angular"; | ||
|
||
@Component({ | ||
... | ||
template: ` | ||
<button | ||
disabled={createMovie.isPending()} | ||
(click)="addMovie()" | ||
> | ||
{{createMovie.isPending() ? "Creating..." : "Create Movie"}} | ||
</button> | ||
` | ||
}) | ||
class AddMovieComponent() { | ||
cabljac marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Calls `injectDataConnectMutation` with the respective types. | ||
// Alternatively: | ||
// import { injectDataConnectMutation } from '@tanstack-query-firebase/angular/data-connect'; | ||
// ... | ||
// createMovie = injectDataConnectMutation(createMovieRef); | ||
createMovie = injectCreateMovie(); | ||
addMovie() { | ||
createMovie.mutate({ | ||
title: 'John Wick', | ||
genre: "Action", | ||
imageUrl: "https://example.com/image.jpg", | ||
}); | ||
} | ||
} | ||
``` | ||
|
||
Additionally, you can provide a factory function to the mutation, which will be called with the mutation variables: | ||
|
||
```ts | ||
createMovie = injectDataConnectMutation(undefined, () => ({ | ||
mutationFn: (title: string) => createMovieRef({ title, reviewDate: Date.now() }) | ||
})); | ||
|
||
// ... | ||
createMovie.mutate("John Wick"); | ||
``` | ||
|
||
## Invalidating Queries | ||
|
||
The function provides an additional [mutation option](https://tanstack.com/query/latest/docs/framework/angular/reference/functions/injectMutation) called `invalidate`. This option accepts a list of query references which will be automatically invalidated when the mutation is successful. | ||
|
||
You can also provide explicit references to the invalidate array, for example: | ||
|
||
```ts | ||
const createMovie = injectDataConnectMutation(createMovieRef, { | ||
invalidate: [getMovieRef({ id: "1" })], | ||
}); | ||
``` | ||
|
||
In this case only the query reference `getMovieRef({ id: "1" })` will be invalidated. | ||
|
||
## Overriding the mutation key | ||
|
||
### Metadata | ||
|
||
Along with the data, the function will also return the `ref`, `source`, and `fetchTime` metadata from the mutation. | ||
|
||
```ts | ||
const createMovie = injectDataConnectMutation(createMovieRef); | ||
|
||
await createMovie.mutateAsync({ | ||
title: 'John Wick', | ||
genre: "Action", | ||
imageUrl: "https://example.com/image.jpg", | ||
}); | ||
|
||
console.log(createMovie.dataConnectResult().ref); | ||
console.log(createMovie.dataConnectResult().source); | ||
console.log(createMovie.dataConnectResult().fetchTime); | ||
``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.