Use AI assistance for Firebase Data Connect schemas, queries and mutations

You can use Gemini in Firebase to help you craft schemas, queries and mutations to include in your client-side code.

Describe an app and summarize its data model, or describe a query or mutation you want to generate in natural language, and Gemini in Firebase will provide you with its GraphQL equivalent.

This AI assistance is available in many development contexts:

  • In the Firebase console, run and test the output, deploy your schema and operations to production, and sync them to your local development environment.
  • Locally, in our Data Connect VS Code extension, design, run and test using Gemini Code Assist with a local PostgreSQL database and emulator.

Learn more about queries and mutations at Data Connect schemas, queries, and mutations .

How AI assistance for Data Connect uses your data

See How Gemini in Firebase uses your data for more information about how Gemini in Firebase uses your data.

Set up AI assistance for Data Connect

To set up AI assistance in Data Connect , enable Gemini in Firebase as described in Set up Gemini in Firebase , then proceed to Generate GraphQL queries and mutations with Gemini in Firebase .

Generate GraphQL schemas, queries and mutations with Gemini in Firebase

AI assistance for Data Connect is available in many contexts and in many of your workflows.

Create a new app and its initial schema and operations in the Firebase console

When you create a new Firebase project and set up to develop a new app, the Firebase console automatically offers AI assistance for schema and operations generation.

This setup flow lets you describe an app and then AI assistance:

  • Generates a complete Data Connect schema
  • Generates a useful, core set of queries and mutations you can then integrate with client code.

You sync these resources created in the console to your local development environment to continue integration with your clients.

This workflow is described in our Get started guide .

Add new queries and mutations to run in the Firebase console

To use AI assistance for Data Connect to generate GraphQL based on natural language:

  1. Open Data Connect in your project and, under Services, select your data source.

  2. Click Data.

  3. Click the Help me write GraphQL pen_spark icon.

  4. Inside the text field that appears, describe in natural language the query or mutation you want to generate, and click Generate.

    For example, if you're using the Movies data source referenced in the "Build with Data Connect (web)" codelab , you could ask, " Return the top five movies of 2022, in descending order by rating," which might return a result like the following:

      query 
      
     TopMovies2022 
      
     { 
      
     movies 
     ( 
     where 
     : 
      
     { 
     releaseYear 
     : 
      
     { 
     eq 
     : 
      
     2022 
     }}, 
      
     orderBy 
     : 
      
     [{ 
     rating 
     : 
      
     DESC 
     }], 
      
     limit 
     : 
      
     5 
     ) 
      
     { 
      
     id 
      
     title 
      
     rating 
      
     releaseYear 
      
     } 
     } 
     
    
  5. Review the response:

    • If the response looks correct, click Insertto insert the response into the code editor.
    • If the response could be refined, click Edit, update the prompt, and click Regenerate.
  6. After you've accepted the response, set the following in the Parameterssection, if applicable:

    • Variables: If your query or mutation contains variables, define them here. Use JSON to define them, for example, {"title":"The Matrix", "releaseYear":"1999"} .
    • Authorization: Choose the Authorization context (Administrator, Authenticated, or Unauthenticated) with which to run the query or mutation.
  7. Click Runin the code editor and review results.

To test multiple queries or mutations in the code editor, ensure they are named. For example, the following query is named GetMovie . Move your cursor into the first line of the query or mutation to activate the Runbutton.

  query 
  
 GetMovie 
 ( 
 $myKey 
 : 
  
 Movie_Key 
 !) 
  
 { 
  
 movie 
 ( 
 key 
 : 
  
 $myKey 
 ) 
  
 { 
  
 title 
  
 } 
 } 
 

Create an initial schema and operations during local prototyping

AI assistance is available from Gemini Code Assist for your local prototyping work when you use Visual Studio Code and our Data Connect VS Code extension.

The extension lets you describe an app and then Gemini Code Assist :

  • Generates a complete Data Connect schema
  • Generates a useful, core set of queries and mutations you can then integrate with client code.

This workflow is described in our Get started guide for local prototyping .

Use the Firebase MCP server in local prototyping

The Firebase MCP server, provided in the Firebase CLI, gives your AI-powered development tools the ability to work with your Firebase projects. The Firebase MCP server works with any AI assistant IDE that can act as an MCP client, including Cursor, Visual Studio Code Copilot, and Windsurf Editor.

