El Firebase CLI te permite administrar tus proyectos de Firebase en un directorio de proyectos local, con control de versiones. Esto incluye los Data Connect servicios en tus proyectos, los conectores para esos servicios y los recursos como el esquema, las fuentes de consultas y mutaciones para cada conector. La CLI también te permite instalar y operar el Firebase Data Connect emulador. La CLI es una alternativa eficiente para trabajar en la Firebase consola.
Para obtener instrucciones sobre cómo instalar el experimento de CLI Firebase para el programa de vista previa privada y los comandos de la CLI relacionados con Data Connect, consulta la referencia de la CLI.
En esta guía de referencia, se documenta lo siguiente:
- Entradas específicas de Data Connect en tu archivo de configuración del proyecto
firebase.json - Data Connect configuraciones en
dataconnect.yamlyconnector.yaml.
Archivos de configuración del proyecto de Firebase
Referencia de configuración firebase.json
Usa las claves dataconnect para configurar uno o más Data Connect
servicios en tu proyecto.
dataconnect: {
source: string // Path to the directory containing the dataconnect.yaml service file.
}
Referencia de configuración dataconnect.yaml
El archivo dataconnect.yaml almacena información de configuración sobre las ubicaciones de las fuentes del esquema de la aplicación, las fuentes del conector y la información de conexión de la fuente de datos. El archivo también sirve como indicador de directorio de proyectos para la
Firebase CLI.
La clave schemaValidation controla el nivel de validación del esquema que se realiza cuando se migran los esquemas durante la implementación. Sin ningún valor establecido, el comportamiento del comando dataconect:sql:migrate es aplicar cambios compatibles y solicitarte confirmación antes de ejecutar cualquier cambio estricto. Cuando se establece, el comportamiento es el siguiente:
- Modo
STRICT. El esquema de la base de datos debe coincidir exactamente con el esquema de la aplicación antes de que se pueda implementar. Cualquier tabla o columna que no se use en tu Data Connect esquema se borrará de la base de datos. - Modo
COMPATIBLE. El esquema de la base de datos debe ser compatible con el esquema de la aplicación antes de que se pueda implementar; cualquier cambio adicional se considera opcional. Compatible significa que las migraciones de esquemas se basan en el esquema de la aplicación que escribes. Los elementos de tu base de datos que no usa el esquema de tu aplicación no se modifican. Por lo tanto, después de la implementación, tu backend puede contener esquemas, tablas y columnas sin usar.
Los valores de otras claves de este archivo se explican en los comentarios a continuación.
# 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]
El archivo YAML supone una estructura de directorio predeterminada (pero configurable) de la siguiente manera:
./(project root)
/dataconnect
dataconnect.yaml
/schema
*.gql
/example
connector.yaml
*.gql
Referencia de configuración connector.yaml
Usa connector.yaml para configurar el modo de autenticación predeterminado y las opciones de generación del 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
# Enable and configure client-side caching for the generated SDK.
# Optional. If the `clientCache` key is not present, caching is disabled.
clientCache:
# The maximum age allowed for cached results before fetching fresh
# values. A value of "0" means that responses are cached, but the
# client SDK will always fetch fresh values; the cached values are
# only used when CACHE_ONLY is specified to executeQuery() and as the
# initial result returned from subscribe().
# Examples: "0", "30s", "1h30m"
# Optional. Default: "0"
maxAge: string
# Configures how results are to be cached.
# Optional. Only "memory" is allowed for JavaScript SDKs.
storage: string
# 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
# Enable and configure client-side caching for the generated SDK.
# Optional. If the `clientCache` key is not present, caching is disabled.
clientCache:
# The maximum age allowed for cached results before fetching fresh
# values. A value of "0" means that responses are cached, but the
# client SDK will always fetch fresh values; the cached values are
# only used when CACHE_ONLY is specified to execute() and as the
# initial result returned from subscribe().
# Examples: "0", "30s", "1h30m"
# Optional. Default: "0"
maxAge: string
# Configures whether results are to be cached in persistent storage
# or in memory ("persistent" or "memory").
# Optional.
# Default: "persistent" for Android and iOS targets, "memory" for web.
storage: 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
# Enable and configure client-side caching for the generated SDK.
# Optional. If the `clientCache` key is not present, caching is disabled.
clientCache:
# The maximum age allowed for cached results before fetching fresh
# values. A value of "0" means that responses are cached, but the
# client SDK will always fetch fresh values; the cached values are
# only used when CACHE_ONLY is specified to execute().
# Examples: "0", "30s", "1h30m"
# Optional. Default: "0"
maxAge: string
# Configures whether results are to be cached in persistent storage
# or in memory ("persistent" or "memory").
# Optional. Default: persistent
storage: 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
# Enable and configure client-side caching for the generated SDK.
# Optional. If the `clientCache` key is not present, caching is disabled.
clientCache:
# The maximum age allowed for cached results before fetching fresh
# values. A value of "0" means that responses are cached, but the
# client SDK will always fetch fresh values; the cached values are
# only used when CACHE_ONLY is specified to execute().
# Examples: "0", "30s", "1h30m"
# Optional. Default: "0"
maxAge: string
# Configures whether results are to be cached in persistent storage
# or in memory ("persistent" or "memory").
# Optional. Default: persistent
storage: string