Data Connect 配置文件参考

借助 Firebase CLI,您可以在本地, 可进行版本控制的项目目录中管理 Firebase 项目。这包括项目中的 Data Connect 服务、这些服务的连接器,以及每个连接器的架构、查询和突变来源等资源。您还可以使用 CLI 安装和运行 Firebase Data Connect 模拟器。与在 Firebase 控制台中操作相比,CLI 是一种更 高效的替代方案。

如需了解如何安装 Firebase CLI 实验版以参与 Private Preview 计划,以及 Data Connect-相关 CLI 命令,请参阅 CLI 参考文档

本参考指南介绍了以下内容:

  • 项目配置文件 firebase.json 中特定于 Data Connect- 的条目。
  • Data Connect 配置在 dataconnect.yamlconnector.yaml 中。

Firebase 项目配置文件

firebase.json 配置参考文档

使用 dataconnect 键在项目中配置一项或多项 Data Connect 服务。

dataconnect: {
   source: string // Path to the directory containing the dataconnect.yaml service file.
}

dataconnect.yaml 配置参考文档

dataconnect.yaml 文件存储有关应用架构来源、连接器来源和数据源连接信息的位置的配置信息。该文件还充当 Firebase CLI 的项目目录标识符。

schemaValidation 键用于控制在部署期间迁移架构时执行的架构验证级别。如果未设置任何值,dataconect:sql:migrate 命令的行为是应用兼容的更改,并在执行任何严格的更改之前提示您。如果已设置,则行为如下:

  • STRICT 模式。数据库架构必须与应用架构完全匹配,然后才能部署应用架构。Data Connect Data Connect 架构中未使用的任何 表或列 都将从数据库中删除。
  • COMPATIBLE 模式。数据库架构必须与应用架构兼容,然后才能部署应用架构;任何其他更改都被视为可选。兼容是指架构迁移基于您编写的应用架构。数据库中未被应用架构使用的元素将保持不变。 因此,部署后,后端可能包含未使用的架构、表和列。

此文件中其他键的值将在下面的注释中进行说明。

# The top-level Firebase Data Connect YAML file.

# The Firebase Data Connect API version to target.
# Optional. Defaults to the latest version.
specVersion: string

# The ID of the Firebase Data Connect service resource.
# Required.
serviceId: string

# The location of the Firebase Data Connect service.
# Required.
location: string

# Required.
schema:
  # Relative path to directory for schema definitions.
  # Recursively loads all .gql files in this directory.
  # Optional. If not present, defaults to ./schema.
  source: string
  # Datasource connection information.
  # Required.
  datasource:
    # Required.
    postgresql:
      # The name of the PostgreSQL database.
      # Required.
      database: string
      cloudSql:
        # The ID of the CloudSQL instance resource.
        # Required.
        instanceId: string
        # Schema validation mode for schema migrations.
        # Defaults to unspecified/commented out, meaning you are prompted to
        # review all changes during migration.
        # If desired, uncomment and indicate one of "STRICT" or "COMPATIBLE".
        schemaValidation: string

# Required.
# Relative paths to directories for connector definitions.
# Recursively loads all .gql files in the listed directories.
# All directories specified MUST contain a connector.yaml file.
connectorDirs: [string]

YAML 文件采用以下默认(但可配置)目录结构:

./(project root)
   /dataconnect
      dataconnect.yaml
      /schema
        *.gql
      /example
        connector.yaml
        *.gql

connector.yaml 配置参考文档

使用 connector.yaml 配置默认身份验证模式和 SDK 生成选项。

# The connector-level YAML file.

# Required. The connector name of the Firebase Data Connect connector resource.
connectorId: string

# Optional. If not specified, no generated libraries (i.e. type-safe SDKs) will
# be generated.
generate:
    # Optional.
    javascriptSdk:
        # Path to the directory that will be updated with the latest generated
        # web TypeScript SDK.
        # Required.
        outputDir: string
        # Name of the Javascript package to be created.
        # Required. Example: @dataconnect/generated
        package: string
        # Path to your package.json directory. If specified, the new generated
        # SDK will be installed in this path.
        # Optional. If not provided, the package will not be auto-installed for
        # you.
        packageJsonDir: string
        # Enable React framework bindings.
        # Optional. Default to false.
        react: Boolean
        # Enable Angular framework bindings.
        # Optional. Default to false.
        angular: Boolean
    # Optional.
    dartSdk:
        # Path to the directory that will be updated with the latest generated
        # Flutter Dart SDK.
        # Required.
        outputDir: string
        # Name of the Dart package to be created.
        # Required. Example: "dataconnect_generated"
        package: string
    # Optional.
    kotlinSdk:
        # Path to the directory that will be updated with the latest generated
        # Android SDK.
        # Required.
        outputDir: string
        # Name of the package to be created.
        # Required. Example: com.google.firebase.dataconnect.generated
        package: string
    # Optional.
    adminNodeSdk:
        # Path to the directory that will be updated with the latest generated
        # Node Admin SDK.
        # Required.
        outputDir: string
        # Path to your package.json directory. If specified, the new generated
        # SDK will be installed in this path.
        # Optional. If not provided, the package will not be auto-installed for
        # you.
        packageJsonDir: string
        # Name of the package to be created (for example: @dataconnect/admin-generated).
        # Required.
        package: string
    # Optional.
    swiftSdk:
        # Path to the directory that will be updated with the latest generated
        # iOS Swift SDK.
        # Required.
        outputDir: string
        # Name of the Swift package to be created.
        # Required. Example: "FirebaseDataConnectGenerated"
        package: string