In this quickstart, you will learn how to build Firebase Data Connect in your application locally without setting up a production SQL instance. You will:
- Add Firebase Data Connect to your Firebase project.
- Set up a development environment including Visual Studio Code extensions to work with a local instance.
- Then we will show you how to:
- Use VS Code extension tooling, with Gemini Code Assist, to:
- Create a schema for an app
- Create administrative queries and mutations to populate your local database
- Help you implement queries and mutations for your app in a deployable connector
- Test your queries and mutations with sample data against a local emulator
- Generate strongly typed SDKs and use them in your app
- Deploy your final schema and connector to the cloud (optional, with a Blaze plan upgrade).
- Use VS Code extension tooling, with Gemini Code Assist, to:
Choose a local development flow
Data Connect offers you two ways to install development tools and work locally.
Prerequisites
To use this quickstart, you'll need the following.
- Visual Studio Code.
- A Node.js installation, using nvm-windows for Windows or nvm for macOS or Linux.
- A Firebase project. If you haven't already created one, do so in the Firebase console.
Local flow: Set up the development environment
- Create a new directory for your local project.
- Open VS Code in the new directory.
- Install the Firebase Data Connect extension from the Visual Studio Code Marketplace.
Set up your project directory
To set up your local project, initialize your project directory. In the IDE window, in the left-hand panel, click the Firebase icon to open the Data Connect VS Code extension UI:
- Click the Sign in with Google button.
- Click the Connect a Firebase project button and select the project you created earlier in the console.
- Click the Run firebase init button.
Click the Start emulators button.
Create a schema
In your Firebase project directory, in the /dataconnect/schema/schema.gql
file, start defining a GraphQL schema about, for example, movie reviews.
Use Gemini Code Assist to build a schema
To create a movie review app schema using Gemini Code Assist:
- Click the Data Connect VS Code extension icon to open its sidebar.
- Click Try Gemini with @data-connect. The Gemini Code Assist chat window opens.
- Click the chat interface, and begin typing
@data-connect
to filter relevant commands. Select the
/generate_schema
command and at the prompt, complete the command, asking Gemini to build a schema for the app you're developing.For example:
@data-connect /generate_schema I want to build an app to track movie reviews from multiple users
After a few moments, a recommended schema appears. Review the schema.
To add the code to
schema.gql
:- Click the Insert to bottom of file button
- Or, to insert the code at your cursor position, click the + button at the top of the chat response.
Movie
In Data Connect, GraphQL fields are mapped to columns. Movie has id
,
title
, imageUrl
and genre
. Data Connect recognizes primitive
data types: String
and UUID
.
Copy the following snippet or uncomment the corresponding lines in the file.
# By default, a UUID id key will be created by default as primary key.
# If you want to specify a primary key, say title, which you can do through
# the @table(key: "title") directive
type Movie @table {
id: UUID! @default(expr: "uuidV4()")
title: String!
imageUrl: String!
genre: String
}
MovieMetadata
Copy the following snippet or uncomment the corresponding lines in the file.
# Movie - MovieMetadata is a one-to-one relationship
type MovieMetadata @table {
# This time, we omit adding a primary key because
# you can rely on Data Connect to manage it.
# @unique indicates a 1-1 relationship
movie: Movie! @unique
# movieId: UUID <- this is created by the above reference
rating: Float
releaseYear: Int
description: String
}
Notice that the movie
field is mapped to a type of Movie
.
Data Connect understands that this is a relationship between Movie
and MovieMetadata
and will manage this relationship for you.
Learn more about Data Connect schemas in the documentation
Add data to your tables
In the IDE editor panel, you will see CodeLens buttons appear over the
GraphQL types in /dataconnect/schema/schema.gql
. You can use the Add data
and Run (Local) buttons add data to your local database.
To add records to the Movie
, and MovieMetadata
tables:
- In
schema.gql
, click the Add data button above theMovie
type declaration.
- In the
Movie_insert.gql
file that is generated, hard code data for the three fields. - Click the Run (Local) button.
- Repeat the previous steps to add a record to the
MovieMetadata
table, supplying theid
of your Movie in themovieId
field, as prompted in the generatedMovieMetadata_insert
mutation.
To quickly verify data was added:
- Back in
schema.gql
, click the Read data button above theMovie
type declaration. - In the resulting
Movie_read.gql
file, click the Run (Local) button to execute the query.
Learn more about Data Connect mutations in the documentation
Define a query
Now for more fun: define the queries you will need in your application. As a developer, you're accustomed to writing SQL queries rather than GraphQL queries, so this can feel a bit different at first.
However, GraphQL is far more terse and type-safe than raw SQL. And, our VS Code extension eases the development experience, both for queries and mutations.
To create a query using Gemini Code Assist:
- Click the Data Connect VS Code extension icon to open its sidebar.
- Click Try Gemini with @data-connect. The Gemini Code Assist chat window opens.
- Click the chat interface, and begin typing
@data-connect
to filter relevant commands. Select the
/generate_operation
command and at the prompt, complete the command, asking Gemini to build a query.For example:
@data-connect /generate_operation List all movies with titles start with "A".
After a few moments, a recommended query appears. Review the query.
To add the code to
queries.gql
:- Click the Insert to bottom of file button
- Or, to insert the code at your cursor position, click the + button at the top of the chat response.
Execute the query using the nearby CodeLens button.
Learn more about Data Connect queries in the documentation
Generate SDKs and use them in your app
In the IDE left-hand panel, click the Firebase icon to open the Data Connect VS Code extension UI:
- Click the Add SDK to app button.
In the dialog that appears, select a directory containing code for your app. Data Connect SDK code will be generated and saved there.
Select your app platform, then note that SDK code is immediately generated in your selected directory.
Use the SDKs to call your query from an app
You can use the SDK that Data Connect generated to implement a call
to your ListMovies
query. You can then execute this query locally using the
Data Connect emulator.
Web
- Add Firebase to your web app.
In your React app's main file:
- import your generated SDK
- instrument your app to connect to the Data Connect emulator
- call Data Connect methods.
import React from 'react'; import ReactDOM from 'react-dom/client'; import { connectDataConnectEmulator } from 'firebase/data-connect'; // Generated queries. // Update as needed with the path to your generated SDK. import { listMovies, ListMoviesData } from '@movie-app/movies'; const dataConnect = getDataConnect(connectorConfig); connectDataConnectEmulator(dataConnect, 'localhost', 9399); function App() { const [movies, setMovies] = useState<ListMoviesData['movies']>([]); useEffect(() => { listMovies.then(res => setMovies(res.data)); }, []); return ( movies.map(movie => <h1>{movie.title}</h1>); ); } const root = ReactDOM.createRoot(document.getElementById('root')); root.render(<App />);
Swift
- Add Firebase to your iOS app.
To use the generated SDK, configure it as a dependency in Xcode.
In the Xcode top navigation bar, select File > Add Package Dependencies > Add Local, and choose the folder containing the generated
Package.swift
.In your app's main delegate:
- import your generated SDK
- instrument your app to connect to the Data Connect emulator
- call Data Connect methods.
import SwiftUI import FirebaseDataConnect // Generated queries. // Update as needed with the package name of your generated SDK. import <CONNECTOR-PACKAGE-NAME> let connector = DataConnect.moviesConnector // Connect to the emulator on "127.0.0.1:9399" connector.useEmulator() // (alternatively) if you're running your emulator on non-default port: // connector.useEmulator(port: 9999) struct ListMovieView: View { @StateObject private var queryRef = connector.listMovies.ref() var body: some View { VStack { Button { Task { do { try await refresh() } catch { print("Failed to refresh: \(error)") } } } label: { Text("Refresh") } // use the query results in a view ForEach(queryRef.data?.movies ?? []) { movie in Text(movie.title) } } } @MainActor func refresh() async throws { _ = try await queryRef.execute() } struct ContentView_Previews: PreviewProvider { static var previews: some View { ListMovieView() } }
Kotlin Android
- Add Firebase to your Android app.
To use the generated SDK, configure Data Connect as a dependency in Gradle.
Update
plugins
anddependencies
in yourapp/build.gradle.kts
.plugins { // Use whichever versions of these dependencies suit your application. // The versions shown here were the latest as of March 14, 2025. // Note, however, that the version of kotlin("plugin.serialization") must, // in general, match the version of kotlin("android"). id("com.android.application") version "8.9.0" id("com.google.gms.google-services") version "4.4.2" val kotlinVersion = "2.1.10" kotlin("android") version kotlinVersion kotlin("plugin.serialization") version kotlinVersion } dependencies { // Use whichever versions of these dependencies suit your application. // The versions shown here were the latest versions as of March 14, 2025. implementation("com.google.firebase:firebase-dataconnect:16.0.0-beta04") implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.1") implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:1.7.3") // These dependencies are not strictly required, but will very likely be used // when writing modern Android applications. implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.9.0") implementation("androidx.appcompat:appcompat:1.7.0") implementation("androidx.activity:activity-ktx:1.10.1") implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.7") implementation("com.google.android.material:material:1.12.0") }
In your app's main activity:
- import your generated SDK
- instrument your app to connect to the Data Connect emulator
- call Data Connect methods.
import android.os.Bundle import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import androidx.lifecycle.Lifecycle import androidx.lifecycle.lifecycleScope import androidx.lifecycle.repeatOnLifecycle import kotlinx.coroutines.launch private val connector = com.myapplication.MoviesConnector.instance .apply { // Connect to the emulator on "10.0.2.2:9399" (default port) dataConnect.useEmulator() // (alternatively) if you're running your emulator on non-default port: // dataConnect.useEmulator(port = 9999) } class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val textView: TextView = findViewById(R.id.text_view) lifecycleScope.launch { lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) { val result = connector.listMovies.runCatching { execute { } } val newTextViewText = result.fold( onSuccess = { val titles = it.data.movies.map { it.title } "${titles.size} movies: " + titles.joinToString(", ") }, onFailure = { "ERROR: ${it.message}" } ) textView.text = newTextViewText } } } }
Flutter
- Add Firebase to your Flutter app.
- Install the flutterfire CLI
dart pub global activate flutterfire_cli
. - Run
flutterfire configure
. - In your app's main function:
- import your generated SDK
- instrument your app to connect to the Data Connect emulator
- call Data Connect methods.
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'firebase_options.dart';
// Generated queries.
// Update as needed with the path to your generated SDK
import 'movies_connector/movies.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
MoviesConnector.instance.dataConnect
.useDataConnectEmulator(Uri.base.host, 443, isSecure: true);
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Column(children: [
ConstrainedBox(
constraints: const BoxConstraints(maxHeight: 200),
child: FutureBuilder(
future: MoviesConnector.instance.listMovies().execute(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return ListView.builder(
scrollDirection: Axis.vertical,
itemBuilder: (context, index) => Card(
child: Text(
snapshot.data!.data.movies[index].title,
)),
itemCount: snapshot.data!.data.movies.length,
);
}
return const CircularProgressIndicator();
}),
)
])));
}
}
Deploy your schema and query to production
Once you have your local setup on your app, now you can deploy your schema and connector to the cloud. You need a Blaze plan project to set up a Cloud SQL instance.
Navigate to Data Connect section of the Firebase console and create a free trial Cloud SQL instance.
In the IDE integrated Terminal, run
firebase init dataconnect
and select the Region/Service ID you just created on the console.Select "Y" when prompted with "File dataconnect/dataconnect.yaml already exists, Overwrite?".
In the IDE window, in the VS Code Extension UI, click the Deploy to production button.
Once deployed, go to the Firebase console to verify the schema, operations and data has been uploaded to the cloud. You should be able to view the schema, and run your operations on the console as well. The Cloud SQL for PostgreSQL instance will be updated with its final deployed generated schema and data.
Next steps
Review your deployed project and discover more tools:
- Add data to your database, inspect and modify your schemas, and monitor your Data Connect service in the Firebase console.
Access more information in the documentation. For example, since you've completed the quickstart:
- Learn more about schema, query and mutation development
- Learn about generating client SDKs and calling queries and mutations from client code for web, Android, and iOS, and Flutter.