Skip to content

Commit

Permalink
Flows store
Browse files Browse the repository at this point in the history
  • Loading branch information
omreego committed Jan 9, 2024
1 parent eaac1bc commit 05db435
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/adapter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ export function asV2AST(ast: gql.ASTNode, typeInfo: gql.TypeInfo): gql.ASTNode {
}));
}


/** Shim that retrieves data from a V2 graph using a V1 query */
export class QueryAdapter {
constructor(
Expand Down Expand Up @@ -420,10 +421,28 @@ export class QueryAdapter {
args: Map<string, any> = new Map<string, any>(),
postProcessV2Query: (v2Query: string) => string = _.identity
): AsyncIterable<any> {
// Returns an object with a default async iterator
const v1AST = gql.parse(v1Query);
const validationErrors = gql.validate(this.v1Schema, v1AST);
const v1TypeInfo = new gql.TypeInfo(this.v1Schema);
const nodePaths = this.nodePaths(v1AST, v1TypeInfo);
const v2Query = postProcessV2Query(gql.print(asV2AST(v1AST, v1TypeInfo)));
let v2Query: string;
if (validationErrors.length > 0) {
const v2ValidationErrors = gql.validate(this.v2Schema, v1AST);
if (v2ValidationErrors.length > 0) {
throw new VError(
'invalid query: %s\nValidation errors: %s',
v1Query,
validationErrors.map((err) => err.message).join(', ') +
v2ValidationErrors.map((err) => err.message).join(', ')
);
}
// Errors means the query is likely already a V2 query
v2Query = v1Query;

} else {
v2Query = postProcessV2Query(gql.print(asV2AST(v1AST, v1TypeInfo)));
}
const v2Nodes = this.faros.nodeIterable(
graph,
v2Query,
Expand Down

0 comments on commit 05db435

Please sign in to comment.