Files
Krow-workspace/frontend-web/src/dataconnect-generated

Generated TypeScript README

This README will guide you through the process of using the generated JavaScript 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.

If you're looking for the React README, you can find it at dataconnect-generated/react/README.md

NOTE: This README is generated alongside the generated SDK. If you make changes to this file, they will be overwritten when the SDK is regenerated.

Table of Contents

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. You can find more information about connectors in the Data Connect documentation.

You can use this generated SDK by importing from the package @dataconnect/generated as shown below. Both CommonJS and ESM imports are supported.

You can also follow the instructions from the Data Connect documentation.

import { getDataConnect } from 'firebase/data-connect';
import { connectorConfig } from '@dataconnect/generated';

const dataConnect = getDataConnect(connectorConfig);

Connecting to the local Emulator

By default, the connector will connect to the production service.

To connect to the emulator, you can use the following code. You can also follow the emulator instructions from the Data Connect documentation.

import { connectDataConnectEmulator, getDataConnect } from 'firebase/data-connect';
import { connectorConfig } from '@dataconnect/generated';

const dataConnect = getDataConnect(connectorConfig);
connectDataConnectEmulator(dataConnect, 'localhost', 9399);

After it's initialized, you can call your Data Connect queries and mutations from your generated SDK.

Queries

There are two ways to execute a Data Connect Query using the generated Web SDK:

  • Using a Query Reference function, which returns a QueryRef
    • The QueryRef can be used as an argument to executeQuery(), which will execute the Query and return a QueryPromise
  • Using an action shortcut function, which returns a QueryPromise
    • Calling the action shortcut function will execute the Query and return a QueryPromise

The following is true for both the action shortcut function and the QueryRef function:

  • The QueryPromise returned will resolve to the result of the Query once it has finished executing
  • If the Query accepts arguments, both the action shortcut function and the QueryRef function accept a single argument: an object that contains all the required variables (and the optional variables) for the Query
  • Both functions can be called with or without passing in a DataConnect instance as an argument. If no DataConnect argument is passed in, then the generated SDK will call getDataConnect(connectorConfig) behind the scenes for you.

Below are examples of how to use the example connector's generated functions to execute each query. You can also follow the examples from the Data Connect documentation.

ListMovies

You can execute the ListMovies query using the following action shortcut function, or by calling executeQuery() after calling the following QueryRef function, both of which are defined in dataconnect-generated/index.d.ts:

listMovies(): QueryPromise<ListMoviesData, undefined>;

interface ListMoviesRef {
  ...
  /* Allow users to create refs without passing in DataConnect */
  (): QueryRef<ListMoviesData, undefined>;
}
export const listMoviesRef: ListMoviesRef;

You can also pass in a DataConnect instance to the action shortcut function or QueryRef function.

listMovies(dc: DataConnect): QueryPromise<ListMoviesData, undefined>;

interface ListMoviesRef {
  ...
  (dc: DataConnect): QueryRef<ListMoviesData, undefined>;
}
export const listMoviesRef: ListMoviesRef;

If you need the name of the operation without creating a ref, you can retrieve the operation name by calling the operationName property on the listMoviesRef:

const name = listMoviesRef.operationName;
console.log(name);

Variables

The ListMovies query has no variables.

Return Type

Recall that executing the ListMovies query returns a QueryPromise that resolves to an object with a data property.

The data property is an object of type ListMoviesData, which is defined in dataconnect-generated/index.d.ts. It has the following fields:

export interface ListMoviesData {
  movies: ({
    id: UUIDString;
    title: string;
    imageUrl: string;
    genre?: string | null;
  } & Movie_Key)[];
}

Using ListMovies's action shortcut function

import { getDataConnect } from 'firebase/data-connect';
import { connectorConfig, listMovies } from '@dataconnect/generated';


// Call the `listMovies()` function to execute the query.
// You can use the `await` keyword to wait for the promise to resolve.
const { data } = await listMovies();

// You can also pass in a `DataConnect` instance to the action shortcut function.
const dataConnect = getDataConnect(connectorConfig);
const { data } = await listMovies(dataConnect);

console.log(data.movies);

// Or, you can use the `Promise` API.
listMovies().then((response) => {
  const data = response.data;
  console.log(data.movies);
});

Using ListMovies's QueryRef function

import { getDataConnect, executeQuery } from 'firebase/data-connect';
import { connectorConfig, listMoviesRef } from '@dataconnect/generated';


