Skip to content

Commit

Permalink
TanStack Query Firebase + Data Connect
Browse files Browse the repository at this point in the history
  • Loading branch information
HassanBahati committed Dec 17, 2024
1 parent f0cb9e7 commit b5afb80
Show file tree
Hide file tree
Showing 1,034 changed files with 8,532 additions and 0 deletions.
6 changes: 6 additions & 0 deletions react/firebase-dataconnect-movies/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
VITE_FIREBASE_API_KEY="AIzaSyA3vIUtFlnNSuS_wNo5_aTYduLiGNeSzdE"
VITE_FIREBASE_AUTH_DOMAIN="fdc-movies-app.firebaseapp.com"
VITE_FIREBASE_PROJECT_ID="fdc-movies-app"
VITE_FIREBASE_STORAGE_BUCKET="fdc-movies-app.firebasestorage.app"
VITE_FIREBASE_MESSAGING_SENDER_ID="154156738817"
VITE_FIREBASE_APP_ID="1:154156738817:web:77e3a7c25126f8991a5300"
1 change: 1 addition & 0 deletions react/firebase-dataconnect-movies/.firebase/.graphqlrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"schema":["../dataconnect/schema/**/*.gql","../dataconnect/.dataconnect/**/*.gql"],"document":["../dataconnect/connector/**/*.gql"]}
7 changes: 7 additions & 0 deletions react/firebase-dataconnect-movies/.firebaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"projects": {
"default": "fdc-movies-app"
},
"targets": {},
"etags": {}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions react/firebase-dataconnect-movies/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
9 changes: 9 additions & 0 deletions react/firebase-dataconnect-movies/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# TanStack Query Firebase + Data Connect

![alt text](.github/image1.png)

A react app that leverages `useConnectQuery` and `useConnectMutation` from TanStack Query Firebase to perform CRUD operations to Firebase Data Connect.

## Final Result

![alt text](.github/image2.png)
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import { getDataConnect, queryRef, executeQuery, mutationRef, executeMutation, validateArgs } from 'firebase/data-connect';

export const connectorConfig = {
connector: 'default',
service: 'firebase-dataconnect-movies',
location: 'us-central1'
};

