Skip to content

Commit

Permalink
Use PMCD returned by mappinganalysis to build minimal graph for query
Browse files Browse the repository at this point in the history
  • Loading branch information
Gayathri committed Sep 13, 2023
1 parent 655cbdc commit f96aef9
Show file tree
Hide file tree
Showing 17 changed files with 907 additions and 309 deletions.
3 changes: 3 additions & 0 deletions .changeset/clean-toes-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
'@finos/legend-graph': patch
---
6 changes: 6 additions & 0 deletions .changeset/kind-rabbits-draw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@finos/legend-extension-dsl-data-space': minor
'@finos/legend-application-query': minor
---

Use PMCD returned by mapping analysis to build minimal graph for query
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

import { LegendApplicationPlugin } from '@finos/legend-application';
import type { Query } from '@finos/legend-graph';
import type { QueryBuilderState } from '@finos/legend-query-builder';
import type React from 'react';
import type { LegendQueryPluginManager } from '../application/LegendQueryPluginManager.js';
Expand Down Expand Up @@ -52,10 +51,13 @@ export type QuerySetupActionConfiguration = {
};

export type ExistingQueryEditorStateBuilder = (
query: Query,
editorStore: ExistingQueryEditorStore,
) => Promise<QueryBuilderState | undefined>;

export type ExistingQueryGraphBuilderChecker = (
editorStore: ExistingQueryEditorStore,
) => boolean | undefined;

export type QueryEditorActionConfiguration = {
key: string;
renderer: (
Expand Down Expand Up @@ -98,6 +100,11 @@ export abstract class LegendQueryApplicationPlugin extends LegendApplicationPlug
*/
getExtraExistingQueryEditorStateBuilders?(): ExistingQueryEditorStateBuilder[];

/**
* Get the list of existing query graph builder checkers
*/
getExtraExistingQueryGraphBuilderCheckers?(): ExistingQueryGraphBuilderChecker[];

/**
* Get the list of query editor action renderer configurations.
*/
Expand Down
39 changes: 34 additions & 5 deletions packages/legend-application-query/src/stores/QueryEditorStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,10 @@ export abstract class QueryEditorStore {
// do nothing
}

requiresGraphBuilding(): boolean {
return true;
}

async buildQueryForPersistence(
query: Query,
rawLambda: RawLambda,
Expand Down Expand Up @@ -485,7 +489,9 @@ export abstract class QueryEditorStore {
);

yield this.setUpEditorState();
yield flowResult(this.buildGraph());
if (this.requiresGraphBuilding()) {
yield flowResult(this.buildGraph());
}
this.queryBuilderState = (yield this.initializeQueryBuilderState(
stopWatch,
)) as QueryBuilderState;
Expand Down Expand Up @@ -991,9 +997,24 @@ export class ExistingQueryEditorStore extends QueryEditorStore {
);
}

async initializeQueryBuilderState(
stopWatch: StopWatch,
): Promise<QueryBuilderState> {
override requiresGraphBuilding(): boolean {
const existingQueryGraphBuilderCheckers =
this.applicationStore.pluginManager
.getApplicationPlugins()
.flatMap(
(plugin) =>
plugin.getExtraExistingQueryGraphBuilderCheckers?.() ?? [],
);
for (const checker of existingQueryGraphBuilderCheckers) {
const isGraphBuildingRequired = checker(this);
if (isGraphBuildingRequired !== undefined) {
return isGraphBuildingRequired;
}
}
return true;
}

async setupQuery(): Promise<void> {
const query = await this.graphManagerState.graphManager.getQuery(
this.queryId,
this.graphManagerState.graph,
Expand All @@ -1003,19 +1024,27 @@ export class ExistingQueryEditorStore extends QueryEditorStore {
this.applicationStore.userDataService,
query.id,
);
}

async initializeQueryBuilderState(
stopWatch: StopWatch,
): Promise<QueryBuilderState> {
let queryBuilderState: QueryBuilderState | undefined;
const existingQueryEditorStateBuilders = this.applicationStore.pluginManager
.getApplicationPlugins()
.flatMap(
(plugin) => plugin.getExtraExistingQueryEditorStateBuilders?.() ?? [],
);
for (const builder of existingQueryEditorStateBuilders) {
queryBuilderState = await builder(query, this);
queryBuilderState = await builder(this);
if (queryBuilderState) {
break;
}
}

await this.setupQuery();
const query = guaranteeNonNullable(this.query);

// if no extension found, fall back to basic `class -> mapping -> runtime` mode
queryBuilderState =
queryBuilderState ??
Expand Down
Loading

0 comments on commit f96aef9

Please sign in to comment.