// Call the `listMoviesRef()` function to get a reference to the query.
const ref = listMoviesRef();

// You can also pass in a `DataConnect` instance to the `QueryRef` function.
const dataConnect = getDataConnect(connectorConfig);
const ref = listMoviesRef(dataConnect);

// Call `executeQuery()` on the reference to execute the query.
// You can use the `await` keyword to wait for the promise to resolve.
const { data } = await executeQuery(ref);

console.log(data.movies);

// Or, you can use the `Promise` API.
executeQuery(ref).then((response) => {
  const data = response.data;
  console.log(data.movies);
});

ListUsers

You can execute the ListUsers query using the following action shortcut function, or by calling executeQuery() after calling the following QueryRef function, both of which are defined in dataconnect-generated/index.d.ts:

listUsers(): QueryPromise<ListUsersData, undefined>;

interface ListUsersRef {
  ...
  /* Allow users to create refs without passing in DataConnect */
  (): QueryRef<ListUsersData, undefined>;
}
export const listUsersRef: ListUsersRef;

You can also pass in a DataConnect instance to the action shortcut function or QueryRef function.

listUsers(dc: DataConnect): QueryPromise<ListUsersData, undefined>;

interface ListUsersRef {
  ...
  (dc: DataConnect): QueryRef<ListUsersData, undefined>;
}
export const listUsersRef: ListUsersRef;

If you need the name of the operation without creating a ref, you can retrieve the operation name by calling the operationName property on the listUsersRef:

const name = listUsersRef.operationName;
console.log(name);

Variables

The ListUsers query has no variables.

Return Type

Recall that executing the ListUsers query returns a QueryPromise that resolves to an object with a data property.

The data property is an object of type ListUsersData, which is defined in dataconnect-generated/index.d.ts. It has the following fields:

export interface ListUsersData {
  users: ({
    id: string;
    username: string;
  } & User_Key)[];
}

Using ListUsers's action shortcut function

import { getDataConnect } from 'firebase/data-connect';
import { connectorConfig, listUsers } from '@dataconnect/generated';


// Call the `listUsers()` function to execute the query.
// You can use the `await` keyword to wait for the promise to resolve.
const { data } = await listUsers();

// You can also pass in a `DataConnect` instance to the action shortcut function.
const dataConnect = getDataConnect(connectorConfig);
const { data } = await listUsers(dataConnect);

console.log(data.users);

// Or, you can use the `Promise` API.
listUsers().then((response) => {
  const data = response.data;
  console.log(data.users);
});

Using ListUsers's QueryRef function

import { getDataConnect, executeQuery } from 'firebase/data-connect';
import { connectorConfig, listUsersRef } from '@dataconnect/generated';


// Call the `listUsersRef()` function to get a reference to the query.
const ref = listUsersRef();

// You can also pass in a `DataConnect` instance to the `QueryRef` function.
const dataConnect = getDataConnect(connectorConfig);
const ref = listUsersRef(dataConnect);

// Call `executeQuery()` on the reference to execute the query.
// You can use the `await` keyword to wait for the promise to resolve.
const { data } = await executeQuery(ref);

console.log(data.users);

// Or, you can use the `Promise` API.
executeQuery(ref).then((response) => {
  const data = response.data;
  console.log(data.users);
});

ListUserReviews

You can execute the ListUserReviews query using the following action shortcut function, or by calling executeQuery() after calling the following QueryRef function, both of which are defined in dataconnect-generated/index.d.ts:

listUserReviews(): QueryPromise<ListUserReviewsData, undefined>;

interface ListUserReviewsRef {
  ...
  /* Allow users to create refs without passing in DataConnect */
  (): QueryRef<ListUserReviewsData, undefined>;
}
export const listUserReviewsRef: ListUserReviewsRef;

You can also pass in a DataConnect instance to the action shortcut function or QueryRef function.

listUserReviews(dc: DataConnect): QueryPromise<ListUserReviewsData, undefined>;

interface ListUserReviewsRef {
  ...
  (dc: DataConnect): QueryRef<ListUserReviewsData, undefined>;
}
export const listUserReviewsRef: ListUserReviewsRef;

If you need the name of the operation without creating a ref, you can retrieve the operation name by calling the operationName property on the listUserReviewsRef:

const name = listUserReviewsRef.operationName;
console.log(name);