You can use the MCP server to generate schemas, queries and mutations, and gather inputs to perform common operations with the Firebase CLI.

To use the MCP server:

  1. Install the server following this guide .
  2. Invoke the dataconnect_generate_schema tool, describe an app, and review the resulting recommended schema.
  3. Invoke the dataconnect_generate_operation tool, describe an operation you want to perform against your schema, and review the resulting recommended query or mutation.

For more Data Connect tools, see the MCP server guide .

More AI assistance for Data Connect use cases

The following sections describe sample use cases, including one where you can ask Gemini to help you create a mutation to populate Data Connect and then query it to verify the results.

Create a mutation that adds a movie to the database based on user input

In this section, you'll walk through an example of using natural language to generate GraphQL for a mutation that you can use to populate your database. This example assumes that you're using the movie database schema used in the Firebase Data Connect documentation and "Build with Data Connect (web)" codelab .

  1. From the Firebase console , open Data Connect .

  2. Select your service and data source, then open the Datatab.

  3. Click the Help me write GraphQL pen_spark icon and, in the box that appears, type your query:

     Create  
    a  
    movie  
    based  
    on  
    user  
    input. 
    
  4. Click Generate. The mutation is returned. For example, Gemini might return a mutation like:

      mutation 
      
     CreateMovie 
     ( 
     $title 
     : 
      
     String 
     !, 
      
     $releaseYear 
     : 
      
     Int 
     !, 
      
     $genre 
     : 
      
     String 
     !, 
      
     $rating 
     : 
      
     Float 
     !, 
      
     $description 
     : 
      
     String 
     !, 
      
     $imageUrl 
     : 
      
     String 
     !, 
      
     $tags 
     : 
      
     [ 
     String 
     !] 
      
     = 
      
     []) 
      
     @ 
     auth 
     ( 
     level 
     : 
      
     USER 
     ) 
      
     { 
      
     movie_insert 
     ( 
     data 
     : 
      
     { 
      
     title 
     : 
      
     $title 
     , 
      
     releaseYear 
     : 
      
     $releaseYear 
     , 
      
     genre 
     : 
      
     $genre 
     , 
      
     rating 
     : 
      
     $rating 
     , 
      
     description 
     : 
      
     $description 
     , 
      
     imageUrl 
     : 
      
     $imageUrl 
     , 
      
     tags 
     : 
      
     $tags 
      
     }) 
     } 
     
    
  5. Review the output. If needed, click Editto refine the prompt and click Regenerate.

  6. Next, click Insertto insert the mutation into the data editor.

  7. To execute the mutation, you'll need to add variables. From the Parameterssection, open Variablesand include some test variables:

      { 
     " 
     title 
     ":" 
     My 
      
     amazing 
      
     movie 
     " 
     , 
      
     " 
     releaseYear 
     ":2024 
     , 
      
     " 
     genre 
     ": 
      
     " 
     Comedy 
     " 
     , 
     " 
     rating 
     ": 
      
     8 
     , 
      
     " 
     description 
     ": 
      
     " 
     A 
      
     new 
      
     movie 
      
     to 
      
     test 
      
     mutations 
     " 
     , 
     " 
     imageUrl 
     ": 
      
     "" 
     , 
      
     " 
     tags 
     ": 
      
     [" 
     comedy 
     " 
     , 
     " 
     space 
      
     travel 
     "] 
     } 
     
    
  8. Click Run.

  9. Next, create a query that verifies that your movie was added. Click the Help me write GraphQL pen_spark and, in the box that appears, type your prompt:

     List  
    all  
    movies  
    from  
     2024 
      
    that  
    include  
    all  
    of  
    these  
    tags:  
     'space travel' 
    ,  
     'comedy' 
    . 
    

    Gemini might return a response like the following:

      query 
      
     ComedySpaceTravelMovies2024 
      
     @ 
     auth 
     ( 
     level 
     : 
      
     PUBLIC 
     ) 
      
     { 
      
     movies 
     ( 
      
     where 
     : 
      
     { 
      
     releaseYear 
     : 
      
     { 
      
     eq 
     : 
      
     2024 
      
     }, 
      
     tags 
     : 
      
     { 
      
     includesAll 
     : 
      
     [ 
     "space travel" 
     , 
      
     "comedy" 
     ] 
      
     } 
      
     } 
      
     ) 
      
     { 
      
     id 
      
     title 
      
     imageUrl 
      
     releaseYear 
      
     genre 
      
     rating 
      
     description 
      
     tags 
      
     } 
     } 
     
    
  10. Insert and run the query. The movie you added should appear in the Historyfield.

Create a query that lists reviews based on user-provided genre and ratings

In this section, you'll walk through an example of using natural language to generate GraphQL for a query. This example assumes that you're using the movie database used in the Firebase Data Connect documentation and "Build with Data Connect (web)" codelab .

  1. From the Firebase console , open Data Connect .

  2. Select your service and data source, then open the Datatab.

  3. Click the Help me write GraphQL pen_spark icon and, in the box that appears, type your query:

     List  
    all  
    movie  
    reviews,  
    based  
    on  
    user-configurable  
    genre  
    and  
    ratings. 
    
  4. Click Generate. The query is returned. For example, Gemini might return a query like:

      query 
      
     ListReviewsByGenreAndRating 
     ( 
     $genre 
     : 
      
     String 
     , 
      
     $minRating 
     : 
      
     Int 
     , 
      
     $maxRating 
     : 
      
     Int 
     ) 
      
     @ 
     auth 
     ( 
     level 
     : 
      
     PUBLIC 
     ) 
      
     { 
      
     reviews 
     ( 
     where 
     : 
      
     { 
      
     movie 
     : 
      
     { 
      
     genre 
     : 
      
     { 
     eq 
     : 
      
     $genre 
     } 
      
     }, 
      
     rating 
     : 
      
     { 
     ge 
     : 
      
     $minRating 
     , 
      
     le 
     : 
      
     $maxRating 
     } 
      
     }) 
      
     { 
      
     id 
      
     user 
      
     { 
      
     username 
      
     } 
      
     movie 
      
     { 
      
     title 
      
     genre 
      
     } 
      
     rating 
      
     reviewText 
      
     reviewDate 
      
     } 
     } 
     
    
  5. Review the output. If needed, click Editto refine the prompt and click Regenerate.

  6. Next, click Insertto insert the mutation into the data editor.

  7. To test this query, you'll need to add variables. From the Parameterssection, open Variablesand include variables to use for testing:

      { 
     "genre" 
     : 
     "sci-fi" 
     , 
      
     "minRating" 
     : 
     4 
     , 
      
     "maxRating" 
     : 
     9 
     } 
     
    
  8. Click Run.

Design prompts to use with third-party AI assistance tools

As with all AI assistance tools and agents, the better your prompts, the more useful your outputs.

When you provide natural language prompts to Gemini in Firebase , behind the scenes, the assistant translates your inputs to a more fully-developed prompt.

If you're not using Gemini in Firebase or other Firebase AI assistance, and are working with third-party AI tooling like Cursor or Windsurf, you can get better recommendations about Data Connect by using similar fleshed-out prompts.

We've published prompt templates for you to download, adapt, and copy into your IDE:

After downloading and modifying, create a prompt in familiar tooling (for example Cursor or Windsurf) as follows:

  • In Cursor (be sure to review the latest instructions from Cursor ):

    1. Click the settings icon on top right.
    2. Select the Rulestab.
    3. Under the Project Rules, click Add a new rulebutton.
    4. Copy and paste the rule.
  • In Windsurf (be sure to review the latest instructions from Windsurf ):

    1. Open the Cascade window by clicking the Cascadebutton in the top right corner.
    2. Click the Customizationsicon in the top right slider menu in Cascade, then navigate to the Rulespanel.
    3. Click the + Globalor + Workspacebutton to create new rules at either the global or workspace level, respectively.
    4. Copy and paste the rule.

Troubleshoot AI assistance for Data Connect

Refer to Troubleshoot Gemini in Firebase .

Pricing

AI assistance for Data Connect is available as part of Gemini in Firebase , which is included for individual users.

See Gemini in Firebase pricing for more information.

Next steps

Design a Mobile Site
View Site in Mobile | Classic
Share by: