@slickgrid-universal/graphql 5.4.0 → 5.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/services/graphql.service.js +21 -9
- package/dist/cjs/services/graphql.service.js.map +1 -1
- package/dist/esm/services/graphql.service.js +22 -12
- package/dist/esm/services/graphql.service.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/interfaces/graphqlPaginatedResult.interface.d.ts +2 -0
- package/dist/types/interfaces/graphqlPaginatedResult.interface.d.ts.map +1 -1
- package/dist/types/services/graphql.service.d.ts +3 -2
- package/dist/types/services/graphql.service.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/interfaces/graphqlPaginatedResult.interface.ts +7 -3
- package/src/services/graphql.service.ts +26 -12
|
@@ -15,6 +15,8 @@ export interface GraphqlPaginatedResult {
|
|
|
15
15
|
pageInfo?: CursorPageInfo;
|
|
16
16
|
};
|
|
17
17
|
};
|
|
18
|
+
/** when using Infinite Scroll, we'll want to know when we hit the bottom of the scroll to get next subset */
|
|
19
|
+
infiniteScrollBottomHit?: boolean;
|
|
18
20
|
/** Some metrics of the last executed query (startTime, endTime, executionTime, itemCount, totalItemCount) */
|
|
19
21
|
metrics?: Metrics;
|
|
20
22
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphqlPaginatedResult.interface.d.ts","sourceRoot":"","sources":["../../../src/interfaces/graphqlPaginatedResult.interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAE3E,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE;QACJ,CAAC,WAAW,EAAE,MAAM,GAAG;YACrB,iDAAiD;YACjD,KAAK,EAAE,GAAG,EAAE,CAAC;YAEb,4EAA4E;YAC5E,UAAU,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"graphqlPaginatedResult.interface.d.ts","sourceRoot":"","sources":["../../../src/interfaces/graphqlPaginatedResult.interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAE3E,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE;QACJ,CAAC,WAAW,EAAE,MAAM,GAAG;YACrB,iDAAiD;YACjD,KAAK,EAAE,GAAG,EAAE,CAAC;YAEb,4EAA4E;YAC5E,UAAU,EAAE,MAAM,CAAC;YAKnB,8CAA8C;YAC9C,KAAK,CAAC,EAAE;gBACN,8BAA8B;gBAC9B,MAAM,EAAE,MAAM,CAAC;aAChB,CAAC;YAEF,iGAAiG;YACjG,QAAQ,CAAC,EAAE,cAAc,CAAC;SAC3B,CAAC;KACH,CAAC;IAEF,6GAA6G;IAC7G,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAElC,6GAA6G;IAC7G,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BackendService, Column, ColumnFilters, ColumnSort, CurrentFilter, CurrentPagination, CurrentSorter, FilterChangedArgs, GridOption, MultiColumnSort, Pagination, PaginationChangedArgs, PaginationCursorChangedArgs, SharedService, SingleColumnSort, SlickGrid } from '@slickgrid-universal/common';
|
|
2
2
|
import { FieldType } from '@slickgrid-universal/common';
|
|
3
|
-
import type { GraphqlDatasetFilter, GraphqlPaginationOption, GraphqlServiceOption } from '../interfaces/index';
|
|
3
|
+
import type { GraphqlDatasetFilter, GraphqlPaginatedResult, GraphqlPaginationOption, GraphqlServiceOption } from '../interfaces/index';
|
|
4
4
|
export declare class GraphqlService implements BackendService {
|
|
5
5
|
protected _currentFilters: ColumnFilters | CurrentFilter[];
|
|
6
6
|
protected _currentPagination: CurrentPagination | null;
|
|
@@ -22,6 +22,7 @@ export declare class GraphqlService implements BackendService {
|
|
|
22
22
|
* @param serviceOptions GraphqlServiceOption
|
|
23
23
|
*/
|
|
24
24
|
buildQuery(): string;
|
|
25
|
+
postProcess(processResult: GraphqlPaginatedResult): void;
|
|
25
26
|
/**
|
|
26
27
|
* From an input array of strings, we want to build a GraphQL query string.
|
|
27
28
|
* The process has to take the dot notation and parse it into a valid GraphQL query
|
|
@@ -37,7 +38,7 @@ export declare class GraphqlService implements BackendService {
|
|
|
37
38
|
clearFilters(): void;
|
|
38
39
|
clearSorters(): void;
|
|
39
40
|
/**
|
|
40
|
-
* Get
|
|
41
|
+
* Get default initial Pagination options
|
|
41
42
|
* @return Pagination Options
|
|
42
43
|
*/
|
|
43
44
|
getInitPaginationOptions(): GraphqlDatasetFilter;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql.service.d.ts","sourceRoot":"","sources":["../../../src/services/graphql.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,MAAM,EAEN,aAAa,EACb,UAAU,EACV,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,iBAAiB,EACjB,UAAU,
|
|
1
|
+
{"version":3,"file":"graphql.service.d.ts","sourceRoot":"","sources":["../../../src/services/graphql.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,MAAM,EAEN,aAAa,EACb,UAAU,EACV,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,iBAAiB,EACjB,UAAU,EAEV,eAAe,EAEf,UAAU,EACV,qBAAqB,EACrB,2BAA2B,EAC3B,aAAa,EACb,gBAAgB,EAChB,SAAS,EAEV,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,SAAS,EAKV,MAAM,6BAA6B,CAAC;AAGrC,OAAO,KAAK,EAGV,oBAAoB,EAEpB,sBAAsB,EACtB,uBAAuB,EACvB,oBAAoB,EAErB,MAAM,qBAAqB,CAAC;AAO7B,qBAAa,cAAe,YAAW,cAAc;IACnD,SAAS,CAAC,eAAe,EAAE,aAAa,GAAG,aAAa,EAAE,CAAM;IAChE,SAAS,CAAC,kBAAkB,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a grid with a GraphQL backend server",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"types": "./dist/types/index.d.ts",
|
|
@@ -38,12 +38,12 @@
|
|
|
38
38
|
"not dead"
|
|
39
39
|
],
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@slickgrid-universal/common": "~5.
|
|
42
|
-
"@slickgrid-universal/utils": "~5.
|
|
41
|
+
"@slickgrid-universal/common": "~5.5.0",
|
|
42
|
+
"@slickgrid-universal/utils": "~5.5.0"
|
|
43
43
|
},
|
|
44
44
|
"funding": {
|
|
45
45
|
"type": "ko_fi",
|
|
46
46
|
"url": "https://ko-fi.com/ghiscoding"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "bc7ad96ca72c4d7509c160b77a50a2b071028dff"
|
|
49
49
|
}
|
|
@@ -10,18 +10,22 @@ export interface GraphqlPaginatedResult {
|
|
|
10
10
|
totalCount: number;
|
|
11
11
|
|
|
12
12
|
// ---
|
|
13
|
-
// When using a Cursor, we'll also have Edges and PageInfo according to a cursor position
|
|
13
|
+
// When using a Cursor, we'll also have `Edges` and `PageInfo` according to a cursor position
|
|
14
|
+
|
|
14
15
|
/** Edges information of the current cursor */
|
|
15
16
|
edges?: {
|
|
16
17
|
/** Current cursor position */
|
|
17
18
|
cursor: string;
|
|
18
|
-
}
|
|
19
|
+
};
|
|
19
20
|
|
|
20
21
|
/** Page information of the current cursor, do we have a next page and what is the end cursor? */
|
|
21
22
|
pageInfo?: CursorPageInfo;
|
|
22
|
-
}
|
|
23
|
+
};
|
|
23
24
|
};
|
|
24
25
|
|
|
26
|
+
/** when using Infinite Scroll, we'll want to know when we hit the bottom of the scroll to get next subset */
|
|
27
|
+
infiniteScrollBottomHit?: boolean;
|
|
28
|
+
|
|
25
29
|
/** Some metrics of the last executed query (startTime, endTime, executionTime, itemCount, totalItemCount) */
|
|
26
30
|
metrics?: Metrics;
|
|
27
31
|
}
|
|
@@ -9,6 +9,7 @@ import type {
|
|
|
9
9
|
CurrentSorter,
|
|
10
10
|
FilterChangedArgs,
|
|
11
11
|
GridOption,
|
|
12
|
+
InfiniteScrollOption,
|
|
12
13
|
MultiColumnSort,
|
|
13
14
|
OperatorString,
|
|
14
15
|
Pagination,
|
|
@@ -21,7 +22,6 @@ import type {
|
|
|
21
22
|
} from '@slickgrid-universal/common';
|
|
22
23
|
import {
|
|
23
24
|
FieldType,
|
|
24
|
-
// utilities
|
|
25
25
|
mapOperatorType,
|
|
26
26
|
mapOperatorByFieldType,
|
|
27
27
|
OperatorType,
|
|
@@ -34,6 +34,7 @@ import type {
|
|
|
34
34
|
GraphqlCustomFilteringOption,
|
|
35
35
|
GraphqlDatasetFilter,
|
|
36
36
|
GraphqlFilteringOption,
|
|
37
|
+
GraphqlPaginatedResult,
|
|
37
38
|
GraphqlPaginationOption,
|
|
38
39
|
GraphqlServiceOption,
|
|
39
40
|
GraphqlSortingOption,
|
|
@@ -75,7 +76,7 @@ export class GraphqlService implements BackendService {
|
|
|
75
76
|
this.pagination = pagination;
|
|
76
77
|
this._datasetIdPropName = this._gridOptions.datasetIdPropertyName || 'id';
|
|
77
78
|
|
|
78
|
-
if (grid?.getColumns) {
|
|
79
|
+
if (typeof grid?.getColumns === 'function') {
|
|
79
80
|
this._columnDefinitions = sharedService?.allColumns ?? grid.getColumns() ?? [];
|
|
80
81
|
}
|
|
81
82
|
}
|
|
@@ -88,7 +89,6 @@ export class GraphqlService implements BackendService {
|
|
|
88
89
|
if (!this.options || !this.options.datasetName || !Array.isArray(this._columnDefinitions)) {
|
|
89
90
|
throw new Error('GraphQL Service requires the "datasetName" property to properly build the GraphQL query');
|
|
90
91
|
}
|
|
91
|
-
|
|
92
92
|
// get the column definitions and exclude some if they were tagged as excluded
|
|
93
93
|
let columnDefinitions = this._columnDefinitions || [];
|
|
94
94
|
columnDefinitions = columnDefinitions.filter((column: Column) => !column.excludeFromQuery);
|
|
@@ -99,7 +99,7 @@ export class GraphqlService implements BackendService {
|
|
|
99
99
|
|
|
100
100
|
// get all the columnds Ids for the filters to work
|
|
101
101
|
const columnIds: string[] = [];
|
|
102
|
-
if (
|
|
102
|
+
if (Array.isArray(columnDefinitions)) {
|
|
103
103
|
for (const column of columnDefinitions) {
|
|
104
104
|
if (!column.excludeFieldFromQuery) {
|
|
105
105
|
columnIds.push(column.field);
|
|
@@ -121,7 +121,7 @@ export class GraphqlService implements BackendService {
|
|
|
121
121
|
const columnsQuery = this.buildFilterQuery(columnIds);
|
|
122
122
|
let graphqlNodeFields = [];
|
|
123
123
|
|
|
124
|
-
if (this._gridOptions.enablePagination !== false) {
|
|
124
|
+
if (this._gridOptions.enablePagination !== false || this.options.infiniteScroll) {
|
|
125
125
|
if (this.options.useCursor) {
|
|
126
126
|
// ...pageInfo { hasNextPage, endCursor }, edges { cursor, node { _columns_ } }, totalCount: 100
|
|
127
127
|
const edgesQb = new QueryBuilder('edges');
|
|
@@ -146,7 +146,7 @@ export class GraphqlService implements BackendService {
|
|
|
146
146
|
let datasetFilters: GraphqlDatasetFilter = {};
|
|
147
147
|
|
|
148
148
|
// only add pagination if it's enabled in the grid options
|
|
149
|
-
if (this._gridOptions.enablePagination !== false) {
|
|
149
|
+
if (this._gridOptions.enablePagination !== false || this.options.infiniteScroll) {
|
|
150
150
|
datasetFilters = {};
|
|
151
151
|
|
|
152
152
|
if (this.options.useCursor && this.options.paginationOptions) {
|
|
@@ -154,7 +154,10 @@ export class GraphqlService implements BackendService {
|
|
|
154
154
|
}
|
|
155
155
|
else {
|
|
156
156
|
const paginationOptions = this.options?.paginationOptions;
|
|
157
|
-
datasetFilters.first = this.options?.
|
|
157
|
+
datasetFilters.first = (this.options?.infiniteScroll as InfiniteScrollOption)?.fetchSize
|
|
158
|
+
?? this.options?.paginationOptions?.first
|
|
159
|
+
?? this.pagination?.pageSize
|
|
160
|
+
?? this.defaultPaginationOptions.first;
|
|
158
161
|
datasetFilters.offset = paginationOptions?.hasOwnProperty('offset') ? +(paginationOptions as any)['offset'] : 0;
|
|
159
162
|
}
|
|
160
163
|
}
|
|
@@ -187,6 +190,12 @@ export class GraphqlService implements BackendService {
|
|
|
187
190
|
return this.trimDoubleQuotesOnEnumField(queryQb.toString(), enumSearchProperties, this.options.keepArgumentFieldDoubleQuotes || false);
|
|
188
191
|
}
|
|
189
192
|
|
|
193
|
+
postProcess(processResult: GraphqlPaginatedResult): void {
|
|
194
|
+
if (processResult.data && this.pagination) {
|
|
195
|
+
this.pagination.totalItems = processResult.data[this.getDatasetName()]?.totalCount || 0;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
190
199
|
/**
|
|
191
200
|
* From an input array of strings, we want to build a GraphQL query string.
|
|
192
201
|
* The process has to take the dot notation and parse it into a valid GraphQL query
|
|
@@ -225,11 +234,11 @@ export class GraphqlService implements BackendService {
|
|
|
225
234
|
}
|
|
226
235
|
|
|
227
236
|
/**
|
|
228
|
-
* Get
|
|
237
|
+
* Get default initial Pagination options
|
|
229
238
|
* @return Pagination Options
|
|
230
239
|
*/
|
|
231
240
|
getInitPaginationOptions(): GraphqlDatasetFilter {
|
|
232
|
-
const paginationFirst = this.
|
|
241
|
+
const paginationFirst = (this.options?.infiniteScroll as InfiniteScrollOption)?.fetchSize ?? this.pagination?.pageSize ?? DEFAULT_ITEMS_PER_PAGE;
|
|
233
242
|
return this.options?.useCursor
|
|
234
243
|
? { first: paginationFirst }
|
|
235
244
|
: { first: paginationFirst, offset: 0 };
|
|
@@ -276,7 +285,7 @@ export class GraphqlService implements BackendService {
|
|
|
276
285
|
};
|
|
277
286
|
|
|
278
287
|
// unless user specifically set "enablePagination" to False, we'll update pagination options in every other cases
|
|
279
|
-
if (this._gridOptions && (this._gridOptions.enablePagination || !this._gridOptions.hasOwnProperty('enablePagination'))) {
|
|
288
|
+
if (this._gridOptions && (this._gridOptions.enablePagination || !this._gridOptions.hasOwnProperty('enablePagination') || this.options?.infiniteScroll)) {
|
|
280
289
|
this.updateOptions({ paginationOptions });
|
|
281
290
|
}
|
|
282
291
|
}
|
|
@@ -339,7 +348,7 @@ export class GraphqlService implements BackendService {
|
|
|
339
348
|
* }
|
|
340
349
|
*/
|
|
341
350
|
processOnPaginationChanged(_event: Event | undefined, args: PaginationChangedArgs | (PaginationCursorChangedArgs & PaginationChangedArgs)): string {
|
|
342
|
-
const pageSize = +(args.pageSize || ((this.pagination) ? this.pagination.pageSize : DEFAULT_PAGE_SIZE));
|
|
351
|
+
const pageSize = +((this.options?.infiniteScroll as InfiniteScrollOption)?.fetchSize || args.pageSize || ((this.pagination) ? this.pagination.pageSize : DEFAULT_PAGE_SIZE));
|
|
343
352
|
|
|
344
353
|
// if first/last defined on args, then it is a cursor based pagination change
|
|
345
354
|
'first' in args || 'last' in args
|
|
@@ -370,6 +379,11 @@ export class GraphqlService implements BackendService {
|
|
|
370
379
|
// loop through all columns to inspect sorters & set the query
|
|
371
380
|
this.updateSorters(sortColumns);
|
|
372
381
|
|
|
382
|
+
// when using infinite scroll, we need to go back to 1st page
|
|
383
|
+
if (this.options?.infiniteScroll) {
|
|
384
|
+
this.updateOptions({ paginationOptions: { offset: 0 } });
|
|
385
|
+
}
|
|
386
|
+
|
|
373
387
|
// build the GraphQL query which we will use in the WebAPI callback
|
|
374
388
|
return this.buildQuery();
|
|
375
389
|
}
|
|
@@ -571,7 +585,7 @@ export class GraphqlService implements BackendService {
|
|
|
571
585
|
// use offset based pagination
|
|
572
586
|
paginationOptions = {
|
|
573
587
|
first: pageSize,
|
|
574
|
-
offset: (newPage > 1) ? ((newPage - 1) * pageSize
|
|
588
|
+
offset: (newPage > 1) ? ((newPage - 1) * pageSize) : 0 // recalculate offset but make sure the result is always over 0
|
|
575
589
|
};
|
|
576
590
|
}
|
|
577
591
|
|