export function createMovieRef(dcOrVars, vars) {
const { dc: dcInstance, vars: inputVars} = validateArgs(connectorConfig, dcOrVars, vars, true);
if('_useGeneratedSdk' in dcInstance) {
dcInstance._useGeneratedSdk();
} else {
console.error('Please update to the latest version of the Data Connect SDK by running `npm install firebase@dataconnect-preview`.');
}
return mutationRef(dcInstance, 'CreateMovie', inputVars);
}
export function createMovie(dcOrVars, vars) {
return executeMutation(createMovieRef(dcOrVars, vars));
}
export function upsertUserRef(dcOrVars, vars) {
const { dc: dcInstance, vars: inputVars} = validateArgs(connectorConfig, dcOrVars, vars, true);
if('_useGeneratedSdk' in dcInstance) {
dcInstance._useGeneratedSdk();
} else {
console.error('Please update to the latest version of the Data Connect SDK by running `npm install firebase@dataconnect-preview`.');
}
return mutationRef(dcInstance, 'UpsertUser', inputVars);
}
export function upsertUser(dcOrVars, vars) {
return executeMutation(upsertUserRef(dcOrVars, vars));
}
export function deleteMovieRef(dcOrVars, vars) {
const { dc: dcInstance, vars: inputVars} = validateArgs(connectorConfig, dcOrVars, vars, true);
if('_useGeneratedSdk' in dcInstance) {
dcInstance._useGeneratedSdk();
} else {
console.error('Please update to the latest version of the Data Connect SDK by running `npm install firebase@dataconnect-preview`.');
}
return mutationRef(dcInstance, 'DeleteMovie', inputVars);
}
export function deleteMovie(dcOrVars, vars) {
return executeMutation(deleteMovieRef(dcOrVars, vars));
}
export function addReviewRef(dcOrVars, vars) {
const { dc: dcInstance, vars: inputVars} = validateArgs(connectorConfig, dcOrVars, vars, true);
if('_useGeneratedSdk' in dcInstance) {
dcInstance._useGeneratedSdk();
} else {
console.error('Please update to the latest version of the Data Connect SDK by running `npm install firebase@dataconnect-preview`.');
}
return mutationRef(dcInstance, 'AddReview', inputVars);
}
export function addReview(dcOrVars, vars) {
return executeMutation(addReviewRef(dcOrVars, vars));
}
export function deleteReviewRef(dcOrVars, vars) {
const { dc: dcInstance, vars: inputVars} = validateArgs(connectorConfig, dcOrVars, vars, true);
if('_useGeneratedSdk' in dcInstance) {
dcInstance._useGeneratedSdk();
} else {
console.error('Please update to the latest version of the Data Connect SDK by running `npm install firebase@dataconnect-preview`.');
}
return mutationRef(dcInstance, 'DeleteReview', inputVars);
}
export function deleteReview(dcOrVars, vars) {
return executeMutation(deleteReviewRef(dcOrVars, vars));
}
export function listMoviesRef(dc) {
const { dc: dcInstance} = validateArgs(connectorConfig, dc, undefined);
if('_useGeneratedSdk' in dcInstance) {
dcInstance._useGeneratedSdk();
} else {
console.error('Please update to the latest version of the Data Connect SDK by running `npm install firebase@dataconnect-preview`.');
}
return queryRef(dcInstance, 'ListMovies');
}
export function listMovies(dc) {
return executeQuery(listMoviesRef(dc));
}
export function listUsersRef(dc) {
const { dc: dcInstance} = validateArgs(connectorConfig, dc, undefined);
if('_useGeneratedSdk' in dcInstance) {
dcInstance._useGeneratedSdk();
} else {
console.error('Please update to the latest version of the Data Connect SDK by running `npm install firebase@dataconnect-preview`.');
}
return queryRef(dcInstance, 'ListUsers');
}
export function listUsers(dc) {
return executeQuery(listUsersRef(dc));
}
export function listUserReviewsRef(dc) {
const { dc: dcInstance} = validateArgs(connectorConfig, dc, undefined);
if('_useGeneratedSdk' in dcInstance) {
dcInstance._useGeneratedSdk();
} else {
console.error('Please update to the latest version of the Data Connect SDK by running `npm install firebase@dataconnect-preview`.');
}
return queryRef(dcInstance, 'ListUserReviews');
}
export function listUserReviews(dc) {
return executeQuery(listUserReviewsRef(dc));
}
export function getMovieByIdRef(dcOrVars, vars) {
const { dc: dcInstance, vars: inputVars} = validateArgs(connectorConfig, dcOrVars, vars, true);
if('_useGeneratedSdk' in dcInstance) {
dcInstance._useGeneratedSdk();
} else {
console.error('Please update to the latest version of the Data Connect SDK by running `npm install firebase@dataconnect-preview`.');
}
return queryRef(dcInstance, 'GetMovieById', inputVars);
}
export function getMovieById(dcOrVars, vars) {
return executeQuery(getMovieByIdRef(dcOrVars, vars));
}
export function searchMovieRef(dcOrVars, vars) {
const { dc: dcInstance, vars: inputVars} = validateArgs(connectorConfig, dcOrVars, vars);
if('_useGeneratedSdk' in dcInstance) {
dcInstance._useGeneratedSdk();
} else {
console.error('Please update to the latest version of the Data Connect SDK by running `npm install firebase@dataconnect-preview`.');
}
return queryRef(dcInstance, 'SearchMovie', inputVars);
}
export function searchMovie(dcOrVars, vars) {
return executeQuery(searchMovieRef(dcOrVars, vars));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type":"module"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
const { getDataConnect, queryRef, executeQuery, mutationRef, executeMutation, validateArgs } = require('firebase/data-connect');

const connectorConfig = {
connector: 'default',
service: 'firebase-dataconnect-movies',
location: 'us-central1'
};
exports.connectorConfig = connectorConfig;

function createMovieRef(dcOrVars, vars) {
const { dc: dcInstance, vars: inputVars} = validateArgs(connectorConfig, dcOrVars, vars, true);
if('_useGeneratedSdk' in dcInstance) {
dcInstance._useGeneratedSdk();
} else {
console.error('Please update to the latest version of the Data Connect SDK by running `npm install firebase@dataconnect-preview`.');
}
return mutationRef(dcInstance, 'CreateMovie', inputVars);
}
exports.createMovieRef = createMovieRef;
exports.createMovie = function createMovie(dcOrVars, vars) {
return executeMutation(createMovieRef(dcOrVars, vars));
};

function upsertUserRef(dcOrVars, vars) {
const { dc: dcInstance, vars: inputVars} = validateArgs(connectorConfig, dcOrVars, vars, true);
if('_useGeneratedSdk' in dcInstance) {
dcInstance._useGeneratedSdk();
} else {
console.error('Please update to the latest version of the Data Connect SDK by running `npm install firebase@dataconnect-preview`.');
}
return mutationRef(dcInstance, 'UpsertUser', inputVars);
}
exports.upsertUserRef = upsertUserRef;
exports.upsertUser = function upsertUser(dcOrVars, vars) {
return executeMutation(upsertUserRef(dcOrVars, vars));
};

function deleteMovieRef(dcOrVars, vars) {
const { dc: dcInstance, vars: inputVars} = validateArgs(connectorConfig, dcOrVars, vars, true);
if('_useGeneratedSdk' in dcInstance) {
dcInstance._useGeneratedSdk();
} else {
console.error('Please update to the latest version of the Data Connect SDK by running `npm install firebase@dataconnect-preview`.');
}
return mutationRef(dcInstance, 'DeleteMovie', inputVars);
}
exports.deleteMovieRef = deleteMovieRef;
exports.deleteMovie = function deleteMovie(dcOrVars, vars) {
return executeMutation(deleteMovieRef(dcOrVars, vars));
};

function addReviewRef(dcOrVars, vars) {
const { dc: dcInstance, vars: inputVars} = validateArgs(connectorConfig, dcOrVars, vars, true);
if('_useGeneratedSdk' in dcInstance) {
dcInstance._useGeneratedSdk();
} else {
console.error('Please update to the latest version of the Data Connect SDK by running `npm install firebase@dataconnect-preview`.');
}
return mutationRef(dcInstance, 'AddReview', inputVars);
}
exports.addReviewRef = addReviewRef;
exports.addReview = function addReview(dcOrVars, vars) {
return executeMutation(addReviewRef(dcOrVars, vars));
};

function deleteReviewRef(dcOrVars, vars) {
const { dc: dcInstance, vars: inputVars} = validateArgs(connectorConfig, dcOrVars, vars, true);
if('_useGeneratedSdk' in dcInstance) {
dcInstance._useGeneratedSdk();
} else {
console.error('Please update to the latest version of the Data Connect SDK by running `npm install firebase@dataconnect-preview`.');
}
return mutationRef(dcInstance, 'DeleteReview', inputVars);
}
exports.deleteReviewRef = deleteReviewRef;
exports.deleteReview = function deleteReview(dcOrVars, vars) {
return executeMutation(deleteReviewRef(dcOrVars, vars));
};

function listMoviesRef(dc) {
const { dc: dcInstance} = validateArgs(connectorConfig, dc, undefined);
if('_useGeneratedSdk' in dcInstance) {
dcInstance._useGeneratedSdk();
} else {
console.error('Please update to the latest version of the Data Connect SDK by running `npm install firebase@dataconnect-preview`.');
}
return queryRef(dcInstance, 'ListMovies');
}
exports.listMoviesRef = listMoviesRef;
exports.listMovies = function listMovies(dc) {
return executeQuery(listMoviesRef(dc));
};

function listUsersRef(dc) {
const { dc: dcInstance} = validateArgs(connectorConfig, dc, undefined);
if('_useGeneratedSdk' in dcInstance) {
dcInstance._useGeneratedSdk();
} else {
console.error('Please update to the latest version of the Data Connect SDK by running `npm install firebase@dataconnect-preview`.');
}
return queryRef(dcInstance, 'ListUsers');
}
exports.listUsersRef = listUsersRef;
exports.listUsers = function listUsers(dc) {
return executeQuery(listUsersRef(dc));
};

function listUserReviewsRef(dc) {
const { dc: dcInstance} = validateArgs(connectorConfig, dc, undefined);
if('_useGeneratedSdk' in dcInstance) {
dcInstance._useGeneratedSdk();
} else {
console.error('Please update to the latest version of the Data Connect SDK by running `npm install firebase@dataconnect-preview`.');
}
return queryRef(dcInstance, 'ListUserReviews');
}
exports.listUserReviewsRef = listUserReviewsRef;
exports.listUserReviews = function listUserReviews(dc) {
return executeQuery(listUserReviewsRef(dc));
};

function getMovieByIdRef(dcOrVars, vars) {
const { dc: dcInstance, vars: inputVars} = validateArgs(connectorConfig, dcOrVars, vars, true);
if('_useGeneratedSdk' in dcInstance) {
dcInstance._useGeneratedSdk();
} else {
console.error('Please update to the latest version of the Data Connect SDK by running `npm install firebase@dataconnect-preview`.');
}
return queryRef(dcInstance, 'GetMovieById', inputVars);
}
exports.getMovieByIdRef = getMovieByIdRef;
exports.getMovieById = function getMovieById(dcOrVars, vars) {
return executeQuery(getMovieByIdRef(dcOrVars, vars));
};

function searchMovieRef(dcOrVars, vars) {
const { dc: dcInstance, vars: inputVars} = validateArgs(connectorConfig, dcOrVars, vars);
if('_useGeneratedSdk' in dcInstance) {
dcInstance._useGeneratedSdk();
} else {
console.error('Please update to the latest version of the Data Connect SDK by running `npm install firebase@dataconnect-preview`.');
}
return queryRef(dcInstance, 'SearchMovie', inputVars);
}
exports.searchMovieRef = searchMovieRef;
exports.searchMovie = function searchMovie(dcOrVars, vars) {
return executeQuery(searchMovieRef(dcOrVars, vars));
};

Loading

0 comments on commit b5afb80

Please sign in to comment.