sdk from back and first configuration for firebase
This commit is contained in:
@@ -12,26 +12,12 @@ For each operation, there is a wrapper hook that can be used to call the operati
|
|||||||
|
|
||||||
Here are all of the hooks that get generated:
|
Here are all of the hooks that get generated:
|
||||||
```ts
|
```ts
|
||||||
import { useCreateMovie, useUpsertUser, useAddReview, useDeleteReview, useListMovies, useListUsers, useListUserReviews, useGetMovieById, useSearchMovie } from '@dataconnect/generated/react';
|
import { useCreateEvent, useListEvents } from '@dataconnect/generated/react';
|
||||||
// The types of these hooks are available in react/index.d.ts
|
// The types of these hooks are available in react/index.d.ts
|
||||||
|
|
||||||
const { data, isPending, isSuccess, isError, error } = useCreateMovie(createMovieVars);
|
const { data, isPending, isSuccess, isError, error } = useCreateEvent(createEventVars);
|
||||||
|
|
||||||
const { data, isPending, isSuccess, isError, error } = useUpsertUser(upsertUserVars);
|
const { data, isPending, isSuccess, isError, error } = useListEvents();
|
||||||
|
|
||||||
const { data, isPending, isSuccess, isError, error } = useAddReview(addReviewVars);
|
|
||||||
|
|
||||||
const { data, isPending, isSuccess, isError, error } = useDeleteReview(deleteReviewVars);
|
|
||||||
|
|
||||||
const { data, isPending, isSuccess, isError, error } = useListMovies();
|
|
||||||
|
|
||||||
const { data, isPending, isSuccess, isError, error } = useListUsers();
|
|
||||||
|
|
||||||
const { data, isPending, isSuccess, isError, error } = useListUserReviews();
|
|
||||||
|
|
||||||
const { data, isPending, isSuccess, isError, error } = useGetMovieById(getMovieByIdVars);
|
|
||||||
|
|
||||||
const { data, isPending, isSuccess, isError, error } = useSearchMovie(searchMovieVars);
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -70,35 +56,14 @@ If a user is not using a supported framework, they can use the generated SDK dir
|
|||||||
Here's an example of how to use it with the first 5 operations:
|
Here's an example of how to use it with the first 5 operations:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
import { createMovie, upsertUser, addReview, deleteReview, listMovies, listUsers, listUserReviews, getMovieById, searchMovie } from '@dataconnect/generated';
|
import { createEvent, listEvents } from '@dataconnect/generated';
|
||||||
|
|
||||||
|
|
||||||
// Operation CreateMovie: For variables, look at type CreateMovieVars in ../index.d.ts
|
// Operation CreateEvent: For variables, look at type CreateEventVars in ../index.d.ts
|
||||||
const { data } = await CreateMovie(dataConnect, createMovieVars);
|
const { data } = await CreateEvent(dataConnect, createEventVars);
|
||||||
|
|
||||||
// Operation UpsertUser: For variables, look at type UpsertUserVars in ../index.d.ts
|
// Operation listEvents:
|
||||||
const { data } = await UpsertUser(dataConnect, upsertUserVars);
|
const { data } = await ListEvents(dataConnect);
|
||||||
|
|
||||||
// Operation AddReview: For variables, look at type AddReviewVars in ../index.d.ts
|
|
||||||
const { data } = await AddReview(dataConnect, addReviewVars);
|
|
||||||
|
|
||||||
// Operation DeleteReview: For variables, look at type DeleteReviewVars in ../index.d.ts
|
|
||||||
const { data } = await DeleteReview(dataConnect, deleteReviewVars);
|
|
||||||
|
|
||||||
// Operation ListMovies:
|
|
||||||
const { data } = await ListMovies(dataConnect);
|
|
||||||
|
|
||||||
// Operation ListUsers:
|
|
||||||
const { data } = await ListUsers(dataConnect);
|
|
||||||
|
|
||||||
// Operation ListUserReviews:
|
|
||||||
const { data } = await ListUserReviews(dataConnect);
|
|
||||||
|
|
||||||
// Operation GetMovieById: For variables, look at type GetMovieByIdVars in ../index.d.ts
|
|
||||||
const { data } = await GetMovieById(dataConnect, getMovieByIdVars);
|
|
||||||
|
|
||||||
// Operation SearchMovie: For variables, look at type SearchMovieVars in ../index.d.ts
|
|
||||||
const { data } = await SearchMovie(dataConnect, searchMovieVars);
|
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,107 +1,46 @@
|
|||||||
import { queryRef, executeQuery, mutationRef, executeMutation, validateArgs } from 'firebase/data-connect';
|
import { queryRef, executeQuery, mutationRef, executeMutation, validateArgs } from 'firebase/data-connect';
|
||||||
|
|
||||||
|
export const EventStatus = {
|
||||||
|
DRAFT: "DRAFT",
|
||||||
|
ACTIVE: "ACTIVE",
|
||||||
|
PENDING: "PENDING",
|
||||||
|
ASSIGNED: "ASSIGNED",
|
||||||
|
CONFIRMED: "CONFIRMED",
|
||||||
|
COMPLETED: "COMPLETED",
|
||||||
|
CANCELED: "CANCELED",
|
||||||
|
}
|
||||||
|
|
||||||
|
export const RecurrenceType = {
|
||||||
|
SINGLE: "SINGLE",
|
||||||
|
DATE_RANGE: "DATE_RANGE",
|
||||||
|
SCATTER: "SCATTER",
|
||||||
|
}
|
||||||
|
|
||||||
export const connectorConfig = {
|
export const connectorConfig = {
|
||||||
connector: 'example',
|
connector: 'krow-connector',
|
||||||
service: 'krow-workforce',
|
service: 'krow-workforce-db',
|
||||||
location: 'us-central1'
|
location: 'us-central1'
|
||||||
};
|
};
|
||||||
|
|
||||||
export const createMovieRef = (dcOrVars, vars) => {
|
export const createEventRef = (dcOrVars, vars) => {
|
||||||
const { dc: dcInstance, vars: inputVars} = validateArgs(connectorConfig, dcOrVars, vars, true);
|
const { dc: dcInstance, vars: inputVars} = validateArgs(connectorConfig, dcOrVars, vars, true);
|
||||||
dcInstance._useGeneratedSdk();
|
dcInstance._useGeneratedSdk();
|
||||||
return mutationRef(dcInstance, 'CreateMovie', inputVars);
|
return mutationRef(dcInstance, 'CreateEvent', inputVars);
|
||||||
}
|
}
|
||||||
createMovieRef.operationName = 'CreateMovie';
|
createEventRef.operationName = 'CreateEvent';
|
||||||
|
|
||||||
export function createMovie(dcOrVars, vars) {
|
export function createEvent(dcOrVars, vars) {
|
||||||
return executeMutation(createMovieRef(dcOrVars, vars));
|
return executeMutation(createEventRef(dcOrVars, vars));
|
||||||
}
|
}
|
||||||
|
|
||||||
export const upsertUserRef = (dcOrVars, vars) => {
|
export const listEventsRef = (dc) => {
|
||||||
const { dc: dcInstance, vars: inputVars} = validateArgs(connectorConfig, dcOrVars, vars, true);
|
|
||||||
dcInstance._useGeneratedSdk();
|
|
||||||
return mutationRef(dcInstance, 'UpsertUser', inputVars);
|
|
||||||
}
|
|
||||||
upsertUserRef.operationName = 'UpsertUser';
|
|
||||||
|
|
||||||
export function upsertUser(dcOrVars, vars) {
|
|
||||||
return executeMutation(upsertUserRef(dcOrVars, vars));
|
|
||||||
}
|
|
||||||
|
|
||||||
export const addReviewRef = (dcOrVars, vars) => {
|
|
||||||
const { dc: dcInstance, vars: inputVars} = validateArgs(connectorConfig, dcOrVars, vars, true);
|
|
||||||
dcInstance._useGeneratedSdk();
|
|
||||||
return mutationRef(dcInstance, 'AddReview', inputVars);
|
|
||||||
}
|
|
||||||
addReviewRef.operationName = 'AddReview';
|
|
||||||
|
|
||||||
export function addReview(dcOrVars, vars) {
|
|
||||||
return executeMutation(addReviewRef(dcOrVars, vars));
|
|
||||||
}
|
|
||||||
|
|
||||||
export const deleteReviewRef = (dcOrVars, vars) => {
|
|
||||||
const { dc: dcInstance, vars: inputVars} = validateArgs(connectorConfig, dcOrVars, vars, true);
|
|
||||||
dcInstance._useGeneratedSdk();
|
|
||||||
return mutationRef(dcInstance, 'DeleteReview', inputVars);
|
|
||||||
}
|
|
||||||
deleteReviewRef.operationName = 'DeleteReview';
|
|
||||||
|
|
||||||
export function deleteReview(dcOrVars, vars) {
|
|
||||||
return executeMutation(deleteReviewRef(dcOrVars, vars));
|
|
||||||
}
|
|
||||||
|
|
||||||
export const listMoviesRef = (dc) => {
|
|
||||||
const { dc: dcInstance} = validateArgs(connectorConfig, dc, undefined);
|
const { dc: dcInstance} = validateArgs(connectorConfig, dc, undefined);
|
||||||
dcInstance._useGeneratedSdk();
|
dcInstance._useGeneratedSdk();
|
||||||
return queryRef(dcInstance, 'ListMovies');
|
return queryRef(dcInstance, 'listEvents');
|
||||||
}
|
}
|
||||||
listMoviesRef.operationName = 'ListMovies';
|
listEventsRef.operationName = 'listEvents';
|
||||||
|
|
||||||
export function listMovies(dc) {
|
export function listEvents(dc) {
|
||||||
return executeQuery(listMoviesRef(dc));
|
return executeQuery(listEventsRef(dc));
|
||||||
}
|
|
||||||
|
|
||||||
export const listUsersRef = (dc) => {
|
|
||||||
const { dc: dcInstance} = validateArgs(connectorConfig, dc, undefined);
|
|
||||||
dcInstance._useGeneratedSdk();
|
|
||||||
return queryRef(dcInstance, 'ListUsers');
|
|
||||||
}
|
|
||||||
listUsersRef.operationName = 'ListUsers';
|
|
||||||
|
|
||||||
export function listUsers(dc) {
|
|
||||||
return executeQuery(listUsersRef(dc));
|
|
||||||
}
|
|
||||||
|
|
||||||
export const listUserReviewsRef = (dc) => {
|
|
||||||
const { dc: dcInstance} = validateArgs(connectorConfig, dc, undefined);
|
|
||||||
dcInstance._useGeneratedSdk();
|
|
||||||
return queryRef(dcInstance, 'ListUserReviews');
|
|
||||||
}
|
|
||||||
listUserReviewsRef.operationName = 'ListUserReviews';
|
|
||||||
|
|
||||||
export function listUserReviews(dc) {
|
|
||||||
return executeQuery(listUserReviewsRef(dc));
|
|
||||||
}
|
|
||||||
|
|
||||||
export const getMovieByIdRef = (dcOrVars, vars) => {
|
|
||||||
const { dc: dcInstance, vars: inputVars} = validateArgs(connectorConfig, dcOrVars, vars, true);
|
|
||||||
dcInstance._useGeneratedSdk();
|
|
||||||
return queryRef(dcInstance, 'GetMovieById', inputVars);
|
|
||||||
}
|
|
||||||
getMovieByIdRef.operationName = 'GetMovieById';
|
|
||||||
|
|
||||||
export function getMovieById(dcOrVars, vars) {
|
|
||||||
return executeQuery(getMovieByIdRef(dcOrVars, vars));
|
|
||||||
}
|
|
||||||
|
|
||||||
export const searchMovieRef = (dcOrVars, vars) => {
|
|
||||||
const { dc: dcInstance, vars: inputVars} = validateArgs(connectorConfig, dcOrVars, vars);
|
|
||||||
dcInstance._useGeneratedSdk();
|
|
||||||
return queryRef(dcInstance, 'SearchMovie', inputVars);
|
|
||||||
}
|
|
||||||
searchMovieRef.operationName = 'SearchMovie';
|
|
||||||
|
|
||||||
export function searchMovie(dcOrVars, vars) {
|
|
||||||
return executeQuery(searchMovieRef(dcOrVars, vars));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,116 +1,50 @@
|
|||||||
const { queryRef, executeQuery, mutationRef, executeMutation, validateArgs } = require('firebase/data-connect');
|
const { queryRef, executeQuery, mutationRef, executeMutation, validateArgs } = require('firebase/data-connect');
|
||||||
|
|
||||||
|
const EventStatus = {
|
||||||
|
DRAFT: "DRAFT",
|
||||||
|
ACTIVE: "ACTIVE",
|
||||||
|
PENDING: "PENDING",
|
||||||
|
ASSIGNED: "ASSIGNED",
|
||||||
|
CONFIRMED: "CONFIRMED",
|
||||||
|
COMPLETED: "COMPLETED",
|
||||||
|
CANCELED: "CANCELED",
|
||||||
|
}
|
||||||
|
exports.EventStatus = EventStatus;
|
||||||
|
|
||||||
|
const RecurrenceType = {
|
||||||
|
SINGLE: "SINGLE",
|
||||||
|
DATE_RANGE: "DATE_RANGE",
|
||||||
|
SCATTER: "SCATTER",
|
||||||
|
}
|
||||||
|
exports.RecurrenceType = RecurrenceType;
|
||||||
|
|
||||||
const connectorConfig = {
|
const connectorConfig = {
|
||||||
connector: 'example',
|
connector: 'krow-connector',
|
||||||
service: 'krow-workforce',
|
service: 'krow-workforce-db',
|
||||||
location: 'us-central1'
|
location: 'us-central1'
|
||||||
};
|
};
|
||||||
exports.connectorConfig = connectorConfig;
|
exports.connectorConfig = connectorConfig;
|
||||||
|
|
||||||
const createMovieRef = (dcOrVars, vars) => {
|
const createEventRef = (dcOrVars, vars) => {
|
||||||
const { dc: dcInstance, vars: inputVars} = validateArgs(connectorConfig, dcOrVars, vars, true);
|
const { dc: dcInstance, vars: inputVars} = validateArgs(connectorConfig, dcOrVars, vars, true);
|
||||||
dcInstance._useGeneratedSdk();
|
dcInstance._useGeneratedSdk();
|
||||||
return mutationRef(dcInstance, 'CreateMovie', inputVars);
|
return mutationRef(dcInstance, 'CreateEvent', inputVars);
|
||||||
}
|
}
|
||||||
createMovieRef.operationName = 'CreateMovie';
|
createEventRef.operationName = 'CreateEvent';
|
||||||
exports.createMovieRef = createMovieRef;
|
exports.createEventRef = createEventRef;
|
||||||
|
|
||||||
exports.createMovie = function createMovie(dcOrVars, vars) {
|
exports.createEvent = function createEvent(dcOrVars, vars) {
|
||||||
return executeMutation(createMovieRef(dcOrVars, vars));
|
return executeMutation(createEventRef(dcOrVars, vars));
|
||||||
};
|
};
|
||||||
|
|
||||||
const upsertUserRef = (dcOrVars, vars) => {
|
const listEventsRef = (dc) => {
|
||||||
const { dc: dcInstance, vars: inputVars} = validateArgs(connectorConfig, dcOrVars, vars, true);
|
|
||||||
dcInstance._useGeneratedSdk();
|
|
||||||
return mutationRef(dcInstance, 'UpsertUser', inputVars);
|
|
||||||
}
|
|
||||||
upsertUserRef.operationName = 'UpsertUser';
|
|
||||||
exports.upsertUserRef = upsertUserRef;
|
|
||||||
|
|
||||||
exports.upsertUser = function upsertUser(dcOrVars, vars) {
|
|
||||||
return executeMutation(upsertUserRef(dcOrVars, vars));
|
|
||||||
};
|
|
||||||
|
|
||||||
const addReviewRef = (dcOrVars, vars) => {
|
|
||||||
const { dc: dcInstance, vars: inputVars} = validateArgs(connectorConfig, dcOrVars, vars, true);
|
|
||||||
dcInstance._useGeneratedSdk();
|
|
||||||
return mutationRef(dcInstance, 'AddReview', inputVars);
|
|
||||||
}
|
|
||||||
addReviewRef.operationName = 'AddReview';
|
|
||||||
exports.addReviewRef = addReviewRef;
|
|
||||||
|
|
||||||
exports.addReview = function addReview(dcOrVars, vars) {
|
|
||||||
return executeMutation(addReviewRef(dcOrVars, vars));
|
|
||||||
};
|
|
||||||
|
|
||||||
const deleteReviewRef = (dcOrVars, vars) => {
|
|
||||||
const { dc: dcInstance, vars: inputVars} = validateArgs(connectorConfig, dcOrVars, vars, true);
|
|
||||||
dcInstance._useGeneratedSdk();
|
|
||||||
return mutationRef(dcInstance, 'DeleteReview', inputVars);
|
|
||||||
}
|
|
||||||
deleteReviewRef.operationName = 'DeleteReview';
|
|
||||||
exports.deleteReviewRef = deleteReviewRef;
|
|
||||||
|
|
||||||
exports.deleteReview = function deleteReview(dcOrVars, vars) {
|
|
||||||
return executeMutation(deleteReviewRef(dcOrVars, vars));
|
|
||||||
};
|
|
||||||
|
|
||||||
const listMoviesRef = (dc) => {
|
|
||||||
const { dc: dcInstance} = validateArgs(connectorConfig, dc, undefined);
|
const { dc: dcInstance} = validateArgs(connectorConfig, dc, undefined);
|
||||||
dcInstance._useGeneratedSdk();
|
dcInstance._useGeneratedSdk();
|
||||||
return queryRef(dcInstance, 'ListMovies');
|
return queryRef(dcInstance, 'listEvents');
|
||||||
}
|
}
|
||||||
listMoviesRef.operationName = 'ListMovies';
|
listEventsRef.operationName = 'listEvents';
|
||||||
exports.listMoviesRef = listMoviesRef;
|
exports.listEventsRef = listEventsRef;
|
||||||
|
|
||||||
exports.listMovies = function listMovies(dc) {
|
exports.listEvents = function listEvents(dc) {
|
||||||
return executeQuery(listMoviesRef(dc));
|
return executeQuery(listEventsRef(dc));
|
||||||
};
|
|
||||||
|
|
||||||
const listUsersRef = (dc) => {
|
|
||||||
const { dc: dcInstance} = validateArgs(connectorConfig, dc, undefined);
|
|
||||||
dcInstance._useGeneratedSdk();
|
|
||||||
return queryRef(dcInstance, 'ListUsers');
|
|
||||||
}
|
|
||||||
listUsersRef.operationName = 'ListUsers';
|
|
||||||
exports.listUsersRef = listUsersRef;
|
|
||||||
|
|
||||||
exports.listUsers = function listUsers(dc) {
|
|
||||||
return executeQuery(listUsersRef(dc));
|
|
||||||
};
|
|
||||||
|
|
||||||
const listUserReviewsRef = (dc) => {
|
|
||||||
const { dc: dcInstance} = validateArgs(connectorConfig, dc, undefined);
|
|
||||||
dcInstance._useGeneratedSdk();
|
|
||||||
return queryRef(dcInstance, 'ListUserReviews');
|
|
||||||
}
|
|
||||||
listUserReviewsRef.operationName = 'ListUserReviews';
|
|
||||||
exports.listUserReviewsRef = listUserReviewsRef;
|
|
||||||
|
|
||||||
exports.listUserReviews = function listUserReviews(dc) {
|
|
||||||
return executeQuery(listUserReviewsRef(dc));
|
|
||||||
};
|
|
||||||
|
|
||||||
const getMovieByIdRef = (dcOrVars, vars) => {
|
|
||||||
const { dc: dcInstance, vars: inputVars} = validateArgs(connectorConfig, dcOrVars, vars, true);
|
|
||||||
dcInstance._useGeneratedSdk();
|
|
||||||
return queryRef(dcInstance, 'GetMovieById', inputVars);
|
|
||||||
}
|
|
||||||
getMovieByIdRef.operationName = 'GetMovieById';
|
|
||||||
exports.getMovieByIdRef = getMovieByIdRef;
|
|
||||||
|
|
||||||
exports.getMovieById = function getMovieById(dcOrVars, vars) {
|
|
||||||
return executeQuery(getMovieByIdRef(dcOrVars, vars));
|
|
||||||
};
|
|
||||||
|
|
||||||
const searchMovieRef = (dcOrVars, vars) => {
|
|
||||||
const { dc: dcInstance, vars: inputVars} = validateArgs(connectorConfig, dcOrVars, vars);
|
|
||||||
dcInstance._useGeneratedSdk();
|
|
||||||
return queryRef(dcInstance, 'SearchMovie', inputVars);
|
|
||||||
}
|
|
||||||
searchMovieRef.operationName = 'SearchMovie';
|
|
||||||
exports.searchMovieRef = searchMovieRef;
|
|
||||||
|
|
||||||
exports.searchMovie = function searchMovie(dcOrVars, vars) {
|
|
||||||
return executeQuery(searchMovieRef(dcOrVars, vars));
|
|
||||||
};
|
};
|
||||||
|
|||||||
272
frontend-web/src/dataconnect-generated/index.d.ts
vendored
272
frontend-web/src/dataconnect-generated/index.d.ts
vendored
@@ -8,243 +8,83 @@ export type Int64String = string;
|
|||||||
export type DateString = string;
|
export type DateString = string;
|
||||||
|
|
||||||
|
|
||||||
|
export enum EventStatus {
|
||||||
|
DRAFT = "DRAFT",
|
||||||
|
ACTIVE = "ACTIVE",
|
||||||
|
PENDING = "PENDING",
|
||||||
|
ASSIGNED = "ASSIGNED",
|
||||||
|
CONFIRMED = "CONFIRMED",
|
||||||
|
COMPLETED = "COMPLETED",
|
||||||
|
CANCELED = "CANCELED",
|
||||||
|
};
|
||||||
|
|
||||||
|
export enum RecurrenceType {
|
||||||
|
SINGLE = "SINGLE",
|
||||||
|
DATE_RANGE = "DATE_RANGE",
|
||||||
|
SCATTER = "SCATTER",
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
export interface AddReviewData {
|
|
||||||
review_upsert: Review_Key;
|
export interface CreateEventData {
|
||||||
|
event_insert: Event_Key;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AddReviewVariables {
|
export interface CreateEventVariables {
|
||||||
movieId: UUIDString;
|
eventName: string;
|
||||||
rating: number;
|
isRecurring: boolean;
|
||||||
reviewText: string;
|
recurrenceType?: RecurrenceType | null;
|
||||||
|
businessId: UUIDString;
|
||||||
|
vendorId?: UUIDString | null;
|
||||||
|
status: EventStatus;
|
||||||
|
date: TimestampString;
|
||||||
|
shifts?: string | null;
|
||||||
|
total?: number | null;
|
||||||
|
requested?: number | null;
|
||||||
|
assignedStaff?: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CreateMovieData {
|
export interface Event_Key {
|
||||||
movie_insert: Movie_Key;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface CreateMovieVariables {
|
|
||||||
title: string;
|
|
||||||
genre: string;
|
|
||||||
imageUrl: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface DeleteReviewData {
|
|
||||||
review_delete?: Review_Key | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface DeleteReviewVariables {
|
|
||||||
movieId: UUIDString;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface GetMovieByIdData {
|
|
||||||
movie?: {
|
|
||||||
id: UUIDString;
|
|
||||||
title: string;
|
|
||||||
imageUrl: string;
|
|
||||||
genre?: string | null;
|
|
||||||
metadata?: {
|
|
||||||
rating?: number | null;
|
|
||||||
releaseYear?: number | null;
|
|
||||||
description?: string | null;
|
|
||||||
};
|
|
||||||
reviews: ({
|
|
||||||
reviewText?: string | null;
|
|
||||||
reviewDate: DateString;
|
|
||||||
rating?: number | null;
|
|
||||||
user: {
|
|
||||||
id: string;
|
|
||||||
username: string;
|
|
||||||
} & User_Key;
|
|
||||||
})[];
|
|
||||||
} & Movie_Key;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface GetMovieByIdVariables {
|
|
||||||
id: UUIDString;
|
id: UUIDString;
|
||||||
|
__typename?: 'Event_Key';
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ListMoviesData {
|
export interface ListEventsData {
|
||||||
movies: ({
|
events: ({
|
||||||
id: UUIDString;
|
id: UUIDString;
|
||||||
title: string;
|
eventName: string;
|
||||||
imageUrl: string;
|
status: EventStatus;
|
||||||
genre?: string | null;
|
date: TimestampString;
|
||||||
} & Movie_Key)[];
|
isRecurring: boolean;
|
||||||
|
recurrenceType?: RecurrenceType | null;
|
||||||
|
businessId: UUIDString;
|
||||||
|
vendorId?: UUIDString | null;
|
||||||
|
total?: number | null;
|
||||||
|
requested?: number | null;
|
||||||
|
} & Event_Key)[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ListUserReviewsData {
|
interface CreateEventRef {
|
||||||
user?: {
|
|
||||||
id: string;
|
|
||||||
username: string;
|
|
||||||
reviews: ({
|
|
||||||
rating?: number | null;
|
|
||||||
reviewDate: DateString;
|
|
||||||
reviewText?: string | null;
|
|
||||||
movie: {
|
|
||||||
id: UUIDString;
|
|
||||||
title: string;
|
|
||||||
} & Movie_Key;
|
|
||||||
})[];
|
|
||||||
} & User_Key;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ListUsersData {
|
|
||||||
users: ({
|
|
||||||
id: string;
|
|
||||||
username: string;
|
|
||||||
} & User_Key)[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface MovieMetadata_Key {
|
|
||||||
id: UUIDString;
|
|
||||||
__typename?: 'MovieMetadata_Key';
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Movie_Key {
|
|
||||||
id: UUIDString;
|
|
||||||
__typename?: 'Movie_Key';
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Review_Key {
|
|
||||||
userId: string;
|
|
||||||
movieId: UUIDString;
|
|
||||||
__typename?: 'Review_Key';
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface SearchMovieData {
|
|
||||||
movies: ({
|
|
||||||
id: UUIDString;
|
|
||||||
title: string;
|
|
||||||
genre?: string | null;
|
|
||||||
imageUrl: string;
|
|
||||||
} & Movie_Key)[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface SearchMovieVariables {
|
|
||||||
titleInput?: string | null;
|
|
||||||
genre?: string | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface UpsertUserData {
|
|
||||||
user_upsert: User_Key;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface UpsertUserVariables {
|
|
||||||
username: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface User_Key {
|
|
||||||
id: string;
|
|
||||||
__typename?: 'User_Key';
|
|
||||||
}
|
|
||||||
|
|
||||||
interface CreateMovieRef {
|
|
||||||
/* Allow users to create refs without passing in DataConnect */
|
/* Allow users to create refs without passing in DataConnect */
|
||||||
(vars: CreateMovieVariables): MutationRef<CreateMovieData, CreateMovieVariables>;
|
(vars: CreateEventVariables): MutationRef<CreateEventData, CreateEventVariables>;
|
||||||
/* Allow users to pass in custom DataConnect instances */
|
/* Allow users to pass in custom DataConnect instances */
|
||||||
(dc: DataConnect, vars: CreateMovieVariables): MutationRef<CreateMovieData, CreateMovieVariables>;
|
(dc: DataConnect, vars: CreateEventVariables): MutationRef<CreateEventData, CreateEventVariables>;
|
||||||
operationName: string;
|
operationName: string;
|
||||||
}
|
}
|
||||||
export const createMovieRef: CreateMovieRef;
|
export const createEventRef: CreateEventRef;
|
||||||
|
|
||||||
export function createMovie(vars: CreateMovieVariables): MutationPromise<CreateMovieData, CreateMovieVariables>;
|
export function createEvent(vars: CreateEventVariables): MutationPromise<CreateEventData, CreateEventVariables>;
|
||||||
export function createMovie(dc: DataConnect, vars: CreateMovieVariables): MutationPromise<CreateMovieData, CreateMovieVariables>;
|
export function createEvent(dc: DataConnect, vars: CreateEventVariables): MutationPromise<CreateEventData, CreateEventVariables>;
|
||||||
|
|
||||||
interface UpsertUserRef {
|
interface ListEventsRef {
|
||||||
/* Allow users to create refs without passing in DataConnect */
|
/* Allow users to create refs without passing in DataConnect */
|
||||||
(vars: UpsertUserVariables): MutationRef<UpsertUserData, UpsertUserVariables>;
|
(): QueryRef<ListEventsData, undefined>;
|
||||||
/* Allow users to pass in custom DataConnect instances */
|
/* Allow users to pass in custom DataConnect instances */
|
||||||
(dc: DataConnect, vars: UpsertUserVariables): MutationRef<UpsertUserData, UpsertUserVariables>;
|
(dc: DataConnect): QueryRef<ListEventsData, undefined>;
|
||||||
operationName: string;
|
operationName: string;
|
||||||
}
|
}
|
||||||
export const upsertUserRef: UpsertUserRef;
|
export const listEventsRef: ListEventsRef;
|
||||||
|
|
||||||
export function upsertUser(vars: UpsertUserVariables): MutationPromise<UpsertUserData, UpsertUserVariables>;
|
export function listEvents(): QueryPromise<ListEventsData, undefined>;
|
||||||
export function upsertUser(dc: DataConnect, vars: UpsertUserVariables): MutationPromise<UpsertUserData, UpsertUserVariables>;
|
export function listEvents(dc: DataConnect): QueryPromise<ListEventsData, undefined>;
|
||||||
|
|
||||||
interface AddReviewRef {
|
|
||||||
/* Allow users to create refs without passing in DataConnect */
|
|
||||||
(vars: AddReviewVariables): MutationRef<AddReviewData, AddReviewVariables>;
|
|
||||||
/* Allow users to pass in custom DataConnect instances */
|
|
||||||
(dc: DataConnect, vars: AddReviewVariables): MutationRef<AddReviewData, AddReviewVariables>;
|
|
||||||
operationName: string;
|
|
||||||
}
|
|
||||||
export const addReviewRef: AddReviewRef;
|
|
||||||
|
|
||||||
export function addReview(vars: AddReviewVariables): MutationPromise<AddReviewData, AddReviewVariables>;
|
|
||||||
export function addReview(dc: DataConnect, vars: AddReviewVariables): MutationPromise<AddReviewData, AddReviewVariables>;
|
|
||||||
|
|
||||||
interface DeleteReviewRef {
|
|
||||||
/* Allow users to create refs without passing in DataConnect */
|
|
||||||
(vars: DeleteReviewVariables): MutationRef<DeleteReviewData, DeleteReviewVariables>;
|
|
||||||
/* Allow users to pass in custom DataConnect instances */
|
|
||||||
(dc: DataConnect, vars: DeleteReviewVariables): MutationRef<DeleteReviewData, DeleteReviewVariables>;
|
|
||||||
operationName: string;
|
|
||||||
}
|
|
||||||
export const deleteReviewRef: DeleteReviewRef;
|
|
||||||
|
|
||||||
export function deleteReview(vars: DeleteReviewVariables): MutationPromise<DeleteReviewData, DeleteReviewVariables>;
|
|
||||||
export function deleteReview(dc: DataConnect, vars: DeleteReviewVariables): MutationPromise<DeleteReviewData, DeleteReviewVariables>;
|
|
||||||
|
|
||||||
interface ListMoviesRef {
|
|
||||||
/* Allow users to create refs without passing in DataConnect */
|
|
||||||
(): QueryRef<ListMoviesData, undefined>;
|
|
||||||
/* Allow users to pass in custom DataConnect instances */
|
|
||||||
(dc: DataConnect): QueryRef<ListMoviesData, undefined>;
|
|
||||||
operationName: string;
|
|
||||||
}
|
|
||||||
export const listMoviesRef: ListMoviesRef;
|
|
||||||
|
|
||||||
export function listMovies(): QueryPromise<ListMoviesData, undefined>;
|
|
||||||
export function listMovies(dc: DataConnect): QueryPromise<ListMoviesData, undefined>;
|
|
||||||
|
|
||||||
interface ListUsersRef {
|
|
||||||
/* Allow users to create refs without passing in DataConnect */
|
|
||||||
(): QueryRef<ListUsersData, undefined>;
|
|
||||||
/* Allow users to pass in custom DataConnect instances */
|
|
||||||
(dc: DataConnect): QueryRef<ListUsersData, undefined>;
|
|
||||||
operationName: string;
|
|
||||||
}
|
|
||||||
export const listUsersRef: ListUsersRef;
|
|
||||||
|
|
||||||
export function listUsers(): QueryPromise<ListUsersData, undefined>;
|
|
||||||
export function listUsers(dc: DataConnect): QueryPromise<ListUsersData, undefined>;
|
|
||||||
|
|
||||||
interface ListUserReviewsRef {
|
|
||||||
/* Allow users to create refs without passing in DataConnect */
|
|
||||||
(): QueryRef<ListUserReviewsData, undefined>;
|
|
||||||
/* Allow users to pass in custom DataConnect instances */
|
|
||||||
(dc: DataConnect): QueryRef<ListUserReviewsData, undefined>;
|
|
||||||
operationName: string;
|
|
||||||
}
|
|
||||||
export const listUserReviewsRef: ListUserReviewsRef;
|
|
||||||
|
|
||||||
export function listUserReviews(): QueryPromise<ListUserReviewsData, undefined>;
|
|
||||||
export function listUserReviews(dc: DataConnect): QueryPromise<ListUserReviewsData, undefined>;
|
|
||||||
|
|
||||||
interface GetMovieByIdRef {
|
|
||||||
/* Allow users to create refs without passing in DataConnect */
|
|
||||||
(vars: GetMovieByIdVariables): QueryRef<GetMovieByIdData, GetMovieByIdVariables>;
|
|
||||||
/* Allow users to pass in custom DataConnect instances */
|
|
||||||
(dc: DataConnect, vars: GetMovieByIdVariables): QueryRef<GetMovieByIdData, GetMovieByIdVariables>;
|
|
||||||
operationName: string;
|
|
||||||
}
|
|
||||||
export const getMovieByIdRef: GetMovieByIdRef;
|
|
||||||
|
|
||||||
export function getMovieById(vars: GetMovieByIdVariables): QueryPromise<GetMovieByIdData, GetMovieByIdVariables>;
|
|
||||||
export function getMovieById(dc: DataConnect, vars: GetMovieByIdVariables): QueryPromise<GetMovieByIdData, GetMovieByIdVariables>;
|
|
||||||
|
|
||||||
interface SearchMovieRef {
|
|
||||||
/* Allow users to create refs without passing in DataConnect */
|
|
||||||
(vars?: SearchMovieVariables): QueryRef<SearchMovieData, SearchMovieVariables>;
|
|
||||||
/* Allow users to pass in custom DataConnect instances */
|
|
||||||
(dc: DataConnect, vars?: SearchMovieVariables): QueryRef<SearchMovieData, SearchMovieVariables>;
|
|
||||||
operationName: string;
|
|
||||||
}
|
|
||||||
export const searchMovieRef: SearchMovieRef;
|
|
||||||
|
|
||||||
export function searchMovie(vars?: SearchMovieVariables): QueryPromise<SearchMovieData, SearchMovieVariables>;
|
|
||||||
export function searchMovie(dc: DataConnect, vars?: SearchMovieVariables): QueryPromise<SearchMovieData, SearchMovieVariables>;
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"name": "@dataconnect/generated",
|
"name": "@dataconnect/generated",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"author": "Firebase <firebase-support@google.com> (https://firebase.google.com/)",
|
"author": "Firebase <firebase-support@google.com> (https://firebase.google.com/)",
|
||||||
"description": "Generated SDK For example",
|
"description": "Generated SDK For krow-connector",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": " >=18.0"
|
"node": " >=18.0"
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Generated React README
|
# Generated React README
|
||||||
This README will guide you through the process of using the generated React SDK package for the connector `example`. It will also provide examples on how to use your generated SDK to call your Data Connect queries and mutations.
|
This README will guide you through the process of using the generated React SDK package for the connector `krow-connector`. It will also provide examples on how to use your generated SDK to call your Data Connect queries and mutations.
|
||||||
|
|
||||||
**If you're looking for the `JavaScript README`, you can find it at [`dataconnect-generated/README.md`](../README.md)**
|
**If you're looking for the `JavaScript README`, you can find it at [`dataconnect-generated/README.md`](../README.md)**
|
||||||
|
|
||||||
@@ -17,19 +17,12 @@ You can also follow the instructions from the [Data Connect documentation](https
|
|||||||
- [**Accessing the connector**](#accessing-the-connector)
|
- [**Accessing the connector**](#accessing-the-connector)
|
||||||
- [*Connecting to the local Emulator*](#connecting-to-the-local-emulator)
|
- [*Connecting to the local Emulator*](#connecting-to-the-local-emulator)
|
||||||
- [**Queries**](#queries)
|
- [**Queries**](#queries)
|
||||||
- [*ListMovies*](#listmovies)
|
- [*listEvents*](#listevents)
|
||||||
- [*ListUsers*](#listusers)
|
|
||||||
- [*ListUserReviews*](#listuserreviews)
|
|
||||||
- [*GetMovieById*](#getmoviebyid)
|
|
||||||
- [*SearchMovie*](#searchmovie)
|
|
||||||
- [**Mutations**](#mutations)
|
- [**Mutations**](#mutations)
|
||||||
- [*CreateMovie*](#createmovie)
|
- [*CreateEvent*](#createevent)
|
||||||
- [*UpsertUser*](#upsertuser)
|
|
||||||
- [*AddReview*](#addreview)
|
|
||||||
- [*DeleteReview*](#deletereview)
|
|
||||||
|
|
||||||
# TanStack Query Firebase & TanStack React Query
|
# TanStack Query Firebase & TanStack React Query
|
||||||
This SDK provides [React](https://react.dev/) hooks generated specific to your application, for the operations found in the connector `example`. These hooks are generated using [TanStack Query Firebase](https://react-query-firebase.invertase.dev/) by our partners at Invertase, a library built on top of [TanStack React Query v5](https://tanstack.com/query/v5/docs/framework/react/overview).
|
This SDK provides [React](https://react.dev/) hooks generated specific to your application, for the operations found in the connector `krow-connector`. These hooks are generated using [TanStack Query Firebase](https://react-query-firebase.invertase.dev/) by our partners at Invertase, a library built on top of [TanStack React Query v5](https://tanstack.com/query/v5/docs/framework/react/overview).
|
||||||
|
|
||||||
***You do not need to be familiar with Tanstack Query or Tanstack Query Firebase to use this SDK.*** However, you may find it useful to learn more about them, as they will empower you as a user of this Generated React SDK.
|
***You do not need to be familiar with Tanstack Query or Tanstack Query Firebase to use this SDK.*** However, you may find it useful to learn more about them, as they will empower you as a user of this Generated React SDK.
|
||||||
|
|
||||||
@@ -66,7 +59,7 @@ function App() {
|
|||||||
To learn more about `QueryClientProvider`, see the [TanStack React Query documentation](https://tanstack.com/query/latest/docs/framework/react/quick-start) and the [TanStack Query Firebase documentation](https://invertase.docs.page/tanstack-query-firebase/react#usage).
|
To learn more about `QueryClientProvider`, see the [TanStack React Query documentation](https://tanstack.com/query/latest/docs/framework/react/quick-start) and the [TanStack Query Firebase documentation](https://invertase.docs.page/tanstack-query-firebase/react#usage).
|
||||||
|
|
||||||
# Accessing the connector
|
# Accessing the connector
|
||||||
A connector is a collection of Queries and Mutations. One SDK is generated for each connector - this SDK is generated for the connector `example`.
|
A connector is a collection of Queries and Mutations. One SDK is generated for each connector - this SDK is generated for the connector `krow-connector`.
|
||||||
|
|
||||||
You can find more information about connectors in the [Data Connect documentation](https://firebase.google.com/docs/data-connect#how-does).
|
You can find more information about connectors in the [Data Connect documentation](https://firebase.google.com/docs/data-connect#how-does).
|
||||||
|
|
||||||
@@ -116,64 +109,70 @@ Here's a general overview of how to use the generated Query hooks in your code:
|
|||||||
- Query hooks functions can be called with or without passing in an `options` argument of type `useDataConnectQueryOptions`. To learn more about the `options` argument, see the [TanStack React Query documentation](https://tanstack.com/query/v5/docs/framework/react/guides/query-options).
|
- Query hooks functions can be called with or without passing in an `options` argument of type `useDataConnectQueryOptions`. To learn more about the `options` argument, see the [TanStack React Query documentation](https://tanstack.com/query/v5/docs/framework/react/guides/query-options).
|
||||||
- ***Special case:*** If the Query has all optional variables and you would like to provide an `options` argument to the Query hook function without providing any variables, you must pass `undefined` where you would normally pass the Query's variables, and then may provide the `options` argument.
|
- ***Special case:*** If the Query has all optional variables and you would like to provide an `options` argument to the Query hook function without providing any variables, you must pass `undefined` where you would normally pass the Query's variables, and then may provide the `options` argument.
|
||||||
|
|
||||||
Below are examples of how to use the `example` connector's generated Query hook functions to execute each Query. You can also follow the examples from the [Data Connect documentation](https://firebase.google.com/docs/data-connect/web-sdk#operations-react-angular).
|
Below are examples of how to use the `krow-connector` connector's generated Query hook functions to execute each Query. You can also follow the examples from the [Data Connect documentation](https://firebase.google.com/docs/data-connect/web-sdk#operations-react-angular).
|
||||||
|
|
||||||
## ListMovies
|
## listEvents
|
||||||
You can execute the `ListMovies` Query using the following Query hook function, which is defined in [dataconnect-generated/react/index.d.ts](./index.d.ts):
|
You can execute the `listEvents` Query using the following Query hook function, which is defined in [dataconnect-generated/react/index.d.ts](./index.d.ts):
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
useListMovies(dc: DataConnect, options?: useDataConnectQueryOptions<ListMoviesData>): UseDataConnectQueryResult<ListMoviesData, undefined>;
|
useListEvents(dc: DataConnect, options?: useDataConnectQueryOptions<ListEventsData>): UseDataConnectQueryResult<ListEventsData, undefined>;
|
||||||
```
|
```
|
||||||
You can also pass in a `DataConnect` instance to the Query hook function.
|
You can also pass in a `DataConnect` instance to the Query hook function.
|
||||||
```javascript
|
```javascript
|
||||||
useListMovies(options?: useDataConnectQueryOptions<ListMoviesData>): UseDataConnectQueryResult<ListMoviesData, undefined>;
|
useListEvents(options?: useDataConnectQueryOptions<ListEventsData>): UseDataConnectQueryResult<ListEventsData, undefined>;
|
||||||
```
|
```
|
||||||
|
|
||||||
### Variables
|
### Variables
|
||||||
The `ListMovies` Query has no variables.
|
The `listEvents` Query has no variables.
|
||||||
### Return Type
|
### Return Type
|
||||||
Recall that calling the `ListMovies` Query hook function returns a `UseQueryResult` object. This object holds the state of your Query, including whether the Query is loading, has completed, or has succeeded/failed, and any data returned by the Query, among other things.
|
Recall that calling the `listEvents` Query hook function returns a `UseQueryResult` object. This object holds the state of your Query, including whether the Query is loading, has completed, or has succeeded/failed, and any data returned by the Query, among other things.
|
||||||
|
|
||||||
To check the status of a Query, use the `UseQueryResult.status` field. You can also check for pending / success / error status using the `UseQueryResult.isPending`, `UseQueryResult.isSuccess`, and `UseQueryResult.isError` fields.
|
To check the status of a Query, use the `UseQueryResult.status` field. You can also check for pending / success / error status using the `UseQueryResult.isPending`, `UseQueryResult.isSuccess`, and `UseQueryResult.isError` fields.
|
||||||
|
|
||||||
To access the data returned by a Query, use the `UseQueryResult.data` field. The data for the `ListMovies` Query is of type `ListMoviesData`, which is defined in [dataconnect-generated/index.d.ts](../index.d.ts). It has the following fields:
|
To access the data returned by a Query, use the `UseQueryResult.data` field. The data for the `listEvents` Query is of type `ListEventsData`, which is defined in [dataconnect-generated/index.d.ts](../index.d.ts). It has the following fields:
|
||||||
```javascript
|
```javascript
|
||||||
export interface ListMoviesData {
|
export interface ListEventsData {
|
||||||
movies: ({
|
events: ({
|
||||||
id: UUIDString;
|
id: UUIDString;
|
||||||
title: string;
|
eventName: string;
|
||||||
imageUrl: string;
|
status: EventStatus;
|
||||||
genre?: string | null;
|
date: TimestampString;
|
||||||
} & Movie_Key)[];
|
isRecurring: boolean;
|
||||||
|
recurrenceType?: RecurrenceType | null;
|
||||||
|
businessId: UUIDString;
|
||||||
|
vendorId?: UUIDString | null;
|
||||||
|
total?: number | null;
|
||||||
|
requested?: number | null;
|
||||||
|
} & Event_Key)[];
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
To learn more about the `UseQueryResult` object, see the [TanStack React Query documentation](https://tanstack.com/query/v5/docs/framework/react/reference/useQuery).
|
To learn more about the `UseQueryResult` object, see the [TanStack React Query documentation](https://tanstack.com/query/v5/docs/framework/react/reference/useQuery).
|
||||||
|
|
||||||
### Using `ListMovies`'s Query hook function
|
### Using `listEvents`'s Query hook function
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
import { getDataConnect } from 'firebase/data-connect';
|
import { getDataConnect } from 'firebase/data-connect';
|
||||||
import { connectorConfig } from '@dataconnect/generated';
|
import { connectorConfig } from '@dataconnect/generated';
|
||||||
import { useListMovies } from '@dataconnect/generated/react'
|
import { useListEvents } from '@dataconnect/generated/react'
|
||||||
|
|
||||||
export default function ListMoviesComponent() {
|
export default function ListEventsComponent() {
|
||||||
// You don't have to do anything to "execute" the Query.
|
// You don't have to do anything to "execute" the Query.
|
||||||
// Call the Query hook function to get a `UseQueryResult` object which holds the state of your Query.
|
// Call the Query hook function to get a `UseQueryResult` object which holds the state of your Query.
|
||||||
const query = useListMovies();
|
const query = useListEvents();
|
||||||
|
|
||||||
// You can also pass in a `DataConnect` instance to the Query hook function.
|
// You can also pass in a `DataConnect` instance to the Query hook function.
|
||||||
const dataConnect = getDataConnect(connectorConfig);
|
const dataConnect = getDataConnect(connectorConfig);
|
||||||
const query = useListMovies(dataConnect);
|
const query = useListEvents(dataConnect);
|
||||||
|
|
||||||
// You can also pass in a `useDataConnectQueryOptions` object to the Query hook function.
|
// You can also pass in a `useDataConnectQueryOptions` object to the Query hook function.
|
||||||
const options = { staleTime: 5 * 1000 };
|
const options = { staleTime: 5 * 1000 };
|
||||||
const query = useListMovies(options);
|
const query = useListEvents(options);
|
||||||
|
|
||||||
// You can also pass both a `DataConnect` instance and a `useDataConnectQueryOptions` object.
|
// You can also pass both a `DataConnect` instance and a `useDataConnectQueryOptions` object.
|
||||||
const dataConnect = getDataConnect(connectorConfig);
|
const dataConnect = getDataConnect(connectorConfig);
|
||||||
const options = { staleTime: 5 * 1000 };
|
const options = { staleTime: 5 * 1000 };
|
||||||
const query = useListMovies(dataConnect, options);
|
const query = useListEvents(dataConnect, options);
|
||||||
|
|
||||||
// Then, you can render your component dynamically based on the status of the Query.
|
// Then, you can render your component dynamically based on the status of the Query.
|
||||||
if (query.isPending) {
|
if (query.isPending) {
|
||||||
@@ -186,356 +185,7 @@ export default function ListMoviesComponent() {
|
|||||||
|
|
||||||
// If the Query is successful, you can access the data returned using the `UseQueryResult.data` field.
|
// If the Query is successful, you can access the data returned using the `UseQueryResult.data` field.
|
||||||
if (query.isSuccess) {
|
if (query.isSuccess) {
|
||||||
console.log(query.data.movies);
|
console.log(query.data.events);
|
||||||
}
|
|
||||||
return <div>Query execution {query.isSuccess ? 'successful' : 'failed'}!</div>;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## ListUsers
|
|
||||||
You can execute the `ListUsers` Query using the following Query hook function, which is defined in [dataconnect-generated/react/index.d.ts](./index.d.ts):
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
useListUsers(dc: DataConnect, options?: useDataConnectQueryOptions<ListUsersData>): UseDataConnectQueryResult<ListUsersData, undefined>;
|
|
||||||
```
|
|
||||||
You can also pass in a `DataConnect` instance to the Query hook function.
|
|
||||||
```javascript
|
|
||||||
useListUsers(options?: useDataConnectQueryOptions<ListUsersData>): UseDataConnectQueryResult<ListUsersData, undefined>;
|
|
||||||
```
|
|
||||||
|
|
||||||
### Variables
|
|
||||||
The `ListUsers` Query has no variables.
|
|
||||||
### Return Type
|
|
||||||
Recall that calling the `ListUsers` Query hook function returns a `UseQueryResult` object. This object holds the state of your Query, including whether the Query is loading, has completed, or has succeeded/failed, and any data returned by the Query, among other things.
|
|
||||||
|
|
||||||
To check the status of a Query, use the `UseQueryResult.status` field. You can also check for pending / success / error status using the `UseQueryResult.isPending`, `UseQueryResult.isSuccess`, and `UseQueryResult.isError` fields.
|
|
||||||
|
|
||||||
To access the data returned by a Query, use the `UseQueryResult.data` field. The data for the `ListUsers` Query is of type `ListUsersData`, which is defined in [dataconnect-generated/index.d.ts](../index.d.ts). It has the following fields:
|
|
||||||
```javascript
|
|
||||||
export interface ListUsersData {
|
|
||||||
users: ({
|
|
||||||
id: string;
|
|
||||||
username: string;
|
|
||||||
} & User_Key)[];
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
To learn more about the `UseQueryResult` object, see the [TanStack React Query documentation](https://tanstack.com/query/v5/docs/framework/react/reference/useQuery).
|
|
||||||
|
|
||||||
### Using `ListUsers`'s Query hook function
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
import { getDataConnect } from 'firebase/data-connect';
|
|
||||||
import { connectorConfig } from '@dataconnect/generated';
|
|
||||||
import { useListUsers } from '@dataconnect/generated/react'
|
|
||||||
|
|
||||||
export default function ListUsersComponent() {
|
|
||||||
// You don't have to do anything to "execute" the Query.
|
|
||||||
// Call the Query hook function to get a `UseQueryResult` object which holds the state of your Query.
|
|
||||||
const query = useListUsers();
|
|
||||||
|
|
||||||
// You can also pass in a `DataConnect` instance to the Query hook function.
|
|
||||||
const dataConnect = getDataConnect(connectorConfig);
|
|
||||||
const query = useListUsers(dataConnect);
|
|
||||||
|
|
||||||
// You can also pass in a `useDataConnectQueryOptions` object to the Query hook function.
|
|
||||||
const options = { staleTime: 5 * 1000 };
|
|
||||||
const query = useListUsers(options);
|
|
||||||
|
|
||||||
// You can also pass both a `DataConnect` instance and a `useDataConnectQueryOptions` object.
|
|
||||||
const dataConnect = getDataConnect(connectorConfig);
|
|
||||||
const options = { staleTime: 5 * 1000 };
|
|
||||||
const query = useListUsers(dataConnect, options);
|
|
||||||
|
|
||||||
// Then, you can render your component dynamically based on the status of the Query.
|
|
||||||
if (query.isPending) {
|
|
||||||
return <div>Loading...</div>;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (query.isError) {
|
|
||||||
return <div>Error: {query.error.message}</div>;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the Query is successful, you can access the data returned using the `UseQueryResult.data` field.
|
|
||||||
if (query.isSuccess) {
|
|
||||||
console.log(query.data.users);
|
|
||||||
}
|
|
||||||
return <div>Query execution {query.isSuccess ? 'successful' : 'failed'}!</div>;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## ListUserReviews
|
|
||||||
You can execute the `ListUserReviews` Query using the following Query hook function, which is defined in [dataconnect-generated/react/index.d.ts](./index.d.ts):
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
useListUserReviews(dc: DataConnect, options?: useDataConnectQueryOptions<ListUserReviewsData>): UseDataConnectQueryResult<ListUserReviewsData, undefined>;
|
|
||||||
```
|
|
||||||
You can also pass in a `DataConnect` instance to the Query hook function.
|
|
||||||
```javascript
|
|
||||||
useListUserReviews(options?: useDataConnectQueryOptions<ListUserReviewsData>): UseDataConnectQueryResult<ListUserReviewsData, undefined>;
|
|
||||||
```
|
|
||||||
|
|
||||||
### Variables
|
|
||||||
The `ListUserReviews` Query has no variables.
|
|
||||||
### Return Type
|
|
||||||
Recall that calling the `ListUserReviews` Query hook function returns a `UseQueryResult` object. This object holds the state of your Query, including whether the Query is loading, has completed, or has succeeded/failed, and any data returned by the Query, among other things.
|
|
||||||
|
|
||||||
To check the status of a Query, use the `UseQueryResult.status` field. You can also check for pending / success / error status using the `UseQueryResult.isPending`, `UseQueryResult.isSuccess`, and `UseQueryResult.isError` fields.
|
|
||||||
|
|
||||||
To access the data returned by a Query, use the `UseQueryResult.data` field. The data for the `ListUserReviews` Query is of type `ListUserReviewsData`, which is defined in [dataconnect-generated/index.d.ts](../index.d.ts). It has the following fields:
|
|
||||||
```javascript
|
|
||||||
export interface ListUserReviewsData {
|
|
||||||
user?: {
|
|
||||||
id: string;
|
|
||||||
username: string;
|
|
||||||
reviews: ({
|
|
||||||
rating?: number | null;
|
|
||||||
reviewDate: DateString;
|
|
||||||
reviewText?: string | null;
|
|
||||||
movie: {
|
|
||||||
id: UUIDString;
|
|
||||||
title: string;
|
|
||||||
} & Movie_Key;
|
|
||||||
})[];
|
|
||||||
} & User_Key;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
To learn more about the `UseQueryResult` object, see the [TanStack React Query documentation](https://tanstack.com/query/v5/docs/framework/react/reference/useQuery).
|
|
||||||
|
|
||||||
### Using `ListUserReviews`'s Query hook function
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
import { getDataConnect } from 'firebase/data-connect';
|
|
||||||
import { connectorConfig } from '@dataconnect/generated';
|
|
||||||
import { useListUserReviews } from '@dataconnect/generated/react'
|
|
||||||
|
|
||||||
export default function ListUserReviewsComponent() {
|
|
||||||
// You don't have to do anything to "execute" the Query.
|
|
||||||
// Call the Query hook function to get a `UseQueryResult` object which holds the state of your Query.
|
|
||||||
const query = useListUserReviews();
|
|
||||||
|
|
||||||
// You can also pass in a `DataConnect` instance to the Query hook function.
|
|
||||||
const dataConnect = getDataConnect(connectorConfig);
|
|
||||||
const query = useListUserReviews(dataConnect);
|
|
||||||
|
|
||||||
// You can also pass in a `useDataConnectQueryOptions` object to the Query hook function.
|
|
||||||
const options = { staleTime: 5 * 1000 };
|
|
||||||
const query = useListUserReviews(options);
|
|
||||||
|
|
||||||
// You can also pass both a `DataConnect` instance and a `useDataConnectQueryOptions` object.
|
|
||||||
const dataConnect = getDataConnect(connectorConfig);
|
|
||||||
const options = { staleTime: 5 * 1000 };
|
|
||||||
const query = useListUserReviews(dataConnect, options);
|
|
||||||
|
|
||||||
// Then, you can render your component dynamically based on the status of the Query.
|
|
||||||
if (query.isPending) {
|
|
||||||
return <div>Loading...</div>;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (query.isError) {
|
|
||||||
return <div>Error: {query.error.message}</div>;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the Query is successful, you can access the data returned using the `UseQueryResult.data` field.
|
|
||||||
if (query.isSuccess) {
|
|
||||||
console.log(query.data.user);
|
|
||||||
}
|
|
||||||
return <div>Query execution {query.isSuccess ? 'successful' : 'failed'}!</div>;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## GetMovieById
|
|
||||||
You can execute the `GetMovieById` Query using the following Query hook function, which is defined in [dataconnect-generated/react/index.d.ts](./index.d.ts):
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
useGetMovieById(dc: DataConnect, vars: GetMovieByIdVariables, options?: useDataConnectQueryOptions<GetMovieByIdData>): UseDataConnectQueryResult<GetMovieByIdData, GetMovieByIdVariables>;
|
|
||||||
```
|
|
||||||
You can also pass in a `DataConnect` instance to the Query hook function.
|
|
||||||
```javascript
|
|
||||||
useGetMovieById(vars: GetMovieByIdVariables, options?: useDataConnectQueryOptions<GetMovieByIdData>): UseDataConnectQueryResult<GetMovieByIdData, GetMovieByIdVariables>;
|
|
||||||
```
|
|
||||||
|
|
||||||
### Variables
|
|
||||||
The `GetMovieById` Query requires an argument of type `GetMovieByIdVariables`, which is defined in [dataconnect-generated/index.d.ts](../index.d.ts). It has the following fields:
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
export interface GetMovieByIdVariables {
|
|
||||||
id: UUIDString;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
### Return Type
|
|
||||||
Recall that calling the `GetMovieById` Query hook function returns a `UseQueryResult` object. This object holds the state of your Query, including whether the Query is loading, has completed, or has succeeded/failed, and any data returned by the Query, among other things.
|
|
||||||
|
|
||||||
To check the status of a Query, use the `UseQueryResult.status` field. You can also check for pending / success / error status using the `UseQueryResult.isPending`, `UseQueryResult.isSuccess`, and `UseQueryResult.isError` fields.
|
|
||||||
|
|
||||||
To access the data returned by a Query, use the `UseQueryResult.data` field. The data for the `GetMovieById` Query is of type `GetMovieByIdData`, which is defined in [dataconnect-generated/index.d.ts](../index.d.ts). It has the following fields:
|
|
||||||
```javascript
|
|
||||||
export interface GetMovieByIdData {
|
|
||||||
movie?: {
|
|
||||||
id: UUIDString;
|
|
||||||
title: string;
|
|
||||||
imageUrl: string;
|
|
||||||
genre?: string | null;
|
|
||||||
metadata?: {
|
|
||||||
rating?: number | null;
|
|
||||||
releaseYear?: number | null;
|
|
||||||
description?: string | null;
|
|
||||||
};
|
|
||||||
reviews: ({
|
|
||||||
reviewText?: string | null;
|
|
||||||
reviewDate: DateString;
|
|
||||||
rating?: number | null;
|
|
||||||
user: {
|
|
||||||
id: string;
|
|
||||||
username: string;
|
|
||||||
} & User_Key;
|
|
||||||
})[];
|
|
||||||
} & Movie_Key;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
To learn more about the `UseQueryResult` object, see the [TanStack React Query documentation](https://tanstack.com/query/v5/docs/framework/react/reference/useQuery).
|
|
||||||
|
|
||||||
### Using `GetMovieById`'s Query hook function
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
import { getDataConnect } from 'firebase/data-connect';
|
|
||||||
import { connectorConfig, GetMovieByIdVariables } from '@dataconnect/generated';
|
|
||||||
import { useGetMovieById } from '@dataconnect/generated/react'
|
|
||||||
|
|
||||||
export default function GetMovieByIdComponent() {
|
|
||||||
// The `useGetMovieById` Query hook requires an argument of type `GetMovieByIdVariables`:
|
|
||||||
const getMovieByIdVars: GetMovieByIdVariables = {
|
|
||||||
id: ...,
|
|
||||||
};
|
|
||||||
|
|
||||||
// You don't have to do anything to "execute" the Query.
|
|
||||||
// Call the Query hook function to get a `UseQueryResult` object which holds the state of your Query.
|
|
||||||
const query = useGetMovieById(getMovieByIdVars);
|
|
||||||
// Variables can be defined inline as well.
|
|
||||||
const query = useGetMovieById({ id: ..., });
|
|
||||||
|
|
||||||
// You can also pass in a `DataConnect` instance to the Query hook function.
|
|
||||||
const dataConnect = getDataConnect(connectorConfig);
|
|
||||||
const query = useGetMovieById(dataConnect, getMovieByIdVars);
|
|
||||||
|
|
||||||
// You can also pass in a `useDataConnectQueryOptions` object to the Query hook function.
|
|
||||||
const options = { staleTime: 5 * 1000 };
|
|
||||||
const query = useGetMovieById(getMovieByIdVars, options);
|
|
||||||
|
|
||||||
// You can also pass both a `DataConnect` instance and a `useDataConnectQueryOptions` object.
|
|
||||||
const dataConnect = getDataConnect(connectorConfig);
|
|
||||||
const options = { staleTime: 5 * 1000 };
|
|
||||||
const query = useGetMovieById(dataConnect, getMovieByIdVars, options);
|
|
||||||
|
|
||||||
// Then, you can render your component dynamically based on the status of the Query.
|
|
||||||
if (query.isPending) {
|
|
||||||
return <div>Loading...</div>;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (query.isError) {
|
|
||||||
return <div>Error: {query.error.message}</div>;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the Query is successful, you can access the data returned using the `UseQueryResult.data` field.
|
|
||||||
if (query.isSuccess) {
|
|
||||||
console.log(query.data.movie);
|
|
||||||
}
|
|
||||||
return <div>Query execution {query.isSuccess ? 'successful' : 'failed'}!</div>;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## SearchMovie
|
|
||||||
You can execute the `SearchMovie` Query using the following Query hook function, which is defined in [dataconnect-generated/react/index.d.ts](./index.d.ts):
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
useSearchMovie(dc: DataConnect, vars?: SearchMovieVariables, options?: useDataConnectQueryOptions<SearchMovieData>): UseDataConnectQueryResult<SearchMovieData, SearchMovieVariables>;
|
|
||||||
```
|
|
||||||
You can also pass in a `DataConnect` instance to the Query hook function.
|
|
||||||
```javascript
|
|
||||||
useSearchMovie(vars?: SearchMovieVariables, options?: useDataConnectQueryOptions<SearchMovieData>): UseDataConnectQueryResult<SearchMovieData, SearchMovieVariables>;
|
|
||||||
```
|
|
||||||
|
|
||||||
### Variables
|
|
||||||
The `SearchMovie` Query has an optional argument of type `SearchMovieVariables`, which is defined in [dataconnect-generated/index.d.ts](../index.d.ts). It has the following fields:
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
export interface SearchMovieVariables {
|
|
||||||
titleInput?: string | null;
|
|
||||||
genre?: string | null;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
### Return Type
|
|
||||||
Recall that calling the `SearchMovie` Query hook function returns a `UseQueryResult` object. This object holds the state of your Query, including whether the Query is loading, has completed, or has succeeded/failed, and any data returned by the Query, among other things.
|
|
||||||
|
|
||||||
To check the status of a Query, use the `UseQueryResult.status` field. You can also check for pending / success / error status using the `UseQueryResult.isPending`, `UseQueryResult.isSuccess`, and `UseQueryResult.isError` fields.
|
|
||||||
|
|
||||||
To access the data returned by a Query, use the `UseQueryResult.data` field. The data for the `SearchMovie` Query is of type `SearchMovieData`, which is defined in [dataconnect-generated/index.d.ts](../index.d.ts). It has the following fields:
|
|
||||||
```javascript
|
|
||||||
export interface SearchMovieData {
|
|
||||||
movies: ({
|
|
||||||
id: UUIDString;
|
|
||||||
title: string;
|
|
||||||
genre?: string | null;
|
|
||||||
imageUrl: string;
|
|
||||||
} & Movie_Key)[];
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
To learn more about the `UseQueryResult` object, see the [TanStack React Query documentation](https://tanstack.com/query/v5/docs/framework/react/reference/useQuery).
|
|
||||||
|
|
||||||
### Using `SearchMovie`'s Query hook function
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
import { getDataConnect } from 'firebase/data-connect';
|
|
||||||
import { connectorConfig, SearchMovieVariables } from '@dataconnect/generated';
|
|
||||||
import { useSearchMovie } from '@dataconnect/generated/react'
|
|
||||||
|
|
||||||
export default function SearchMovieComponent() {
|
|
||||||
// The `useSearchMovie` Query hook has an optional argument of type `SearchMovieVariables`:
|
|
||||||
const searchMovieVars: SearchMovieVariables = {
|
|
||||||
titleInput: ..., // optional
|
|
||||||
genre: ..., // optional
|
|
||||||
};
|
|
||||||
|
|
||||||
// You don't have to do anything to "execute" the Query.
|
|
||||||
// Call the Query hook function to get a `UseQueryResult` object which holds the state of your Query.
|
|
||||||
const query = useSearchMovie(searchMovieVars);
|
|
||||||
// Variables can be defined inline as well.
|
|
||||||
const query = useSearchMovie({ titleInput: ..., genre: ..., });
|
|
||||||
// Since all variables are optional for this Query, you can omit the `SearchMovieVariables` argument.
|
|
||||||
// (as long as you don't want to provide any `options`!)
|
|
||||||
const query = useSearchMovie();
|
|
||||||
|
|
||||||
// You can also pass in a `DataConnect` instance to the Query hook function.
|
|
||||||
const dataConnect = getDataConnect(connectorConfig);
|
|
||||||
const query = useSearchMovie(dataConnect, searchMovieVars);
|
|
||||||
|
|
||||||
// You can also pass in a `useDataConnectQueryOptions` object to the Query hook function.
|
|
||||||
const options = { staleTime: 5 * 1000 };
|
|
||||||
const query = useSearchMovie(searchMovieVars, options);
|
|
||||||
// If you'd like to provide options without providing any variables, you must
|
|
||||||
// pass `undefined` where you would normally pass the variables.
|
|
||||||
const query = useSearchMovie(undefined, options);
|
|
||||||
|
|
||||||
// You can also pass both a `DataConnect` instance and a `useDataConnectQueryOptions` object.
|
|
||||||
const dataConnect = getDataConnect(connectorConfig);
|
|
||||||
const options = { staleTime: 5 * 1000 };
|
|
||||||
const query = useSearchMovie(dataConnect, searchMovieVars /** or undefined */, options);
|
|
||||||
|
|
||||||
// Then, you can render your component dynamically based on the status of the Query.
|
|
||||||
if (query.isPending) {
|
|
||||||
return <div>Loading...</div>;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (query.isError) {
|
|
||||||
return <div>Error: {query.error.message}</div>;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the Query is successful, you can access the data returned using the `UseQueryResult.data` field.
|
|
||||||
if (query.isSuccess) {
|
|
||||||
console.log(query.data.movies);
|
|
||||||
}
|
}
|
||||||
return <div>Query execution {query.isSuccess ? 'successful' : 'failed'}!</div>;
|
return <div>Query execution {query.isSuccess ? 'successful' : 'failed'}!</div>;
|
||||||
}
|
}
|
||||||
@@ -564,88 +214,104 @@ Here's a general overview of how to use the generated Mutation hooks in your cod
|
|||||||
- `UseMutationResult.mutate()` also accepts an `options` argument of type `useDataConnectMutationOptions`.
|
- `UseMutationResult.mutate()` also accepts an `options` argument of type `useDataConnectMutationOptions`.
|
||||||
- ***Special case:*** If the Mutation has no arguments (or all optional arguments and you wish to provide none), and you want to pass `options` to `UseMutationResult.mutate()`, you must pass `undefined` where you would normally pass the Mutation's arguments, and then may provide the options argument.
|
- ***Special case:*** If the Mutation has no arguments (or all optional arguments and you wish to provide none), and you want to pass `options` to `UseMutationResult.mutate()`, you must pass `undefined` where you would normally pass the Mutation's arguments, and then may provide the options argument.
|
||||||
|
|
||||||
Below are examples of how to use the `example` connector's generated Mutation hook functions to execute each Mutation. You can also follow the examples from the [Data Connect documentation](https://firebase.google.com/docs/data-connect/web-sdk#operations-react-angular).
|
Below are examples of how to use the `krow-connector` connector's generated Mutation hook functions to execute each Mutation. You can also follow the examples from the [Data Connect documentation](https://firebase.google.com/docs/data-connect/web-sdk#operations-react-angular).
|
||||||
|
|
||||||
## CreateMovie
|
## CreateEvent
|
||||||
You can execute the `CreateMovie` Mutation using the `UseMutationResult` object returned by the following Mutation hook function (which is defined in [dataconnect-generated/react/index.d.ts](./index.d.ts)):
|
You can execute the `CreateEvent` Mutation using the `UseMutationResult` object returned by the following Mutation hook function (which is defined in [dataconnect-generated/react/index.d.ts](./index.d.ts)):
|
||||||
```javascript
|
```javascript
|
||||||
useCreateMovie(options?: useDataConnectMutationOptions<CreateMovieData, FirebaseError, CreateMovieVariables>): UseDataConnectMutationResult<CreateMovieData, CreateMovieVariables>;
|
useCreateEvent(options?: useDataConnectMutationOptions<CreateEventData, FirebaseError, CreateEventVariables>): UseDataConnectMutationResult<CreateEventData, CreateEventVariables>;
|
||||||
```
|
```
|
||||||
You can also pass in a `DataConnect` instance to the Mutation hook function.
|
You can also pass in a `DataConnect` instance to the Mutation hook function.
|
||||||
```javascript
|
```javascript
|
||||||
useCreateMovie(dc: DataConnect, options?: useDataConnectMutationOptions<CreateMovieData, FirebaseError, CreateMovieVariables>): UseDataConnectMutationResult<CreateMovieData, CreateMovieVariables>;
|
useCreateEvent(dc: DataConnect, options?: useDataConnectMutationOptions<CreateEventData, FirebaseError, CreateEventVariables>): UseDataConnectMutationResult<CreateEventData, CreateEventVariables>;
|
||||||
```
|
```
|
||||||
|
|
||||||
### Variables
|
### Variables
|
||||||
The `CreateMovie` Mutation requires an argument of type `CreateMovieVariables`, which is defined in [dataconnect-generated/index.d.ts](../index.d.ts). It has the following fields:
|
The `CreateEvent` Mutation requires an argument of type `CreateEventVariables`, which is defined in [dataconnect-generated/index.d.ts](../index.d.ts). It has the following fields:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
export interface CreateMovieVariables {
|
export interface CreateEventVariables {
|
||||||
title: string;
|
eventName: string;
|
||||||
genre: string;
|
isRecurring: boolean;
|
||||||
imageUrl: string;
|
recurrenceType?: RecurrenceType | null;
|
||||||
|
businessId: UUIDString;
|
||||||
|
vendorId?: UUIDString | null;
|
||||||
|
status: EventStatus;
|
||||||
|
date: TimestampString;
|
||||||
|
shifts?: string | null;
|
||||||
|
total?: number | null;
|
||||||
|
requested?: number | null;
|
||||||
|
assignedStaff?: string | null;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
### Return Type
|
### Return Type
|
||||||
Recall that calling the `CreateMovie` Mutation hook function returns a `UseMutationResult` object. This object holds the state of your Mutation, including whether the Mutation is loading, has completed, or has succeeded/failed, among other things.
|
Recall that calling the `CreateEvent` Mutation hook function returns a `UseMutationResult` object. This object holds the state of your Mutation, including whether the Mutation is loading, has completed, or has succeeded/failed, among other things.
|
||||||
|
|
||||||
To check the status of a Mutation, use the `UseMutationResult.status` field. You can also check for pending / success / error status using the `UseMutationResult.isPending`, `UseMutationResult.isSuccess`, and `UseMutationResult.isError` fields.
|
To check the status of a Mutation, use the `UseMutationResult.status` field. You can also check for pending / success / error status using the `UseMutationResult.isPending`, `UseMutationResult.isSuccess`, and `UseMutationResult.isError` fields.
|
||||||
|
|
||||||
To execute the Mutation, call `UseMutationResult.mutate()`. This function executes the Mutation, but does not return the data from the Mutation.
|
To execute the Mutation, call `UseMutationResult.mutate()`. This function executes the Mutation, but does not return the data from the Mutation.
|
||||||
|
|
||||||
To access the data returned by a Mutation, use the `UseMutationResult.data` field. The data for the `CreateMovie` Mutation is of type `CreateMovieData`, which is defined in [dataconnect-generated/index.d.ts](../index.d.ts). It has the following fields:
|
To access the data returned by a Mutation, use the `UseMutationResult.data` field. The data for the `CreateEvent` Mutation is of type `CreateEventData`, which is defined in [dataconnect-generated/index.d.ts](../index.d.ts). It has the following fields:
|
||||||
```javascript
|
```javascript
|
||||||
export interface CreateMovieData {
|
export interface CreateEventData {
|
||||||
movie_insert: Movie_Key;
|
event_insert: Event_Key;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
To learn more about the `UseMutationResult` object, see the [TanStack React Query documentation](https://tanstack.com/query/v5/docs/framework/react/reference/useMutation).
|
To learn more about the `UseMutationResult` object, see the [TanStack React Query documentation](https://tanstack.com/query/v5/docs/framework/react/reference/useMutation).
|
||||||
|
|
||||||
### Using `CreateMovie`'s Mutation hook function
|
### Using `CreateEvent`'s Mutation hook function
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
import { getDataConnect } from 'firebase/data-connect';
|
import { getDataConnect } from 'firebase/data-connect';
|
||||||
import { connectorConfig, CreateMovieVariables } from '@dataconnect/generated';
|
import { connectorConfig, CreateEventVariables } from '@dataconnect/generated';
|
||||||
import { useCreateMovie } from '@dataconnect/generated/react'
|
import { useCreateEvent } from '@dataconnect/generated/react'
|
||||||
|
|
||||||
export default function CreateMovieComponent() {
|
export default function CreateEventComponent() {
|
||||||
// Call the Mutation hook function to get a `UseMutationResult` object which holds the state of your Mutation.
|
// Call the Mutation hook function to get a `UseMutationResult` object which holds the state of your Mutation.
|
||||||
const mutation = useCreateMovie();
|
const mutation = useCreateEvent();
|
||||||
|
|
||||||
// You can also pass in a `DataConnect` instance to the Mutation hook function.
|
// You can also pass in a `DataConnect` instance to the Mutation hook function.
|
||||||
const dataConnect = getDataConnect(connectorConfig);
|
const dataConnect = getDataConnect(connectorConfig);
|
||||||
const mutation = useCreateMovie(dataConnect);
|
const mutation = useCreateEvent(dataConnect);
|
||||||
|
|
||||||
// You can also pass in a `useDataConnectMutationOptions` object to the Mutation hook function.
|
// You can also pass in a `useDataConnectMutationOptions` object to the Mutation hook function.
|
||||||
const options = {
|
const options = {
|
||||||
onSuccess: () => { console.log('Mutation succeeded!'); }
|
onSuccess: () => { console.log('Mutation succeeded!'); }
|
||||||
};
|
};
|
||||||
const mutation = useCreateMovie(options);
|
const mutation = useCreateEvent(options);
|
||||||
|
|
||||||
// You can also pass both a `DataConnect` instance and a `useDataConnectMutationOptions` object.
|
// You can also pass both a `DataConnect` instance and a `useDataConnectMutationOptions` object.
|
||||||
const dataConnect = getDataConnect(connectorConfig);
|
const dataConnect = getDataConnect(connectorConfig);
|
||||||
const options = {
|
const options = {
|
||||||
onSuccess: () => { console.log('Mutation succeeded!'); }
|
onSuccess: () => { console.log('Mutation succeeded!'); }
|
||||||
};
|
};
|
||||||
const mutation = useCreateMovie(dataConnect, options);
|
const mutation = useCreateEvent(dataConnect, options);
|
||||||
|
|
||||||
// After calling the Mutation hook function, you must call `UseMutationResult.mutate()` to execute the Mutation.
|
// After calling the Mutation hook function, you must call `UseMutationResult.mutate()` to execute the Mutation.
|
||||||
// The `useCreateMovie` Mutation requires an argument of type `CreateMovieVariables`:
|
// The `useCreateEvent` Mutation requires an argument of type `CreateEventVariables`:
|
||||||
const createMovieVars: CreateMovieVariables = {
|
const createEventVars: CreateEventVariables = {
|
||||||
title: ...,
|
eventName: ...,
|
||||||
genre: ...,
|
isRecurring: ...,
|
||||||
imageUrl: ...,
|
recurrenceType: ..., // optional
|
||||||
|
businessId: ...,
|
||||||
|
vendorId: ..., // optional
|
||||||
|
status: ...,
|
||||||
|
date: ...,
|
||||||
|
shifts: ..., // optional
|
||||||
|
total: ..., // optional
|
||||||
|
requested: ..., // optional
|
||||||
|
assignedStaff: ..., // optional
|
||||||
};
|
};
|
||||||
mutation.mutate(createMovieVars);
|
mutation.mutate(createEventVars);
|
||||||
// Variables can be defined inline as well.
|
// Variables can be defined inline as well.
|
||||||
mutation.mutate({ title: ..., genre: ..., imageUrl: ..., });
|
mutation.mutate({ eventName: ..., isRecurring: ..., recurrenceType: ..., businessId: ..., vendorId: ..., status: ..., date: ..., shifts: ..., total: ..., requested: ..., assignedStaff: ..., });
|
||||||
|
|
||||||
// You can also pass in a `useDataConnectMutationOptions` object to `UseMutationResult.mutate()`.
|
// You can also pass in a `useDataConnectMutationOptions` object to `UseMutationResult.mutate()`.
|
||||||
const options = {
|
const options = {
|
||||||
onSuccess: () => { console.log('Mutation succeeded!'); }
|
onSuccess: () => { console.log('Mutation succeeded!'); }
|
||||||
};
|
};
|
||||||
mutation.mutate(createMovieVars, options);
|
mutation.mutate(createEventVars, options);
|
||||||
|
|
||||||
// Then, you can render your component dynamically based on the status of the Mutation.
|
// Then, you can render your component dynamically based on the status of the Mutation.
|
||||||
if (mutation.isPending) {
|
if (mutation.isPending) {
|
||||||
@@ -658,293 +324,7 @@ export default function CreateMovieComponent() {
|
|||||||
|
|
||||||
// If the Mutation is successful, you can access the data returned using the `UseMutationResult.data` field.
|
// If the Mutation is successful, you can access the data returned using the `UseMutationResult.data` field.
|
||||||
if (mutation.isSuccess) {
|
if (mutation.isSuccess) {
|
||||||
console.log(mutation.data.movie_insert);
|
console.log(mutation.data.event_insert);
|
||||||
}
|
|
||||||
return <div>Mutation execution {mutation.isSuccess ? 'successful' : 'failed'}!</div>;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## UpsertUser
|
|
||||||
You can execute the `UpsertUser` Mutation using the `UseMutationResult` object returned by the following Mutation hook function (which is defined in [dataconnect-generated/react/index.d.ts](./index.d.ts)):
|
|
||||||
```javascript
|
|
||||||
useUpsertUser(options?: useDataConnectMutationOptions<UpsertUserData, FirebaseError, UpsertUserVariables>): UseDataConnectMutationResult<UpsertUserData, UpsertUserVariables>;
|
|
||||||
```
|
|
||||||
You can also pass in a `DataConnect` instance to the Mutation hook function.
|
|
||||||
```javascript
|
|
||||||
useUpsertUser(dc: DataConnect, options?: useDataConnectMutationOptions<UpsertUserData, FirebaseError, UpsertUserVariables>): UseDataConnectMutationResult<UpsertUserData, UpsertUserVariables>;
|
|
||||||
```
|
|
||||||
|
|
||||||
### Variables
|
|
||||||
The `UpsertUser` Mutation requires an argument of type `UpsertUserVariables`, which is defined in [dataconnect-generated/index.d.ts](../index.d.ts). It has the following fields:
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
export interface UpsertUserVariables {
|
|
||||||
username: string;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
### Return Type
|
|
||||||
Recall that calling the `UpsertUser` Mutation hook function returns a `UseMutationResult` object. This object holds the state of your Mutation, including whether the Mutation is loading, has completed, or has succeeded/failed, among other things.
|
|
||||||
|
|
||||||
To check the status of a Mutation, use the `UseMutationResult.status` field. You can also check for pending / success / error status using the `UseMutationResult.isPending`, `UseMutationResult.isSuccess`, and `UseMutationResult.isError` fields.
|
|
||||||
|
|
||||||
To execute the Mutation, call `UseMutationResult.mutate()`. This function executes the Mutation, but does not return the data from the Mutation.
|
|
||||||
|
|
||||||
To access the data returned by a Mutation, use the `UseMutationResult.data` field. The data for the `UpsertUser` Mutation is of type `UpsertUserData`, which is defined in [dataconnect-generated/index.d.ts](../index.d.ts). It has the following fields:
|
|
||||||
```javascript
|
|
||||||
export interface UpsertUserData {
|
|
||||||
user_upsert: User_Key;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
To learn more about the `UseMutationResult` object, see the [TanStack React Query documentation](https://tanstack.com/query/v5/docs/framework/react/reference/useMutation).
|
|
||||||
|
|
||||||
### Using `UpsertUser`'s Mutation hook function
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
import { getDataConnect } from 'firebase/data-connect';
|
|
||||||
import { connectorConfig, UpsertUserVariables } from '@dataconnect/generated';
|
|
||||||
import { useUpsertUser } from '@dataconnect/generated/react'
|
|
||||||
|
|
||||||
export default function UpsertUserComponent() {
|
|
||||||
// Call the Mutation hook function to get a `UseMutationResult` object which holds the state of your Mutation.
|
|
||||||
const mutation = useUpsertUser();
|
|
||||||
|
|
||||||
// You can also pass in a `DataConnect` instance to the Mutation hook function.
|
|
||||||
const dataConnect = getDataConnect(connectorConfig);
|
|
||||||
const mutation = useUpsertUser(dataConnect);
|
|
||||||
|
|
||||||
// You can also pass in a `useDataConnectMutationOptions` object to the Mutation hook function.
|
|
||||||
const options = {
|
|
||||||
onSuccess: () => { console.log('Mutation succeeded!'); }
|
|
||||||
};
|
|
||||||
const mutation = useUpsertUser(options);
|
|
||||||
|
|
||||||
// You can also pass both a `DataConnect` instance and a `useDataConnectMutationOptions` object.
|
|
||||||
const dataConnect = getDataConnect(connectorConfig);
|
|
||||||
const options = {
|
|
||||||
onSuccess: () => { console.log('Mutation succeeded!'); }
|
|
||||||
};
|
|
||||||
const mutation = useUpsertUser(dataConnect, options);
|
|
||||||
|
|
||||||
// After calling the Mutation hook function, you must call `UseMutationResult.mutate()` to execute the Mutation.
|
|
||||||
// The `useUpsertUser` Mutation requires an argument of type `UpsertUserVariables`:
|
|
||||||
const upsertUserVars: UpsertUserVariables = {
|
|
||||||
username: ...,
|
|
||||||
};
|
|
||||||
mutation.mutate(upsertUserVars);
|
|
||||||
// Variables can be defined inline as well.
|
|
||||||
mutation.mutate({ username: ..., });
|
|
||||||
|
|
||||||
// You can also pass in a `useDataConnectMutationOptions` object to `UseMutationResult.mutate()`.
|
|
||||||
const options = {
|
|
||||||
onSuccess: () => { console.log('Mutation succeeded!'); }
|
|
||||||
};
|
|
||||||
mutation.mutate(upsertUserVars, options);
|
|
||||||
|
|
||||||
// Then, you can render your component dynamically based on the status of the Mutation.
|
|
||||||
if (mutation.isPending) {
|
|
||||||
return <div>Loading...</div>;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mutation.isError) {
|
|
||||||
return <div>Error: {mutation.error.message}</div>;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the Mutation is successful, you can access the data returned using the `UseMutationResult.data` field.
|
|
||||||
if (mutation.isSuccess) {
|
|
||||||
console.log(mutation.data.user_upsert);
|
|
||||||
}
|
|
||||||
return <div>Mutation execution {mutation.isSuccess ? 'successful' : 'failed'}!</div>;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## AddReview
|
|
||||||
You can execute the `AddReview` Mutation using the `UseMutationResult` object returned by the following Mutation hook function (which is defined in [dataconnect-generated/react/index.d.ts](./index.d.ts)):
|
|
||||||
```javascript
|
|
||||||
useAddReview(options?: useDataConnectMutationOptions<AddReviewData, FirebaseError, AddReviewVariables>): UseDataConnectMutationResult<AddReviewData, AddReviewVariables>;
|
|
||||||
```
|
|
||||||
You can also pass in a `DataConnect` instance to the Mutation hook function.
|
|
||||||
```javascript
|
|
||||||
useAddReview(dc: DataConnect, options?: useDataConnectMutationOptions<AddReviewData, FirebaseError, AddReviewVariables>): UseDataConnectMutationResult<AddReviewData, AddReviewVariables>;
|
|
||||||
```
|
|
||||||
|
|
||||||
### Variables
|
|
||||||
The `AddReview` Mutation requires an argument of type `AddReviewVariables`, which is defined in [dataconnect-generated/index.d.ts](../index.d.ts). It has the following fields:
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
export interface AddReviewVariables {
|
|
||||||
movieId: UUIDString;
|
|
||||||
rating: number;
|
|
||||||
reviewText: string;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
### Return Type
|
|
||||||
Recall that calling the `AddReview` Mutation hook function returns a `UseMutationResult` object. This object holds the state of your Mutation, including whether the Mutation is loading, has completed, or has succeeded/failed, among other things.
|
|
||||||
|
|
||||||
To check the status of a Mutation, use the `UseMutationResult.status` field. You can also check for pending / success / error status using the `UseMutationResult.isPending`, `UseMutationResult.isSuccess`, and `UseMutationResult.isError` fields.
|
|
||||||
|
|
||||||
To execute the Mutation, call `UseMutationResult.mutate()`. This function executes the Mutation, but does not return the data from the Mutation.
|
|
||||||
|
|
||||||
To access the data returned by a Mutation, use the `UseMutationResult.data` field. The data for the `AddReview` Mutation is of type `AddReviewData`, which is defined in [dataconnect-generated/index.d.ts](../index.d.ts). It has the following fields:
|
|
||||||
```javascript
|
|
||||||
export interface AddReviewData {
|
|
||||||
review_upsert: Review_Key;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
To learn more about the `UseMutationResult` object, see the [TanStack React Query documentation](https://tanstack.com/query/v5/docs/framework/react/reference/useMutation).
|
|
||||||
|
|
||||||
### Using `AddReview`'s Mutation hook function
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
import { getDataConnect } from 'firebase/data-connect';
|
|
||||||
import { connectorConfig, AddReviewVariables } from '@dataconnect/generated';
|
|
||||||
import { useAddReview } from '@dataconnect/generated/react'
|
|
||||||
|
|
||||||
export default function AddReviewComponent() {
|
|
||||||
// Call the Mutation hook function to get a `UseMutationResult` object which holds the state of your Mutation.
|
|
||||||
const mutation = useAddReview();
|
|
||||||
|
|
||||||
// You can also pass in a `DataConnect` instance to the Mutation hook function.
|
|
||||||
const dataConnect = getDataConnect(connectorConfig);
|
|
||||||
const mutation = useAddReview(dataConnect);
|
|
||||||
|
|
||||||
// You can also pass in a `useDataConnectMutationOptions` object to the Mutation hook function.
|
|
||||||
const options = {
|
|
||||||
onSuccess: () => { console.log('Mutation succeeded!'); }
|
|
||||||
};
|
|
||||||
const mutation = useAddReview(options);
|
|
||||||
|
|
||||||
// You can also pass both a `DataConnect` instance and a `useDataConnectMutationOptions` object.
|
|
||||||
const dataConnect = getDataConnect(connectorConfig);
|
|
||||||
const options = {
|
|
||||||
onSuccess: () => { console.log('Mutation succeeded!'); }
|
|
||||||
};
|
|
||||||
const mutation = useAddReview(dataConnect, options);
|
|
||||||
|
|
||||||
// After calling the Mutation hook function, you must call `UseMutationResult.mutate()` to execute the Mutation.
|
|
||||||
// The `useAddReview` Mutation requires an argument of type `AddReviewVariables`:
|
|
||||||
const addReviewVars: AddReviewVariables = {
|
|
||||||
movieId: ...,
|
|
||||||
rating: ...,
|
|
||||||
reviewText: ...,
|
|
||||||
};
|
|
||||||
mutation.mutate(addReviewVars);
|
|
||||||
// Variables can be defined inline as well.
|
|
||||||
mutation.mutate({ movieId: ..., rating: ..., reviewText: ..., });
|
|
||||||
|
|
||||||
// You can also pass in a `useDataConnectMutationOptions` object to `UseMutationResult.mutate()`.
|
|
||||||
const options = {
|
|
||||||
onSuccess: () => { console.log('Mutation succeeded!'); }
|
|
||||||
};
|
|
||||||
mutation.mutate(addReviewVars, options);
|
|
||||||
|
|
||||||
// Then, you can render your component dynamically based on the status of the Mutation.
|
|
||||||
if (mutation.isPending) {
|
|
||||||
return <div>Loading...</div>;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mutation.isError) {
|
|
||||||
return <div>Error: {mutation.error.message}</div>;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the Mutation is successful, you can access the data returned using the `UseMutationResult.data` field.
|
|
||||||
if (mutation.isSuccess) {
|
|
||||||
console.log(mutation.data.review_upsert);
|
|
||||||
}
|
|
||||||
return <div>Mutation execution {mutation.isSuccess ? 'successful' : 'failed'}!</div>;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## DeleteReview
|
|
||||||
You can execute the `DeleteReview` Mutation using the `UseMutationResult` object returned by the following Mutation hook function (which is defined in [dataconnect-generated/react/index.d.ts](./index.d.ts)):
|
|
||||||
```javascript
|
|
||||||
useDeleteReview(options?: useDataConnectMutationOptions<DeleteReviewData, FirebaseError, DeleteReviewVariables>): UseDataConnectMutationResult<DeleteReviewData, DeleteReviewVariables>;
|
|
||||||
```
|
|
||||||
You can also pass in a `DataConnect` instance to the Mutation hook function.
|
|
||||||
```javascript
|
|
||||||
useDeleteReview(dc: DataConnect, options?: useDataConnectMutationOptions<DeleteReviewData, FirebaseError, DeleteReviewVariables>): UseDataConnectMutationResult<DeleteReviewData, DeleteReviewVariables>;
|
|
||||||
```
|
|
||||||
|
|
||||||
### Variables
|
|
||||||
The `DeleteReview` Mutation requires an argument of type `DeleteReviewVariables`, which is defined in [dataconnect-generated/index.d.ts](../index.d.ts). It has the following fields:
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
export interface DeleteReviewVariables {
|
|
||||||
movieId: UUIDString;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
### Return Type
|
|
||||||
Recall that calling the `DeleteReview` Mutation hook function returns a `UseMutationResult` object. This object holds the state of your Mutation, including whether the Mutation is loading, has completed, or has succeeded/failed, among other things.
|
|
||||||
|
|
||||||
To check the status of a Mutation, use the `UseMutationResult.status` field. You can also check for pending / success / error status using the `UseMutationResult.isPending`, `UseMutationResult.isSuccess`, and `UseMutationResult.isError` fields.
|
|
||||||
|
|
||||||
To execute the Mutation, call `UseMutationResult.mutate()`. This function executes the Mutation, but does not return the data from the Mutation.
|
|
||||||
|
|
||||||
To access the data returned by a Mutation, use the `UseMutationResult.data` field. The data for the `DeleteReview` Mutation is of type `DeleteReviewData`, which is defined in [dataconnect-generated/index.d.ts](../index.d.ts). It has the following fields:
|
|
||||||
```javascript
|
|
||||||
export interface DeleteReviewData {
|
|
||||||
review_delete?: Review_Key | null;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
To learn more about the `UseMutationResult` object, see the [TanStack React Query documentation](https://tanstack.com/query/v5/docs/framework/react/reference/useMutation).
|
|
||||||
|
|
||||||
### Using `DeleteReview`'s Mutation hook function
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
import { getDataConnect } from 'firebase/data-connect';
|
|
||||||
import { connectorConfig, DeleteReviewVariables } from '@dataconnect/generated';
|
|
||||||
import { useDeleteReview } from '@dataconnect/generated/react'
|
|
||||||
|
|
||||||
export default function DeleteReviewComponent() {
|
|
||||||
// Call the Mutation hook function to get a `UseMutationResult` object which holds the state of your Mutation.
|
|
||||||
const mutation = useDeleteReview();
|
|
||||||
|
|
||||||
// You can also pass in a `DataConnect` instance to the Mutation hook function.
|
|
||||||
const dataConnect = getDataConnect(connectorConfig);
|
|
||||||
const mutation = useDeleteReview(dataConnect);
|
|
||||||
|
|
||||||
// You can also pass in a `useDataConnectMutationOptions` object to the Mutation hook function.
|
|
||||||
const options = {
|
|
||||||
onSuccess: () => { console.log('Mutation succeeded!'); }
|
|
||||||
};
|
|
||||||
const mutation = useDeleteReview(options);
|
|
||||||
|
|
||||||
// You can also pass both a `DataConnect` instance and a `useDataConnectMutationOptions` object.
|
|
||||||
const dataConnect = getDataConnect(connectorConfig);
|
|
||||||
const options = {
|
|
||||||
onSuccess: () => { console.log('Mutation succeeded!'); }
|
|
||||||
};
|
|
||||||
const mutation = useDeleteReview(dataConnect, options);
|
|
||||||
|
|
||||||
// After calling the Mutation hook function, you must call `UseMutationResult.mutate()` to execute the Mutation.
|
|
||||||
// The `useDeleteReview` Mutation requires an argument of type `DeleteReviewVariables`:
|
|
||||||
const deleteReviewVars: DeleteReviewVariables = {
|
|
||||||
movieId: ...,
|
|
||||||
};
|
|
||||||
mutation.mutate(deleteReviewVars);
|
|
||||||
// Variables can be defined inline as well.
|
|
||||||
mutation.mutate({ movieId: ..., });
|
|
||||||
|
|
||||||
// You can also pass in a `useDataConnectMutationOptions` object to `UseMutationResult.mutate()`.
|
|
||||||
const options = {
|
|
||||||
onSuccess: () => { console.log('Mutation succeeded!'); }
|
|
||||||
};
|
|
||||||
mutation.mutate(deleteReviewVars, options);
|
|
||||||
|
|
||||||
// Then, you can render your component dynamically based on the status of the Mutation.
|
|
||||||
if (mutation.isPending) {
|
|
||||||
return <div>Loading...</div>;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mutation.isError) {
|
|
||||||
return <div>Error: {mutation.error.message}</div>;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the Mutation is successful, you can access the data returned using the `UseMutationResult.data` field.
|
|
||||||
if (mutation.isSuccess) {
|
|
||||||
console.log(mutation.data.review_delete);
|
|
||||||
}
|
}
|
||||||
return <div>Mutation execution {mutation.isSuccess ? 'successful' : 'failed'}!</div>;
|
return <div>Mutation execution {mutation.isSuccess ? 'successful' : 'failed'}!</div>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,66 +1,18 @@
|
|||||||
import { createMovieRef, upsertUserRef, addReviewRef, deleteReviewRef, listMoviesRef, listUsersRef, listUserReviewsRef, getMovieByIdRef, searchMovieRef, connectorConfig } from '../../esm/index.esm.js';
|
import { createEventRef, listEventsRef, connectorConfig } from '../../esm/index.esm.js';
|
||||||
import { validateArgs, CallerSdkTypeEnum } from 'firebase/data-connect';
|
import { validateArgs, CallerSdkTypeEnum } from 'firebase/data-connect';
|
||||||
import { useDataConnectQuery, useDataConnectMutation, validateReactArgs } from '@tanstack-query-firebase/react/data-connect';
|
import { useDataConnectQuery, useDataConnectMutation, validateReactArgs } from '@tanstack-query-firebase/react/data-connect';
|
||||||
|
|
||||||
export function useCreateMovie(dcOrOptions, options) {
|
export function useCreateEvent(dcOrOptions, options) {
|
||||||
const { dc: dcInstance, vars: inputOpts } = validateArgs(connectorConfig, dcOrOptions, options);
|
const { dc: dcInstance, vars: inputOpts } = validateArgs(connectorConfig, dcOrOptions, options);
|
||||||
function refFactory(vars) {
|
function refFactory(vars) {
|
||||||
return createMovieRef(dcInstance, vars);
|
return createEventRef(dcInstance, vars);
|
||||||
}
|
|
||||||
return useDataConnectMutation(refFactory, inputOpts, CallerSdkTypeEnum.GeneratedReact);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useUpsertUser(dcOrOptions, options) {
|
|
||||||
const { dc: dcInstance, vars: inputOpts } = validateArgs(connectorConfig, dcOrOptions, options);
|
|
||||||
function refFactory(vars) {
|
|
||||||
return upsertUserRef(dcInstance, vars);
|
|
||||||
}
|
|
||||||
return useDataConnectMutation(refFactory, inputOpts, CallerSdkTypeEnum.GeneratedReact);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useAddReview(dcOrOptions, options) {
|
|
||||||
const { dc: dcInstance, vars: inputOpts } = validateArgs(connectorConfig, dcOrOptions, options);
|
|
||||||
function refFactory(vars) {
|
|
||||||
return addReviewRef(dcInstance, vars);
|
|
||||||
}
|
|
||||||
return useDataConnectMutation(refFactory, inputOpts, CallerSdkTypeEnum.GeneratedReact);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useDeleteReview(dcOrOptions, options) {
|
|
||||||
const { dc: dcInstance, vars: inputOpts } = validateArgs(connectorConfig, dcOrOptions, options);
|
|
||||||
function refFactory(vars) {
|
|
||||||
return deleteReviewRef(dcInstance, vars);
|
|
||||||
}
|
}
|
||||||
return useDataConnectMutation(refFactory, inputOpts, CallerSdkTypeEnum.GeneratedReact);
|
return useDataConnectMutation(refFactory, inputOpts, CallerSdkTypeEnum.GeneratedReact);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export function useListMovies(dcOrOptions, options) {
|
export function useListEvents(dcOrOptions, options) {
|
||||||
const { dc: dcInstance, options: inputOpts } = validateReactArgs(connectorConfig, dcOrOptions, options);
|
const { dc: dcInstance, options: inputOpts } = validateReactArgs(connectorConfig, dcOrOptions, options);
|
||||||
const ref = listMoviesRef(dcInstance);
|
const ref = listEventsRef(dcInstance);
|
||||||
return useDataConnectQuery(ref, inputOpts, CallerSdkTypeEnum.GeneratedReact);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useListUsers(dcOrOptions, options) {
|
|
||||||
const { dc: dcInstance, options: inputOpts } = validateReactArgs(connectorConfig, dcOrOptions, options);
|
|
||||||
const ref = listUsersRef(dcInstance);
|
|
||||||
return useDataConnectQuery(ref, inputOpts, CallerSdkTypeEnum.GeneratedReact);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useListUserReviews(dcOrOptions, options) {
|
|
||||||
const { dc: dcInstance, options: inputOpts } = validateReactArgs(connectorConfig, dcOrOptions, options);
|
|
||||||
const ref = listUserReviewsRef(dcInstance);
|
|
||||||
return useDataConnectQuery(ref, inputOpts, CallerSdkTypeEnum.GeneratedReact);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useGetMovieById(dcOrVars, varsOrOptions, options) {
|
|
||||||
const { dc: dcInstance, vars: inputVars, options: inputOpts } = validateReactArgs(connectorConfig, dcOrVars, varsOrOptions, options, true, true);
|
|
||||||
const ref = getMovieByIdRef(dcInstance, inputVars);
|
|
||||||
return useDataConnectQuery(ref, inputOpts, CallerSdkTypeEnum.GeneratedReact);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useSearchMovie(dcOrVars, varsOrOptions, options) {
|
|
||||||
const { dc: dcInstance, vars: inputVars, options: inputOpts } = validateReactArgs(connectorConfig, dcOrVars, varsOrOptions, options, true, false);
|
|
||||||
const ref = searchMovieRef(dcInstance, inputVars);
|
|
||||||
return useDataConnectQuery(ref, inputOpts, CallerSdkTypeEnum.GeneratedReact);
|
return useDataConnectQuery(ref, inputOpts, CallerSdkTypeEnum.GeneratedReact);
|
||||||
}
|
}
|
||||||
@@ -1,66 +1,18 @@
|
|||||||
const { createMovieRef, upsertUserRef, addReviewRef, deleteReviewRef, listMoviesRef, listUsersRef, listUserReviewsRef, getMovieByIdRef, searchMovieRef, connectorConfig } = require('../index.cjs.js');
|
const { createEventRef, listEventsRef, connectorConfig } = require('../index.cjs.js');
|
||||||
const { validateArgs, CallerSdkTypeEnum } = require('firebase/data-connect');
|
const { validateArgs, CallerSdkTypeEnum } = require('firebase/data-connect');
|
||||||
const { useDataConnectQuery, useDataConnectMutation, validateReactArgs } = require('@tanstack-query-firebase/react/data-connect');
|
const { useDataConnectQuery, useDataConnectMutation, validateReactArgs } = require('@tanstack-query-firebase/react/data-connect');
|
||||||
|
|
||||||
exports.useCreateMovie = function useCreateMovie(dcOrOptions, options) {
|
exports.useCreateEvent = function useCreateEvent(dcOrOptions, options) {
|
||||||
const { dc: dcInstance, vars: inputOpts } = validateArgs(connectorConfig, dcOrOptions, options);
|
const { dc: dcInstance, vars: inputOpts } = validateArgs(connectorConfig, dcOrOptions, options);
|
||||||
function refFactory(vars) {
|
function refFactory(vars) {
|
||||||
return createMovieRef(dcInstance, vars);
|
return createEventRef(dcInstance, vars);
|
||||||
}
|
|
||||||
return useDataConnectMutation(refFactory, inputOpts, CallerSdkTypeEnum.GeneratedReact);
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.useUpsertUser = function useUpsertUser(dcOrOptions, options) {
|
|
||||||
const { dc: dcInstance, vars: inputOpts } = validateArgs(connectorConfig, dcOrOptions, options);
|
|
||||||
function refFactory(vars) {
|
|
||||||
return upsertUserRef(dcInstance, vars);
|
|
||||||
}
|
|
||||||
return useDataConnectMutation(refFactory, inputOpts, CallerSdkTypeEnum.GeneratedReact);
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.useAddReview = function useAddReview(dcOrOptions, options) {
|
|
||||||
const { dc: dcInstance, vars: inputOpts } = validateArgs(connectorConfig, dcOrOptions, options);
|
|
||||||
function refFactory(vars) {
|
|
||||||
return addReviewRef(dcInstance, vars);
|
|
||||||
}
|
|
||||||
return useDataConnectMutation(refFactory, inputOpts, CallerSdkTypeEnum.GeneratedReact);
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.useDeleteReview = function useDeleteReview(dcOrOptions, options) {
|
|
||||||
const { dc: dcInstance, vars: inputOpts } = validateArgs(connectorConfig, dcOrOptions, options);
|
|
||||||
function refFactory(vars) {
|
|
||||||
return deleteReviewRef(dcInstance, vars);
|
|
||||||
}
|
}
|
||||||
return useDataConnectMutation(refFactory, inputOpts, CallerSdkTypeEnum.GeneratedReact);
|
return useDataConnectMutation(refFactory, inputOpts, CallerSdkTypeEnum.GeneratedReact);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
exports.useListMovies = function useListMovies(dcOrOptions, options) {
|
exports.useListEvents = function useListEvents(dcOrOptions, options) {
|
||||||
const { dc: dcInstance, options: inputOpts } = validateReactArgs(connectorConfig, dcOrOptions, options);
|
const { dc: dcInstance, options: inputOpts } = validateReactArgs(connectorConfig, dcOrOptions, options);
|
||||||
const ref = listMoviesRef(dcInstance);
|
const ref = listEventsRef(dcInstance);
|
||||||
return useDataConnectQuery(ref, inputOpts, CallerSdkTypeEnum.GeneratedReact);
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.useListUsers = function useListUsers(dcOrOptions, options) {
|
|
||||||
const { dc: dcInstance, options: inputOpts } = validateReactArgs(connectorConfig, dcOrOptions, options);
|
|
||||||
const ref = listUsersRef(dcInstance);
|
|
||||||
return useDataConnectQuery(ref, inputOpts, CallerSdkTypeEnum.GeneratedReact);
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.useListUserReviews = function useListUserReviews(dcOrOptions, options) {
|
|
||||||
const { dc: dcInstance, options: inputOpts } = validateReactArgs(connectorConfig, dcOrOptions, options);
|
|
||||||
const ref = listUserReviewsRef(dcInstance);
|
|
||||||
return useDataConnectQuery(ref, inputOpts, CallerSdkTypeEnum.GeneratedReact);
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.useGetMovieById = function useGetMovieById(dcOrVars, varsOrOptions, options) {
|
|
||||||
const { dc: dcInstance, vars: inputVars, options: inputOpts } = validateReactArgs(connectorConfig, dcOrVars, varsOrOptions, options, true, true);
|
|
||||||
const ref = getMovieByIdRef(dcInstance, inputVars);
|
|
||||||
return useDataConnectQuery(ref, inputOpts, CallerSdkTypeEnum.GeneratedReact);
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.useSearchMovie = function useSearchMovie(dcOrVars, varsOrOptions, options) {
|
|
||||||
const { dc: dcInstance, vars: inputVars, options: inputOpts } = validateReactArgs(connectorConfig, dcOrVars, varsOrOptions, options, true, false);
|
|
||||||
const ref = searchMovieRef(dcInstance, inputVars);
|
|
||||||
return useDataConnectQuery(ref, inputOpts, CallerSdkTypeEnum.GeneratedReact);
|
return useDataConnectQuery(ref, inputOpts, CallerSdkTypeEnum.GeneratedReact);
|
||||||
}
|
}
|
||||||
@@ -1,33 +1,12 @@
|
|||||||
import { CreateMovieData, CreateMovieVariables, UpsertUserData, UpsertUserVariables, AddReviewData, AddReviewVariables, DeleteReviewData, DeleteReviewVariables, ListMoviesData, ListUsersData, ListUserReviewsData, GetMovieByIdData, GetMovieByIdVariables, SearchMovieData, SearchMovieVariables } from '../';
|
import { CreateEventData, CreateEventVariables, ListEventsData } from '../';
|
||||||
import { UseDataConnectQueryResult, useDataConnectQueryOptions, UseDataConnectMutationResult, useDataConnectMutationOptions} from '@tanstack-query-firebase/react/data-connect';
|
import { UseDataConnectQueryResult, useDataConnectQueryOptions, UseDataConnectMutationResult, useDataConnectMutationOptions} from '@tanstack-query-firebase/react/data-connect';
|
||||||
import { UseQueryResult, UseMutationResult} from '@tanstack/react-query';
|
import { UseQueryResult, UseMutationResult} from '@tanstack/react-query';
|
||||||
import { DataConnect } from 'firebase/data-connect';
|
import { DataConnect } from 'firebase/data-connect';
|
||||||
import { FirebaseError } from 'firebase/app';
|
import { FirebaseError } from 'firebase/app';
|
||||||
|
|
||||||
|
|
||||||
export function useCreateMovie(options?: useDataConnectMutationOptions<CreateMovieData, FirebaseError, CreateMovieVariables>): UseDataConnectMutationResult<CreateMovieData, CreateMovieVariables>;
|
export function useCreateEvent(options?: useDataConnectMutationOptions<CreateEventData, FirebaseError, CreateEventVariables>): UseDataConnectMutationResult<CreateEventData, CreateEventVariables>;
|
||||||
export function useCreateMovie(dc: DataConnect, options?: useDataConnectMutationOptions<CreateMovieData, FirebaseError, CreateMovieVariables>): UseDataConnectMutationResult<CreateMovieData, CreateMovieVariables>;
|
export function useCreateEvent(dc: DataConnect, options?: useDataConnectMutationOptions<CreateEventData, FirebaseError, CreateEventVariables>): UseDataConnectMutationResult<CreateEventData, CreateEventVariables>;
|
||||||
|
|
||||||
export function useUpsertUser(options?: useDataConnectMutationOptions<UpsertUserData, FirebaseError, UpsertUserVariables>): UseDataConnectMutationResult<UpsertUserData, UpsertUserVariables>;
|
export function useListEvents(options?: useDataConnectQueryOptions<ListEventsData>): UseDataConnectQueryResult<ListEventsData, undefined>;
|
||||||
export function useUpsertUser(dc: DataConnect, options?: useDataConnectMutationOptions<UpsertUserData, FirebaseError, UpsertUserVariables>): UseDataConnectMutationResult<UpsertUserData, UpsertUserVariables>;
|
export function useListEvents(dc: DataConnect, options?: useDataConnectQueryOptions<ListEventsData>): UseDataConnectQueryResult<ListEventsData, undefined>;
|
||||||
|
|
||||||
export function useAddReview(options?: useDataConnectMutationOptions<AddReviewData, FirebaseError, AddReviewVariables>): UseDataConnectMutationResult<AddReviewData, AddReviewVariables>;
|
|
||||||
export function useAddReview(dc: DataConnect, options?: useDataConnectMutationOptions<AddReviewData, FirebaseError, AddReviewVariables>): UseDataConnectMutationResult<AddReviewData, AddReviewVariables>;
|
|
||||||
|
|
||||||
export function useDeleteReview(options?: useDataConnectMutationOptions<DeleteReviewData, FirebaseError, DeleteReviewVariables>): UseDataConnectMutationResult<DeleteReviewData, DeleteReviewVariables>;
|
|
||||||
export function useDeleteReview(dc: DataConnect, options?: useDataConnectMutationOptions<DeleteReviewData, FirebaseError, DeleteReviewVariables>): UseDataConnectMutationResult<DeleteReviewData, DeleteReviewVariables>;
|
|
||||||
|
|
||||||
export function useListMovies(options?: useDataConnectQueryOptions<ListMoviesData>): UseDataConnectQueryResult<ListMoviesData, undefined>;
|
|
||||||
export function useListMovies(dc: DataConnect, options?: useDataConnectQueryOptions<ListMoviesData>): UseDataConnectQueryResult<ListMoviesData, undefined>;
|
|
||||||
|
|
||||||
export function useListUsers(options?: useDataConnectQueryOptions<ListUsersData>): UseDataConnectQueryResult<ListUsersData, undefined>;
|
|
||||||
export function useListUsers(dc: DataConnect, options?: useDataConnectQueryOptions<ListUsersData>): UseDataConnectQueryResult<ListUsersData, undefined>;
|
|
||||||
|
|
||||||
export function useListUserReviews(options?: useDataConnectQueryOptions<ListUserReviewsData>): UseDataConnectQueryResult<ListUserReviewsData, undefined>;
|
|
||||||
export function useListUserReviews(dc: DataConnect, options?: useDataConnectQueryOptions<ListUserReviewsData>): UseDataConnectQueryResult<ListUserReviewsData, undefined>;
|
|
||||||
|
|
||||||
export function useGetMovieById(vars: GetMovieByIdVariables, options?: useDataConnectQueryOptions<GetMovieByIdData>): UseDataConnectQueryResult<GetMovieByIdData, GetMovieByIdVariables>;
|
|
||||||
export function useGetMovieById(dc: DataConnect, vars: GetMovieByIdVariables, options?: useDataConnectQueryOptions<GetMovieByIdData>): UseDataConnectQueryResult<GetMovieByIdData, GetMovieByIdVariables>;
|
|
||||||
|
|
||||||
export function useSearchMovie(vars?: SearchMovieVariables, options?: useDataConnectQueryOptions<SearchMovieData>): UseDataConnectQueryResult<SearchMovieData, SearchMovieVariables>;
|
|
||||||
export function useSearchMovie(dc: DataConnect, vars?: SearchMovieVariables, options?: useDataConnectQueryOptions<SearchMovieData>): UseDataConnectQueryResult<SearchMovieData, SearchMovieVariables>;
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"name": "@dataconnect/generated-react",
|
"name": "@dataconnect/generated-react",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"author": "Firebase <firebase-support@google.com> (https://firebase.google.com/)",
|
"author": "Firebase <firebase-support@google.com> (https://firebase.google.com/)",
|
||||||
"description": "Generated SDK For example",
|
"description": "Generated SDK For krow-connector",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": " >=18.0"
|
"node": " >=18.0"
|
||||||
|
|||||||
22
frontend-web/src/lib/firebaseConfig.js
Normal file
22
frontend-web/src/lib/firebaseConfig.js
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import { getApps, initializeApp, getApp } from 'firebase/app';
|
||||||
|
import { getDataConnect } from 'firebase/data-connect';
|
||||||
|
import { getAuth } from 'firebase/auth';
|
||||||
|
import { connectorConfig } from '@dataconnect/generated';
|
||||||
|
|
||||||
|
const firebaseConfig = {
|
||||||
|
apiKey: import.meta.env.VITE_FIREBASE_API_KEY,
|
||||||
|
authDomain: import.meta.env.VITE_FIREBASE_AUTH_DOMAIN,
|
||||||
|
projectId: import.meta.env.VITE_FIREBASE_PROJECT_ID,
|
||||||
|
appId: import.meta.env.VITE_FIREBASE_APP_ID,
|
||||||
|
};
|
||||||
|
|
||||||
|
export function getFirebaseApp() {
|
||||||
|
if (getApps().length === 0) {
|
||||||
|
return initializeApp(firebaseConfig);
|
||||||
|
}
|
||||||
|
return getApp();
|
||||||
|
}
|
||||||
|
|
||||||
|
export const app = getFirebaseApp();
|
||||||
|
export const dataConnect = getDataConnect(app, connectorConfig);
|
||||||
|
export const auth = getAuth(app);
|
||||||
Reference in New Issue
Block a user