Variables

The ListUserReviews query has no variables.

Return Type

Recall that executing the ListUserReviews query returns a QueryPromise that resolves to an object with a data property.

The data property is an object of type ListUserReviewsData, which is defined in dataconnect-generated/index.d.ts. It has the following fields:

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;
}

Using ListUserReviews's action shortcut function

import { getDataConnect } from 'firebase/data-connect';
import { connectorConfig, listUserReviews } from '@dataconnect/generated';


// Call the `listUserReviews()` function to execute the query.
// You can use the `await` keyword to wait for the promise to resolve.
const { data } = await listUserReviews();

// You can also pass in a `DataConnect` instance to the action shortcut function.
const dataConnect = getDataConnect(connectorConfig);
const { data } = await listUserReviews(dataConnect);

console.log(data.user);

// Or, you can use the `Promise` API.
listUserReviews().then((response) => {
  const data = response.data;
  console.log(data.user);
});

Using ListUserReviews's QueryRef function

import { getDataConnect, executeQuery } from 'firebase/data-connect';
import { connectorConfig, listUserReviewsRef } from '@dataconnect/generated';


// Call the `listUserReviewsRef()` function to get a reference to the query.
const ref = listUserReviewsRef();

// You can also pass in a `DataConnect` instance to the `QueryRef` function.
const dataConnect = getDataConnect(connectorConfig);
const ref = listUserReviewsRef(dataConnect);

// Call `executeQuery()` on the reference to execute the query.
// You can use the `await` keyword to wait for the promise to resolve.
const { data } = await executeQuery(ref);

console.log(data.user);

// Or, you can use the `Promise` API.
executeQuery(ref).then((response) => {
  const data = response.data;
  console.log(data.user);
});

GetMovieById

You can execute the GetMovieById query using the following action shortcut function, or by calling executeQuery() after calling the following QueryRef function, both of which are defined in dataconnect-generated/index.d.ts:

getMovieById(vars: GetMovieByIdVariables): QueryPromise<GetMovieByIdData, GetMovieByIdVariables>;

interface GetMovieByIdRef {
  ...
  /* Allow users to create refs without passing in DataConnect */
  (vars: GetMovieByIdVariables): QueryRef<GetMovieByIdData, GetMovieByIdVariables>;
}
export const getMovieByIdRef: GetMovieByIdRef;

You can also pass in a DataConnect instance to the action shortcut function or QueryRef function.

getMovieById(dc: DataConnect, vars: GetMovieByIdVariables): QueryPromise<GetMovieByIdData, GetMovieByIdVariables>;

interface GetMovieByIdRef {
  ...
  (dc: DataConnect, vars: GetMovieByIdVariables): QueryRef<GetMovieByIdData, GetMovieByIdVariables>;
}
export const getMovieByIdRef: GetMovieByIdRef;

If you need the name of the operation without creating a ref, you can retrieve the operation name by calling the operationName property on the getMovieByIdRef:

const name = getMovieByIdRef.operationName;
console.log(name);

Variables

The GetMovieById query requires an argument of type GetMovieByIdVariables, which is defined in dataconnect-generated/index.d.ts. It has the following fields:

export interface GetMovieByIdVariables {
  id: UUIDString;
}

Return Type

Recall that executing the GetMovieById query returns a QueryPromise that resolves to an object with a data property.

The data property is an object of type GetMovieByIdData, which is defined in dataconnect-generated/index.d.ts. It has the following fields:

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;
}

Using GetMovieById's action shortcut function

import { getDataConnect } from 'firebase/data-connect';
import { connectorConfig, getMovieById, GetMovieByIdVariables } from '@dataconnect/generated';

// The `GetMovieById` query requires an argument of type `GetMovieByIdVariables`:
const getMovieByIdVars: GetMovieByIdVariables = {
  id: ..., 
};

// Call the `getMovieById()` function to execute the query.
// You can use the `await` keyword to wait for the promise to resolve.
const { data } = await getMovieById(getMovieByIdVars);
// Variables can be defined inline as well.
const { data } = await getMovieById({ id: ..., });

// You can also pass in a `DataConnect` instance to the action shortcut function.
const dataConnect = getDataConnect(connectorConfig);
const { data } = await getMovieById(dataConnect, getMovieByIdVars);

console.log(data.movie);

// Or, you can use the `Promise` API.
getMovieById(getMovieByIdVars).then((response) => {
  const data = response.data;
  console.log(data.movie);
});

