Skip to content

Commit 2589791

Browse files
feat(react): useGetIdTokenQuery (#201)
* feat(react): add useUserGetIdTokenMutation * refactor: move forceRefresh to mutation args * chore: format * refactor(react): switch to useGetIdTokenQuery * docs: add docs for useGetIdTokenQuery and an example * fix: use tanstack v5 non-deprecated methods * fix: make requested changes according to review * chore: add changeset * docs: update useGetIdTokenQuery jsDoc and test docs * fix: change error type for useGetIdTokenQuery * refactor(react): use !== false for readability in useGetIdTokenQuery hook * refactor: improve queryKey in useGetIdTokenQuery --------- Co-authored-by: HassanBahati <mukisabahati@gmail.com>
1 parent 0031e98 commit 2589791

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+2624
-704
lines changed

.changeset/proud-rice-vanish.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@dataconnect/default-connector": minor
3+
"react-example": minor
4+
"useGetIdTokenQuery": minor
5+
"@tanstack-query-firebase/react": minor
6+
---
7+
8+
add useGetIdTokenQuery and update examples directory

.github/workflows/local-ci.yml

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
name: Local CI
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
quality:
8+
runs-on: ubuntu-latest
9+
timeout-minutes: 10
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v4
13+
14+
- name: Setup Node.js
15+
uses: actions/setup-node@v4
16+
with:
17+
node-version: "20"
18+
19+
- name: Enable Corepack
20+
run: corepack enable
21+
22+
- name: Get pnpm store directory
23+
id: pnpm-cache
24+
shell: bash
25+
run: |
26+
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
27+
28+
- name: Setup pnpm cache
29+
uses: actions/cache@v4
30+
with:
31+
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
32+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
33+
restore-keys: |
34+
${{ runner.os }}-pnpm-store-
35+
36+
- name: Install dependencies
37+
run: pnpm install
38+
39+
- name: Run format check
40+
run: pnpm format
41+
42+
test:
43+
runs-on: ubuntu-latest
44+
timeout-minutes: 30
45+
needs: quality
46+
steps:
47+
- name: Checkout code
48+
uses: actions/checkout@v4
49+
50+
- name: Setup Node.js
51+
uses: actions/setup-node@v4
52+
with:
53+
node-version: "20"
54+
registry-url: "https://registry.npmjs.org"
55+
56+
- name: Enable Corepack
57+
run: corepack enable
58+
59+
- name: Get pnpm store directory
60+
id: pnpm-cache
61+
shell: bash
62+
run: |
63+
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
64+
65+
- name: Setup pnpm cache
66+
uses: actions/cache@v4
67+
with:
68+
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
69+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
70+
restore-keys: |
71+
${{ runner.os }}-pnpm-store-
72+
73+
- name: Install dependencies
74+
run: pnpm install
75+
76+
- name: Install Java
77+
run: |
78+
sudo apt-get update
79+
sudo apt-get install -y openjdk-17-jdk
80+
java -version
81+
82+
- name: Install Firebase CLI
83+
uses: nick-invision/retry@v3
84+
with:
85+
timeout_minutes: 10
86+
retry_wait_seconds: 60
87+
max_attempts: 3
88+
command: npm i -g firebase-tools@14
89+
90+
# Build packages before testing
91+
- name: Build packages
92+
run: pnpm turbo build
93+
94+
# Verify build outputs
95+
- name: Verify build outputs
96+
run: |
97+
# Check all packages for dist directories
98+
MISSING_BUILDS=""
99+
for PKG_DIR in packages/*; do
100+
if [ -d "$PKG_DIR" ] && [ -f "$PKG_DIR/package.json" ]; then
101+
PKG_NAME=$(basename "$PKG_DIR")
102+
if [ ! -d "$PKG_DIR/dist" ]; then
103+
MISSING_BUILDS="$MISSING_BUILDS $PKG_NAME"
104+
fi
105+
fi
106+
done
107+
108+
if [ -n "$MISSING_BUILDS" ]; then
109+
echo "❌ Build outputs not found for: $MISSING_BUILDS"
110+
exit 1
111+
fi
112+
echo "✅ All build outputs verified"
113+
114+
# Run tests with all emulators (auth, firestore, and data-connect)
115+
- name: Run tests with emulator
116+
run: pnpm test:emulator

.github/workflows/tests.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ jobs:
8686
- name: Install dependencies
8787
run: pnpm install
8888

89+
- name: Install Java
90+
run: |
91+
sudo apt-get update
92+
sudo apt-get install -y openjdk-17-jdk
93+
java -version
94+
8995
- name: Install Firebase CLI
9096
uses: nick-invision/retry@v3
9197
with:
@@ -122,13 +128,13 @@ jobs:
122128
fi
123129
fi
124130
done
125-
131+
126132
if [ -n "$MISSING_BUILDS" ]; then
127133
echo "❌ Build outputs not found for: $MISSING_BUILDS"
128134
exit 1
129135
fi
130136
echo "✅ All build outputs verified"
131137
132-
# Run tests with emulator for changed packages
138+
# Run tests with all emulators (auth, firestore, and data-connect)
133139
- name: Run tests with emulator
134140
run: pnpm test:emulator
Lines changed: 57 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,126 +1,96 @@
1-
import {
2-
executeMutation,
3-
executeQuery,
4-
mutationRef,
5-
queryRef,
6-
validateArgs,
7-
} from "firebase/data-connect";
1+
import { queryRef, executeQuery, mutationRef, executeMutation, validateArgs } from 'firebase/data-connect';
82

93
export const connectorConfig = {
10-
connector: "default",
11-
service: "tanstack-query-firebase",
12-
location: "us-central1",
4+
connector: 'default',
5+
service: 'tanstack-query-firebase',
6+
location: 'us-central1'
137
};
148

9+
export const listMoviesRef = (dc) => {
10+
const { dc: dcInstance} = validateArgs(connectorConfig, dc, undefined);
11+
dcInstance._useGeneratedSdk();
12+
return queryRef(dcInstance, 'ListMovies');
13+
}
14+
listMoviesRef.operationName = 'ListMovies';
15+
16+
export function listMovies(dc) {
17+
return executeQuery(listMoviesRef(dc));
18+
}
19+
20+
export const getMovieByIdRef = (dcOrVars, vars) => {
21+
const { dc: dcInstance, vars: inputVars} = validateArgs(connectorConfig, dcOrVars, vars, true);
22+
dcInstance._useGeneratedSdk();
23+
return queryRef(dcInstance, 'GetMovieById', inputVars);
24+
}
25+
getMovieByIdRef.operationName = 'GetMovieById';
26+
27+
export function getMovieById(dcOrVars, vars) {
28+
return executeQuery(getMovieByIdRef(dcOrVars, vars));
29+
}
30+
31+
export const getMetaRef = (dc) => {
32+
const { dc: dcInstance} = validateArgs(connectorConfig, dc, undefined);
33+
dcInstance._useGeneratedSdk();
34+
return queryRef(dcInstance, 'GetMeta');
35+
}
36+
getMetaRef.operationName = 'GetMeta';
37+
38+
export function getMeta(dc) {
39+
return executeQuery(getMetaRef(dc));
40+
}
41+
1542
export const createMovieRef = (dcOrVars, vars) => {
16-
const { dc: dcInstance, vars: inputVars } = validateArgs(
17-
connectorConfig,
18-
dcOrVars,
19-
vars,
20-
true,
21-
);
43+
const { dc: dcInstance, vars: inputVars} = validateArgs(connectorConfig, dcOrVars, vars, true);
2244
dcInstance._useGeneratedSdk();
23-
return mutationRef(dcInstance, "CreateMovie", inputVars);
24-
};
25-
createMovieRef.operationName = "CreateMovie";
45+
return mutationRef(dcInstance, 'CreateMovie', inputVars);
46+
}
47+
createMovieRef.operationName = 'CreateMovie';
2648

2749
export function createMovie(dcOrVars, vars) {
2850
return executeMutation(createMovieRef(dcOrVars, vars));
2951
}
3052

3153
export const upsertMovieRef = (dcOrVars, vars) => {
32-
const { dc: dcInstance, vars: inputVars } = validateArgs(
33-
connectorConfig,
34-
dcOrVars,
35-
vars,
36-
true,
37-
);
54+
const { dc: dcInstance, vars: inputVars} = validateArgs(connectorConfig, dcOrVars, vars, true);
3855
dcInstance._useGeneratedSdk();
39-
return mutationRef(dcInstance, "UpsertMovie", inputVars);
40-
};
41-
upsertMovieRef.operationName = "UpsertMovie";
56+
return mutationRef(dcInstance, 'UpsertMovie', inputVars);
57+
}
58+
upsertMovieRef.operationName = 'UpsertMovie';
4259

4360
export function upsertMovie(dcOrVars, vars) {
4461
return executeMutation(upsertMovieRef(dcOrVars, vars));
4562
}
4663

4764
export const deleteMovieRef = (dcOrVars, vars) => {
48-
const { dc: dcInstance, vars: inputVars } = validateArgs(
49-
connectorConfig,
50-
dcOrVars,
51-
vars,
52-
true,
53-
);
65+
const { dc: dcInstance, vars: inputVars} = validateArgs(connectorConfig, dcOrVars, vars, true);
5466
dcInstance._useGeneratedSdk();
55-
return mutationRef(dcInstance, "DeleteMovie", inputVars);
56-
};
57-
deleteMovieRef.operationName = "DeleteMovie";
67+
return mutationRef(dcInstance, 'DeleteMovie', inputVars);
68+
}
69+
deleteMovieRef.operationName = 'DeleteMovie';
5870

5971
export function deleteMovie(dcOrVars, vars) {
6072
return executeMutation(deleteMovieRef(dcOrVars, vars));
6173
}
6274

6375
export const addMetaRef = (dc) => {
64-
const { dc: dcInstance } = validateArgs(connectorConfig, dc, undefined);
76+
const { dc: dcInstance} = validateArgs(connectorConfig, dc, undefined);
6577
dcInstance._useGeneratedSdk();
66-
return mutationRef(dcInstance, "AddMeta");
67-
};
68-
addMetaRef.operationName = "AddMeta";
78+
return mutationRef(dcInstance, 'AddMeta');
79+
}
80+
addMetaRef.operationName = 'AddMeta';
6981

7082
export function addMeta(dc) {
7183
return executeMutation(addMetaRef(dc));
7284
}
7385

7486
export const deleteMetaRef = (dcOrVars, vars) => {
75-
const { dc: dcInstance, vars: inputVars } = validateArgs(
76-
connectorConfig,
77-
dcOrVars,
78-
vars,
79-
true,
80-
);
87+
const { dc: dcInstance, vars: inputVars} = validateArgs(connectorConfig, dcOrVars, vars, true);
8188
dcInstance._useGeneratedSdk();
82-
return mutationRef(dcInstance, "DeleteMeta", inputVars);
83-
};
84-
deleteMetaRef.operationName = "DeleteMeta";
89+
return mutationRef(dcInstance, 'DeleteMeta', inputVars);
90+
}
91+
deleteMetaRef.operationName = 'DeleteMeta';
8592

8693
export function deleteMeta(dcOrVars, vars) {
8794
return executeMutation(deleteMetaRef(dcOrVars, vars));
8895
}
8996

90-
export const listMoviesRef = (dc) => {
91-
const { dc: dcInstance } = validateArgs(connectorConfig, dc, undefined);
92-
dcInstance._useGeneratedSdk();
93-
return queryRef(dcInstance, "ListMovies");
94-
};
95-
listMoviesRef.operationName = "ListMovies";
96-
97-
export function listMovies(dc) {
98-
return executeQuery(listMoviesRef(dc));
99-
}
100-
101-
export const getMovieByIdRef = (dcOrVars, vars) => {
102-
const { dc: dcInstance, vars: inputVars } = validateArgs(
103-
connectorConfig,
104-
dcOrVars,
105-
vars,
106-
true,
107-
);
108-
dcInstance._useGeneratedSdk();
109-
return queryRef(dcInstance, "GetMovieById", inputVars);
110-
};
111-
getMovieByIdRef.operationName = "GetMovieById";
112-
113-
export function getMovieById(dcOrVars, vars) {
114-
return executeQuery(getMovieByIdRef(dcOrVars, vars));
115-
}
116-
117-
export const getMetaRef = (dc) => {
118-
const { dc: dcInstance } = validateArgs(connectorConfig, dc, undefined);
119-
dcInstance._useGeneratedSdk();
120-
return queryRef(dcInstance, "GetMeta");
121-
};
122-
getMetaRef.operationName = "GetMeta";
123-
124-
export function getMeta(dc) {
125-
return executeQuery(getMetaRef(dc));
126-
}
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
{
2-
"type": "module"
3-
}
1+
{"type":"module"}

0 commit comments

Comments
 (0)