Get started with Firebase Data Connect Stay organized with collections Save and categorize content based on your preferences.
This quickstart gets you up and running withFirebase Data Connect toconnect your web and mobile apps to a PostgreSQL database. You will:
- Set up your localFirebase Data Connect project directory with VS Codeand the Firebase CLI.
- GenerateData Connect schemas, queries and mutations based on yourapp ideas in natural language.
- Use the strongly-typed SDKs in your apps to runData Connectqueries and mutations.
- Provision a Cloud SQL for PostgreSQL instance, a Data Connect schema,queries, and mutations (requires a Blaze plan).
Set up the local project directory
You can install local development tools forData Connect in two ways.
In a project directory, run the following command.
The script installs the Firebase CLI and theData Connect VS Code extension, and guides you through
firebase initdataconnectto set up your project. If you don't have VS Code desktopinstalled, the script opens it in a browser.curl-sLhttps://firebase.tools/init/dataconnect|editor=truebashOpen the Data Connect VS Code extension screen by clicking the Firebaseicon in the Visual Studio Code left panel.
ClickStart emulators to run the emulator with a local PGlite database.
Review schema
Firebase Data Connect uses GraphQL to define your data model. The@table directive maps aGraphQL type to a PostgreSQL table. Fields in the type map to PostgreSQLcolumns. You can define relationships between tables using fields that referenceother@table types, including many-to-many relationships using join tableswith composite primary keys.
In the default setup, you can find theData Connect schema files inthedataconnect/schema/ directory. Here are two example tables from the movietemplate schema. Your schema may be different if you used Gemini to generate it.
typeMovie@table{# Every table has an implicit primary key field that looks something like:# id: UUID! @default(expr: "uuidV4()")title:String!imageUrl:String!genre:String}typeReview@table(key:["movie","user"]){user:User!movie:Movie!rating:IntreviewText:StringreviewDate:Date!@default(expr:"request.time")}Learn more about Data Connect schemas
Develop queries and mutations
Firebase Data Connect uses GraphQL for queries and mutations. You definethese in.gql files and call them by name from your app. GraphQL syntaxprovides strongly-typed SDKs and a flexible API to fetch the exact data your appneeds.
Seed data in your database
With the emulator running, you can seed it with initial data. You can use theprovideddataconnect/seed_data.gql file or write your own mutations.
Use theRun (local) Code Lens button in VS Code to execute the mutations andpopulate your local PGlite database.

Review queries and mutations
In the default setup, you can find the Data Connect queries and mutations indataconnect/example/ directory.
You can query relational data precisely with nested queries.
queryListMovies@auth(level:PUBLIC,insecureReason:"Anyonecanlistallmoviesandtheirreviews."){movies{titleimageUrlgenrereviews_on_movie{ratingreviewDateuser{username}}}}Data Connect helps you build secure queries and mutations withFirebase Auth.
To keep your app secure, web and mobile apps can only accessData Connect queries and mutations with@authdirectives. Queries and mutations can securely access the Firebase Auth UIDusing an expression like{field}_expr: "auth.uid".
mutationAddReview($movieId:UUID!,$rating:Int!,$reviewText:String!)@auth(level:USER){review_upsert(data:{userId_expr:"auth.uid"movieId:$movieIdrating:$ratingreviewText:$reviewText})}Learn more about Data Connect queriesLearn more about Data Connect mutationsLearn more about Data Connect Auth
Generate queries and mutations
You don't need to be a GraphQL expert to useData Connect effectively.You can generateData Connect queries and mutations from naturallanguage descriptions.
In any.gql file, type# to start a comment and describe a query ormutation. Then, use theGenerate/Refine Operation Code Lens button togenerate the GraphQL operation.

Use generated SDK in your app
firebase init dataconnect automatically sets up type-safe SDKs for apps inyour project. If needed, you can add the SDK manually with theAdd SDK toapp button in the VS Code extension or by runningfirebase initdataconnect:sdk.
Web
- Add Firebase to yourweb app.
In your React app's main file:
- Import your generated SDK:
// Update as needed with the path to your generated SDK.import{listMovies,ListMoviesData}from'@dataconnect/generated';- Instrument your app to connect to theData Connect emulator:
import{connectDataConnectEmulator}from'firebase/data-connect';constdataConnect=getDataConnect(connectorConfig);connectDataConnectEmulator(dataConnect,'localhost',9399);- CallData Connect methods.
Note: In this sample, the React app calls your query using the FirebaseJavaScript SDK.Data Connect also provides special bindings towork withData Connect asynchronously inReact.functionApp(){const[movies,setMovies]=useState<ListMoviesData['movies']>([]);useEffect(()=>{listMovies.then(res=>setMovies(res.data));},[]);return(movies.map(movie=><h1>{movie.title}</h1>););}constroot=ReactDOM.createRoot(document.getElementById('root'));root.render(<App/>);
Swift
- Add Firebase to youriOS app.
To use the generated SDK, configure it as a dependency in Xcode.
In the Xcode top navigation bar, selectFile > Add Package Dependencies > Add Local, and choose the foldercontaining the generated
Package.swift.In your app's main delegate:
Import theData Connect SDK and your generated SDK:
importFirebaseDataConnect// Generated queries.// Update as needed with the package name of your generated SDK.import<CONNECTOR-PACKAGE-NAME>letconnector=DataConnect.moviesConnectorInstrument your app to connect to theData Connect emulator:
// 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)CallData Connect methods:
structListMovieView:View{@StateObjectprivatevarqueryRef=connector.listMovies.ref()varbody:someView{VStack{Button{Task{do{tryawaitrefresh()}catch{print("Failed to refresh:\(error)")}}}label:{Text("Refresh")}// use the query results in a viewForEach(queryRef.data?.movies??[]){movieinText(movie.title)}}}}@MainActorfuncrefresh()asyncthrows{_=tryawaitqueryRef.execute()}structContentView_Previews:PreviewProvider{staticvarpreviews:someView{ListMovieView()}}
Kotlin Android
- Add Firebase to yourAndroid app.
To use the generated SDK, configureData Connect as a dependencyin Gradle.
Update
pluginsanddependenciesin 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"valkotlinVersion="2.1.10"kotlin("android")versionkotlinVersionkotlin("plugin.serialization")versionkotlinVersion}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:
- Get a connector instance from your generated SDK:
privatevalconnector=com.myapplication.MoviesConnector.instance- Instrument your app to connect to theData Connect emulator:
privatevalconnector=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)}- CallData Connect methods.
classMainActivity:AppCompatActivity(){overridefunonCreate(savedInstanceState:Bundle?){super.onCreate(savedInstanceState)setContentView(R.layout.activity_main)valtextView:TextView=findViewById(R.id.text_view)lifecycleScope.launch{lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED){valresult=connector.listMovies.runCatching{execute{}}valnewTextViewText=result.fold(onSuccess={valtitles=it.data.movies.map{it.title}"${titles.size} movies: "+titles.joinToString(", ")},onFailure={"ERROR:${it.message}"})textView.text=newTextViewText}}}}
Flutter
- Add Firebase to yourFlutter app.
- Install the flutterfire CLI
dart pub global activate flutterfire_cli. - Run
flutterfire configure. In your app's main function:
- Import your generated SDK:
// Generated queries.// Update as needed with the path to your generated SDKimport'movies_connector/movies.dart';- Instrument your app to connect to theData Connect emulator:
voidmain()async{WidgetsFlutterBinding.ensureInitialized();awaitFirebase.initializeApp(options:DefaultFirebaseOptions.currentPlatform,);MoviesConnector.instance.dataConnect.useDataConnectEmulator(Uri.base.host,443,isSecure:true);runApp(constMyApp());}- CallData Connect methods.
classMyAppextendsStatelessWidget{constMyApp({super.key});@overrideWidgetbuild(BuildContextcontext){returnMaterialApp(home:Scaffold(body:Column(children:[ConstrainedBox(constraints:constBoxConstraints(maxHeight:200),child:FutureBuilder(future:MoviesConnector.instance.listMovies().execute(),builder:(context,snapshot){if(snapshot.connectionState==ConnectionState.done){returnListView.builder(scrollDirection:Axis.vertical,itemBuilder:(context,index)=>Card(child:Text(snapshot.data!.data.movies[index].title,)),itemCount:snapshot.data!.data.movies.length,);}returnconstCircularProgressIndicator();}),)])));}}
Deploy to production
To deploy yourschema, queries and mutations to production:
Upgrade the Firebase Project to use the Blaze plan.
Click theDeploy to production button inData Connect VS Code extension or run in a terminal:
firebasedeploy--onlydataconnectAfter deploying, visit theFirebase console to view yourschema and run queries and mutations.
Tip: You can configure Cloud SQL region, instance name and PostgreSQLdatabase name indataconnect.yamlbefore deploy.Tip: Each project is eligible for one Cloud SQL 3 month free trial instance.Seeitslimitations.
Learn more about dataconnect.yamlLearn more about howData Connect works with Cloud SQL
Next steps
Now that you've completed the quickstart, here are some next steps:
- Explore a quickstart app repository and build afully-featuredData Connect app by following ourcodelab for web,codelab for iOS,orcodelab for Android.
- Add data to your database, inspect your schemas, and monitor your DataConnect service in theFirebase console.
- Set up theFirebase MCP serverwith AI-powered development tools likeGemini Code Assist.
- Learn more aboutschema,query andmutation development.
- Learn more about howData Connectmanages PostgreSQLschema.
- Learn more about client SDKs forweb,Android,iOS, andFlutter as well as Admin SDKs forNode.js.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-02-10 UTC.