Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

Commit f012017

Browse files
Ghislain BeaulacGhislain Beaulac
authored andcommitted
fix graphQL should cast to Promise also on a filter change
1 parent 87caaa1 commit f012017

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/app/modules/angular-slickgrid/services/controlAndPlugin.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
HeaderButtonOnCommandArgs,
1010
HeaderMenuOnCommandArgs,
1111
HeaderMenuOnBeforeMenuShowArgs
12-
} from './../models/index';
12+
} from './../models';
1313

1414
// using external js modules in Angular
1515
declare var Slick: any;

src/app/modules/angular-slickgrid/services/filter.service.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { castToPromise } from './utilities';
12
import { FilterConditions } from './../filter-conditions';
23
import { FilterTemplates } from './../filter-templates';
34
import {
@@ -53,22 +54,23 @@ export class FilterService {
5354
if (!serviceOptions || !serviceOptions.onBackendEventApi || !serviceOptions.onBackendEventApi.process || !serviceOptions.onBackendEventApi.service) {
5455
throw new Error(`onBackendEventApi requires at least a "process" function and a "service" defined`);
5556
}
56-
const backendApi = serviceOptions.onBackendEventApi;
5757

5858
// run a preProcess callback if defined
59-
if (backendApi.preProcess !== undefined) {
60-
backendApi.preProcess();
59+
if (serviceOptions.onBackendEventApi.preProcess) {
60+
serviceOptions.onBackendEventApi.preProcess();
6161
}
6262

6363
// call the service to get a query back
64-
const query = await backendApi.service.onFilterChanged(event, args);
64+
const query = await serviceOptions.onBackendEventApi.service.onFilterChanged(event, args);
6565

66-
// await for the Promise to resolve the data
67-
const responseProcess = await backendApi.process(query);
66+
// the process could be an Observable (like HttpClient) or a Promise
67+
// in any case, we need to have a Promise so that we can await on it (if an Observable, convert it to Promise)
68+
const observableOrPromise = serviceOptions.onBackendEventApi.process(query);
69+
const responseProcess = await castToPromise(observableOrPromise);
6870

6971
// send the response process to the postProcess callback
70-
if (backendApi.postProcess !== undefined) {
71-
backendApi.postProcess(responseProcess);
72+
if (serviceOptions.onBackendEventApi.postProcess !== undefined) {
73+
serviceOptions.onBackendEventApi.postProcess(responseProcess);
7274
}
7375
}
7476

0 commit comments

Comments
 (0)