Using GetMovieById's QueryRef function

import { getDataConnect, executeQuery } from 'firebase/data-connect';
import { connectorConfig, getMovieByIdRef, GetMovieByIdVariables } from '@dataconnect/generated';

// The `GetMovieById` query requires an argument of type `GetMovieByIdVariables`:
const getMovieByIdVars: GetMovieByIdVariables = {
  id: ..., 
};

// Call the `getMovieByIdRef()` function to get a reference to the query.
const ref = getMovieByIdRef(getMovieByIdVars);
// Variables can be defined inline as well.
const ref = getMovieByIdRef({ id: ..., });

// You can also pass in a `DataConnect` instance to the `QueryRef` function.
const dataConnect = getDataConnect(connectorConfig);
const ref = getMovieByIdRef(dataConnect, getMovieByIdVars);

// Call `executeQuery()` on the reference to execute the query.
// You can use the `await` keyword to wait for the promise to resolve.
const { data } = await executeQuery(ref);

console.log(data.movie);

// Or, you can use the `Promise` API.
executeQuery(ref).then((response) => {
  const data = response.data;
  console.log(data.movie);
});

SearchMovie

You can execute the SearchMovie query using the following action shortcut function, or by calling executeQuery() after calling the following QueryRef function, both of which are defined in dataconnect-generated/index.d.ts:

searchMovie(vars?: SearchMovieVariables): QueryPromise<SearchMovieData, SearchMovieVariables>;

interface SearchMovieRef {
  ...
  /* Allow users to create refs without passing in DataConnect */
  (vars?: SearchMovieVariables): QueryRef<SearchMovieData, SearchMovieVariables>;
}
export const searchMovieRef: SearchMovieRef;

You can also pass in a DataConnect instance to the action shortcut function or QueryRef function.

searchMovie(dc: DataConnect, vars?: SearchMovieVariables): QueryPromise<SearchMovieData, SearchMovieVariables>;

interface SearchMovieRef {
  ...
  (dc: DataConnect, vars?: SearchMovieVariables): QueryRef<SearchMovieData, SearchMovieVariables>;
}
export const searchMovieRef: SearchMovieRef;

If you need the name of the operation without creating a ref, you can retrieve the operation name by calling the operationName property on the searchMovieRef:

const name = searchMovieRef.operationName;
console.log(name);

Variables

The SearchMovie query has an optional argument of type SearchMovieVariables, which is defined in dataconnect-generated/index.d.ts. It has the following fields:

export interface SearchMovieVariables {
  titleInput?: string | null;
  genre?: string | null;
}

Return Type

Recall that executing the SearchMovie query returns a QueryPromise that resolves to an object with a data property.

The data property is an object of type SearchMovieData, which is defined in dataconnect-generated/index.d.ts. It has the following fields:

export interface SearchMovieData {
  movies: ({
    id: UUIDString;
    title: string;
    genre?: string | null;
    imageUrl: string;
  } & Movie_Key)[];
}

Using SearchMovie's action shortcut function

import { getDataConnect } from 'firebase/data-connect';
import { connectorConfig, searchMovie, SearchMovieVariables } from '@dataconnect/generated';

// The `SearchMovie` query has an optional argument of type `SearchMovieVariables`:
const searchMovieVars: SearchMovieVariables = {
  titleInput: ..., // optional
  genre: ..., // optional
};

// Call the `searchMovie()` function to execute the query.
// You can use the `await` keyword to wait for the promise to resolve.
const { data } = await searchMovie(searchMovieVars);
// Variables can be defined inline as well.
const { data } = await searchMovie({ titleInput: ..., genre: ..., });
// Since all variables are optional for this query, you can omit the `SearchMovieVariables` argument.
const { data } = await searchMovie();

// You can also pass in a `DataConnect` instance to the action shortcut function.
const dataConnect = getDataConnect(connectorConfig);
const { data } = await searchMovie(dataConnect, searchMovieVars);

console.log(data.movies);

// Or, you can use the `Promise` API.
searchMovie(searchMovieVars).then((response) => {
  const data = response.data;
  console.log(data.movies);
});

Using SearchMovie's QueryRef function

import { getDataConnect, executeQuery } from 'firebase/data-connect';
import { connectorConfig, searchMovieRef, SearchMovieVariables } from '@dataconnect/generated';

