-
Notifications
You must be signed in to change notification settings - Fork 918
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate local schema and connectors together before deploy (#952)
* Starting on build * types * Progress! * Prettify errors * Line numbers, and save deployment metadata * Extremely defensive
- Loading branch information
Showing
8 changed files
with
91 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { DataConnectEmulator, DataConnectEmulatorArgs } from "../emulator/dataconnectEmulator"; | ||
import { Options } from "../options"; | ||
import { FirebaseError } from "../error"; | ||
import { prettify } from "./graphqlError"; | ||
import { DeploymentMetadata } from "./types"; | ||
|
||
export async function build(options: Options, configDir: string): Promise<DeploymentMetadata> { | ||
// We can build even if there is no project declared. | ||
const projectId = options.project ?? "demo-test"; | ||
const args: DataConnectEmulatorArgs = { | ||
projectId, | ||
configDir, | ||
auto_download: true, | ||
rc: options.rc, | ||
}; | ||
const dataconnectEmulator = new DataConnectEmulator(args); | ||
const buildResult = await dataconnectEmulator.build(); | ||
if (buildResult?.errors?.length) { | ||
throw new FirebaseError( | ||
`There are errors in your schema and connector files:\n${buildResult.errors.map(prettify).join("\n")}`, | ||
); | ||
} | ||
return buildResult?.deploymentMetadata ?? {}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { GraphqlError } from "./types"; | ||
|
||
export function prettify(err: GraphqlError): string { | ||
const message = err.message; | ||
let header = err.extensions.file ?? ""; | ||
for (const loc of err.locations) { | ||
header += `(${loc.line}, ${loc.column})`; | ||
} | ||
return header.length ? `${header}: ${message}` : message; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters