Skip to content

Provide full DocumentNode when validating operations #8408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions firebase-vscode/src/data-connect/code-lens-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class OperationCodeLensProvider extends ComputedCodeLensProvider {
title: `$(play) Run (local)`,
command: "firebase.dataConnect.executeOperation",
tooltip: "Execute the operation (⌘+enter or Ctrl+Enter)",
arguments: [x, operationLocation, InstanceType.LOCAL],
arguments: [x, documentNode, operationLocation, InstanceType.LOCAL],
}),
);

Expand All @@ -112,7 +112,7 @@ export class OperationCodeLensProvider extends ComputedCodeLensProvider {
title: `$(play) Run (Production – Project: ${rc.projects.default})`,
command: "firebase.dataConnect.executeOperation",
tooltip: "Execute the operation (⌘+enter or Ctrl+Enter)",
arguments: [x, operationLocation, InstanceType.PRODUCTION],
arguments: [x, documentNode, operationLocation, InstanceType.PRODUCTION],
}),
);
}
Expand Down
14 changes: 9 additions & 5 deletions firebase-vscode/src/data-connect/execution/execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ interface TypedInput {

interface ExecutionInput {
ast: OperationDefinitionNode;
documentNode: DocumentNode;
location: OperationLocation;
instance: InstanceType;
}
Expand Down Expand Up @@ -106,19 +107,22 @@ export function registerExecution(
}
executeOperation(
lastExecutionInputSignal.value.ast,
lastExecutionInputSignal.value.documentNode,
lastExecutionInputSignal.value.location,
lastExecutionInputSignal.value.instance,
);
});

async function executeOperation(
ast: OperationDefinitionNode,
documentNode: DocumentNode,
{ document, documentPath, position }: OperationLocation,
instance: InstanceType,
) {
// hold last execution in memory, and send operation name to webview
lastExecutionInputSignal.value = {
ast,
documentNode,
location: { document, documentPath, position },
instance,
};
Expand Down Expand Up @@ -189,12 +193,12 @@ export function registerExecution(
const schema = buildClientSchema(introspect.data);
const validationErrors = validate(
schema,
operationDefinitionToDocument(ast),
documentNode,
);

if (validationErrors.length > 0) {
executionError(
"Schema validation errors: ",
`Schema validation errors:`,
JSON.stringify(validationErrors),
);
return undefined;
Expand Down Expand Up @@ -311,13 +315,13 @@ export function registerExecution(
executionHistoryTreeView,
vscode.commands.registerCommand(
"firebase.dataConnect.executeOperation",
(ast, location, instanceType: InstanceType) => {
(operationAST, fullAST, location, instanceType: InstanceType) => {
analyticsLogger.logger.logUsage(
instanceType === InstanceType.LOCAL
? DATA_CONNECT_EVENT_NAME.RUN_LOCAL
: DATA_CONNECT_EVENT_NAME.RUN_PROD,
);
executeOperation(ast, location, instanceType);
executeOperation(operationAST, fullAST, location, instanceType);
},
),
vscode.commands.registerCommand(
Expand All @@ -336,7 +340,7 @@ export function registerExecution(
}

function executionError(message: string, error?: string) {
vscode.window.showErrorMessage(`Failed to execute operation. ${message}`);
vscode.window.showErrorMessage(`Failed to execute operation: ${message}: \n${JSON.stringify(error, undefined, 2)}`);
throw new Error(error);
}

Expand Down
Loading