// The `SearchMovie` query has an optional argument of type `SearchMovieVariables`:
const searchMovieVars: SearchMovieVariables = {
  titleInput: ..., // optional
  genre: ..., // optional
};

// Call the `searchMovieRef()` function to get a reference to the query.
const ref = searchMovieRef(searchMovieVars);
// Variables can be defined inline as well.
const ref = searchMovieRef({ titleInput: ..., genre: ..., });
// Since all variables are optional for this query, you can omit the `SearchMovieVariables` argument.
const ref = searchMovieRef();

// You can also pass in a `DataConnect` instance to the `QueryRef` function.
const dataConnect = getDataConnect(connectorConfig);
const ref = searchMovieRef(dataConnect, searchMovieVars);

// Call `executeQuery()` on the reference to execute the query.
// You can use the `await` keyword to wait for the promise to resolve.
const { data } = await executeQuery(ref);

console.log(data.movies);

// Or, you can use the `Promise` API.
executeQuery(ref).then((response) => {
  const data = response.data;
  console.log(data.movies);
});

Mutations

There are two ways to execute a Data Connect Mutation using the generated Web SDK:

  • Using a Mutation Reference function, which returns a MutationRef
    • The MutationRef can be used as an argument to executeMutation(), which will execute the Mutation and return a MutationPromise
  • Using an action shortcut function, which returns a MutationPromise
    • Calling the action shortcut function will execute the Mutation and return a MutationPromise

The following is true for both the action shortcut function and the MutationRef function:

  • The MutationPromise returned will resolve to the result of the Mutation once it has finished executing
  • If the Mutation accepts arguments, both the action shortcut function and the MutationRef function accept a single argument: an object that contains all the required variables (and the optional variables) for the Mutation
  • Both functions can be called with or without passing in a DataConnect instance as an argument. If no DataConnect argument is passed in, then the generated SDK will call getDataConnect(connectorConfig) behind the scenes for you.

Below are examples of how to use the example connector's generated functions to execute each mutation. You can also follow the examples from the Data Connect documentation.

CreateMovie

You can execute the CreateMovie mutation using the following action shortcut function, or by calling executeMutation() after calling the following MutationRef function, both of which are defined in dataconnect-generated/index.d.ts:

createMovie(vars: CreateMovieVariables): MutationPromise<CreateMovieData, CreateMovieVariables>;

interface CreateMovieRef {
  ...
  /* Allow users to create refs without passing in DataConnect */
  (vars: CreateMovieVariables): MutationRef<CreateMovieData, CreateMovieVariables>;
}
export const createMovieRef: CreateMovieRef;

You can also pass in a DataConnect instance to the action shortcut function or MutationRef function.

createMovie(dc: DataConnect, vars: CreateMovieVariables): MutationPromise<CreateMovieData, CreateMovieVariables>;

interface CreateMovieRef {
  ...
  (dc: DataConnect, vars: CreateMovieVariables): MutationRef<CreateMovieData, CreateMovieVariables>;
}
export const createMovieRef: CreateMovieRef;

If you need the name of the operation without creating a ref, you can retrieve the operation name by calling the operationName property on the createMovieRef:

const name = createMovieRef.operationName;
console.log(name);

Variables

The CreateMovie mutation requires an argument of type CreateMovieVariables, which is defined in dataconnect-generated/index.d.ts. It has the following fields:

export interface CreateMovieVariables {
  title: string;
  genre: string;
  imageUrl: string;
}

Return Type

Recall that executing the CreateMovie mutation returns a MutationPromise that resolves to an object with a data property.

The data property is an object of type CreateMovieData, which is defined in dataconnect-generated/index.d.ts. It has the following fields:

export interface CreateMovieData {
  movie_insert: Movie_Key;
}

Using CreateMovie's action shortcut function

import { getDataConnect } from 'firebase/data-connect';
import { connectorConfig, createMovie, CreateMovieVariables } from '@dataconnect/generated';

// The `CreateMovie` mutation requires an argument of type `CreateMovieVariables`:
const createMovieVars: CreateMovieVariables = {
  title: ..., 
  genre: ..., 
  imageUrl: ..., 
};

// Call the `createMovie()` function to execute the mutation.
// You can use the `await` keyword to wait for the promise to resolve.
const { data } = await createMovie(createMovieVars);
// Variables can be defined inline as well.
const { data } = await createMovie({ title: ..., genre: ..., imageUrl: ..., });

// You can also pass in a `DataConnect` instance to the action shortcut function.
const dataConnect = getDataConnect(connectorConfig);
const { data } = await createMovie(dataConnect, createMovieVars);

console.log(data.movie_insert);

// Or, you can use the `Promise` API.
createMovie(createMovieVars).then((response) => {
  const data = response.data;
  console.log(data.movie_insert);
});

Using CreateMovie's MutationRef function

import { getDataConnect, executeMutation } from 'firebase/data-connect';
import { connectorConfig, createMovieRef, CreateMovieVariables } from '@dataconnect/generated';

// The `CreateMovie` mutation requires an argument of type `CreateMovieVariables`:
const createMovieVars: CreateMovieVariables = {
  title: ..., 
  genre: ..., 
  imageUrl: ..., 
};

// Call the `createMovieRef()` function to get a reference to the mutation.
const ref = createMovieRef(createMovieVars);
// Variables can be defined inline as well.
const ref = createMovieRef({ title: ..., genre: ..., imageUrl: ..., });

// You can also pass in a `DataConnect` instance to the `MutationRef` function.
const dataConnect = getDataConnect(connectorConfig);
const ref = createMovieRef(dataConnect, createMovieVars);

// Call `executeMutation()` on the reference to execute the mutation.
// You can use the `await` keyword to wait for the promise to resolve.
const { data } = await executeMutation(ref);

console.log(data.movie_insert);

// Or, you can use the `Promise` API.
executeMutation(ref).then((response) => {
  const data = response.data;
  console.log(data.movie_insert);
});

UpsertUser

You can execute the UpsertUser mutation using the following action shortcut function, or by calling executeMutation() after calling the following MutationRef function, both of which are defined in dataconnect-generated/index.d.ts:

upsertUser(vars: UpsertUserVariables): MutationPromise<UpsertUserData, UpsertUserVariables>;

interface UpsertUserRef {
  ...
  /* Allow users to create refs without passing in DataConnect */
  (vars: UpsertUserVariables): MutationRef<UpsertUserData, UpsertUserVariables>;
}
export const upsertUserRef: UpsertUserRef;

You can also pass in a DataConnect instance to the action shortcut function or MutationRef function.

upsertUser(dc: DataConnect, vars: UpsertUserVariables): MutationPromise<UpsertUserData, UpsertUserVariables>;

interface UpsertUserRef {
  ...
  (dc: DataConnect, vars: UpsertUserVariables): MutationRef<UpsertUserData, UpsertUserVariables>;
}
export const upsertUserRef: UpsertUserRef;

If you need the name of the operation without creating a ref, you can retrieve the operation name by calling the operationName property on the upsertUserRef:

const name = upsertUserRef.operationName;
console.log(name);

Variables

The UpsertUser mutation requires an argument of type UpsertUserVariables, which is defined in dataconnect-generated/index.d.ts. It has the following fields:

export interface UpsertUserVariables {
  username: string;
}

Return Type

Recall that executing the UpsertUser mutation returns a MutationPromise that resolves to an object with a data property.

The data property is an object of type UpsertUserData, which is defined in dataconnect-generated/index.d.ts. It has the following fields:

export interface UpsertUserData {
  user_upsert: User_Key;
}

Using UpsertUser's action shortcut function

import { getDataConnect } from 'firebase/data-connect';
import { connectorConfig, upsertUser, UpsertUserVariables } from '@dataconnect/generated';

// The `UpsertUser` mutation requires an argument of type `UpsertUserVariables`:
const upsertUserVars: UpsertUserVariables = {
  username: ..., 
};

// Call the `upsertUser()` function to execute the mutation.
// You can use the `await` keyword to wait for the promise to resolve.
const { data } = await upsertUser(upsertUserVars);
// Variables can be defined inline as well.
const { data } = await upsertUser({ username: ..., });

// You can also pass in a `DataConnect` instance to the action shortcut function.
const dataConnect = getDataConnect(connectorConfig);
const { data } = await upsertUser(dataConnect, upsertUserVars);

console.log(data.user_upsert);

// Or, you can use the `Promise` API.
upsertUser(upsertUserVars).then((response) => {
  const data = response.data;
  console.log(data.user_upsert);
});

Using UpsertUser's MutationRef function

import { getDataConnect, executeMutation } from 'firebase/data-connect';
import { connectorConfig, upsertUserRef, UpsertUserVariables } from '@dataconnect/generated';

// The `UpsertUser` mutation requires an argument of type `UpsertUserVariables`:
const upsertUserVars: UpsertUserVariables = {
  username: ..., 
};

// Call the `upsertUserRef()` function to get a reference to the mutation.
const ref = upsertUserRef(upsertUserVars);
// Variables can be defined inline as well.
const ref = upsertUserRef({ username: ..., });

// You can also pass in a `DataConnect` instance to the `MutationRef` function.
const dataConnect = getDataConnect(connectorConfig);
const ref = upsertUserRef(dataConnect, upsertUserVars);

// Call `executeMutation()` on the reference to execute the mutation.
// You can use the `await` keyword to wait for the promise to resolve.
const { data } = await executeMutation(ref);

console.log(data.user_upsert);

// Or, you can use the `Promise` API.
executeMutation(ref).then((response) => {
  const data = response.data;
  console.log(data.user_upsert);
});

AddReview

You can execute the AddReview mutation using the following action shortcut function, or by calling executeMutation() after calling the following MutationRef function, both of which are defined in dataconnect-generated/index.d.ts:

addReview(vars: AddReviewVariables): MutationPromise<AddReviewData, AddReviewVariables>;

interface AddReviewRef {
  ...
  /* Allow users to create refs without passing in DataConnect */
  (vars: AddReviewVariables): MutationRef<AddReviewData, AddReviewVariables>;
}
export const addReviewRef: AddReviewRef;

You can also pass in a DataConnect instance to the action shortcut function or MutationRef function.

addReview(dc: DataConnect, vars: AddReviewVariables): MutationPromise<AddReviewData, AddReviewVariables>;

interface AddReviewRef {
  ...
  (dc: DataConnect, vars: AddReviewVariables): MutationRef<AddReviewData, AddReviewVariables>;
}
export const addReviewRef: AddReviewRef;

If you need the name of the operation without creating a ref, you can retrieve the operation name by calling the operationName property on the addReviewRef:

const name = addReviewRef.operationName;
console.log(name);

Variables

The AddReview mutation requires an argument of type AddReviewVariables, which is defined in dataconnect-generated/index.d.ts. It has the following fields:

export interface AddReviewVariables {
  movieId: UUIDString;
  rating: number;
  reviewText: string;
}

Return Type

Recall that executing the AddReview mutation returns a MutationPromise that resolves to an object with a data property.

The data property is an object of type AddReviewData, which is defined in dataconnect-generated/index.d.ts. It has the following fields:

export interface AddReviewData {
  review_upsert: Review_Key;
}

Using AddReview's action shortcut function

import { getDataConnect } from 'firebase/data-connect';
import { connectorConfig, addReview, AddReviewVariables } from '@dataconnect/generated';

// The `AddReview` mutation requires an argument of type `AddReviewVariables`:
const addReviewVars: AddReviewVariables = {
  movieId: ..., 
  rating: ..., 
  reviewText: ..., 
};

// Call the `addReview()` function to execute the mutation.
// You can use the `await` keyword to wait for the promise to resolve.
const { data } = await addReview(addReviewVars);
// Variables can be defined inline as well.
const { data } = await addReview({ movieId: ..., rating: ..., reviewText: ..., });

// You can also pass in a `DataConnect` instance to the action shortcut function.
const dataConnect = getDataConnect(connectorConfig);
const { data } = await addReview(dataConnect, addReviewVars);

console.log(data.review_upsert);

// Or, you can use the `Promise` API.
addReview(addReviewVars).then((response) => {
  const data = response.data;
  console.log(data.review_upsert);
});

Using AddReview's MutationRef function

import { getDataConnect, executeMutation } from 'firebase/data-connect';
import { connectorConfig, addReviewRef, AddReviewVariables } from '@dataconnect/generated';

// The `AddReview` mutation requires an argument of type `AddReviewVariables`:
const addReviewVars: AddReviewVariables = {
  movieId: ..., 
  rating: ..., 
  reviewText: ..., 
};

// Call the `addReviewRef()` function to get a reference to the mutation.
const ref = addReviewRef(addReviewVars);
// Variables can be defined inline as well.
const ref = addReviewRef({ movieId: ..., rating: ..., reviewText: ..., });

// You can also pass in a `DataConnect` instance to the `MutationRef` function.
const dataConnect = getDataConnect(connectorConfig);
const ref = addReviewRef(dataConnect, addReviewVars);

// Call `executeMutation()` on the reference to execute the mutation.
// You can use the `await` keyword to wait for the promise to resolve.
const { data } = await executeMutation(ref);

console.log(data.review_upsert);

// Or, you can use the `Promise` API.
executeMutation(ref).then((response) => {
  const data = response.data;
  console.log(data.review_upsert);
});

DeleteReview

You can execute the DeleteReview mutation using the following action shortcut function, or by calling executeMutation() after calling the following MutationRef function, both of which are defined in dataconnect-generated/index.d.ts:

deleteReview(vars: DeleteReviewVariables): MutationPromise<DeleteReviewData, DeleteReviewVariables>;

interface DeleteReviewRef {
  ...
  /* Allow users to create refs without passing in DataConnect */
  (vars: DeleteReviewVariables): MutationRef<DeleteReviewData, DeleteReviewVariables>;
}
export const deleteReviewRef: DeleteReviewRef;

You can also pass in a DataConnect instance to the action shortcut function or MutationRef function.

deleteReview(dc: DataConnect, vars: DeleteReviewVariables): MutationPromise<DeleteReviewData, DeleteReviewVariables>;

interface DeleteReviewRef {
  ...
  (dc: DataConnect, vars: DeleteReviewVariables): MutationRef<DeleteReviewData, DeleteReviewVariables>;
}
export const deleteReviewRef: DeleteReviewRef;

If you need the name of the operation without creating a ref, you can retrieve the operation name by calling the operationName property on the deleteReviewRef:

const name = deleteReviewRef.operationName;
console.log(name);

Variables

The DeleteReview mutation requires an argument of type DeleteReviewVariables, which is defined in dataconnect-generated/index.d.ts. It has the following fields:

export interface DeleteReviewVariables {
  movieId: UUIDString;
}

Return Type

Recall that executing the DeleteReview mutation returns a MutationPromise that resolves to an object with a data property.

The data property is an object of type DeleteReviewData, which is defined in dataconnect-generated/index.d.ts. It has the following fields:

export interface DeleteReviewData {
  review_delete?: Review_Key | null;
}

Using DeleteReview's action shortcut function

import { getDataConnect } from 'firebase/data-connect';
import { connectorConfig, deleteReview, DeleteReviewVariables } from '@dataconnect/generated';

// The `DeleteReview` mutation requires an argument of type `DeleteReviewVariables`:
const deleteReviewVars: DeleteReviewVariables = {
  movieId: ..., 
};

// Call the `deleteReview()` function to execute the mutation.
// You can use the `await` keyword to wait for the promise to resolve.
const { data } = await deleteReview(deleteReviewVars);
// Variables can be defined inline as well.
const { data } = await deleteReview({ movieId: ..., });

// You can also pass in a `DataConnect` instance to the action shortcut function.
const dataConnect = getDataConnect(connectorConfig);
const { data } = await deleteReview(dataConnect, deleteReviewVars);

console.log(data.review_delete);

// Or, you can use the `Promise` API.
deleteReview(deleteReviewVars).then((response) => {
  const data = response.data;
  console.log(data.review_delete);
});

Using DeleteReview's MutationRef function

import { getDataConnect, executeMutation } from 'firebase/data-connect';
import { connectorConfig, deleteReviewRef, DeleteReviewVariables } from '@dataconnect/generated';

// The `DeleteReview` mutation requires an argument of type `DeleteReviewVariables`:
const deleteReviewVars: DeleteReviewVariables = {
  movieId: ..., 
};

// Call the `deleteReviewRef()` function to get a reference to the mutation.
const ref = deleteReviewRef(deleteReviewVars);
// Variables can be defined inline as well.
const ref = deleteReviewRef({ movieId: ..., });

// You can also pass in a `DataConnect` instance to the `MutationRef` function.
const dataConnect = getDataConnect(connectorConfig);
const ref = deleteReviewRef(dataConnect, deleteReviewVars);

// Call `executeMutation()` on the reference to execute the mutation.
// You can use the `await` keyword to wait for the promise to resolve.
const { data } = await executeMutation(ref);

console.log(data.review_delete);

// Or, you can use the `Promise` API.
executeMutation(ref).then((response) => {
  const data = response.data;
  console.log(data.review_delete);
});