@slickgrid-universal/graphql 4.0.3 → 4.2.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/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -5
- package/src/index.ts +3 -0
- package/src/interfaces/graphqlCursorPaginationOption.interface.ts +13 -0
- package/src/interfaces/graphqlDatasetFilter.interface.ts +13 -0
- package/src/interfaces/graphqlFilteringOption.interface.ts +12 -0
- package/src/interfaces/graphqlPaginatedResult.interface.ts +27 -0
- package/src/interfaces/graphqlPaginationOption.interface.ts +5 -0
- package/src/interfaces/graphqlResult.interface.ts +10 -0
- package/src/interfaces/graphqlServiceApi.interface.ts +29 -0
- package/src/interfaces/graphqlServiceOption.interface.ts +52 -0
- package/src/interfaces/graphqlSortingOption.interface.ts +6 -0
- package/src/interfaces/index.ts +10 -0
- package/src/interfaces/queryArgument.interface.ts +4 -0
- package/src/services/graphql.service.ts +716 -0
- package/src/services/graphqlQueryBuilder.ts +143 -0
- package/src/services/index.ts +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slickgrid-universal/graphql",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "GraphQL Service to sync a grid with a GraphQL backend server",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
"access": "public"
|
|
26
26
|
},
|
|
27
27
|
"files": [
|
|
28
|
-
"/dist"
|
|
28
|
+
"/dist",
|
|
29
|
+
"/src"
|
|
29
30
|
],
|
|
30
31
|
"license": "MIT",
|
|
31
32
|
"author": "Ghislain B.",
|
|
@@ -44,12 +45,12 @@
|
|
|
44
45
|
"not dead"
|
|
45
46
|
],
|
|
46
47
|
"dependencies": {
|
|
47
|
-
"@slickgrid-universal/common": "~4.0
|
|
48
|
-
"@slickgrid-universal/utils": "~4.0
|
|
48
|
+
"@slickgrid-universal/common": "~4.2.0",
|
|
49
|
+
"@slickgrid-universal/utils": "~4.2.0"
|
|
49
50
|
},
|
|
50
51
|
"funding": {
|
|
51
52
|
"type": "ko_fi",
|
|
52
53
|
"url": "https://ko-fi.com/ghiscoding"
|
|
53
54
|
},
|
|
54
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "d97d211a6c2d7d2f3ad65a3d5f19b27584e5ae8c"
|
|
55
56
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface GraphqlCursorPaginationOption {
|
|
2
|
+
/** Start our page After cursor X */
|
|
3
|
+
after?: string;
|
|
4
|
+
|
|
5
|
+
/** Start our page Before cursor X */
|
|
6
|
+
before?: string;
|
|
7
|
+
|
|
8
|
+
/** Get first X number of objects */
|
|
9
|
+
first?: number;
|
|
10
|
+
|
|
11
|
+
/** Get last X number of objects */
|
|
12
|
+
last?: number;
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { GraphqlFilteringOption } from './graphqlFilteringOption.interface';
|
|
2
|
+
import type { GraphqlSortingOption } from './graphqlSortingOption.interface';
|
|
3
|
+
|
|
4
|
+
export interface GraphqlDatasetFilter {
|
|
5
|
+
first?: number;
|
|
6
|
+
last?: number;
|
|
7
|
+
offset?: number;
|
|
8
|
+
after?: string;
|
|
9
|
+
before?: string;
|
|
10
|
+
locale?: string;
|
|
11
|
+
filterBy?: GraphqlFilteringOption[];
|
|
12
|
+
orderBy?: GraphqlSortingOption[];
|
|
13
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { OperatorString, OperatorType } from '@slickgrid-universal/common';
|
|
2
|
+
|
|
3
|
+
export interface GraphqlFilteringOption {
|
|
4
|
+
/** Field name to use when filtering */
|
|
5
|
+
field: string;
|
|
6
|
+
|
|
7
|
+
/** Operator to use when filtering */
|
|
8
|
+
operator: OperatorType | OperatorString;
|
|
9
|
+
|
|
10
|
+
/** Value to use when filtering */
|
|
11
|
+
value: any | any[];
|
|
12
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Metrics, CursorPageInfo } from '@slickgrid-universal/common';
|
|
2
|
+
|
|
3
|
+
export interface GraphqlPaginatedResult {
|
|
4
|
+
data: {
|
|
5
|
+
[datasetName: string]: {
|
|
6
|
+
/** result set of data objects (array of data) */
|
|
7
|
+
nodes: any[];
|
|
8
|
+
|
|
9
|
+
/** Total count of items in the table (needed for the Pagination to work) */
|
|
10
|
+
totalCount: number;
|
|
11
|
+
|
|
12
|
+
// ---
|
|
13
|
+
// When using a Cursor, we'll also have Edges and PageInfo according to a cursor position
|
|
14
|
+
/** Edges information of the current cursor */
|
|
15
|
+
edges?: {
|
|
16
|
+
/** Current cursor position */
|
|
17
|
+
cursor: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Page information of the current cursor, do we have a next page and what is the end cursor? */
|
|
21
|
+
pageInfo?: CursorPageInfo;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/** Some metrics of the last executed query (startTime, endTime, executionTime, itemCount, totalItemCount) */
|
|
26
|
+
metrics?: Metrics;
|
|
27
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Metrics } from '@slickgrid-universal/common';
|
|
2
|
+
|
|
3
|
+
export interface GraphqlResult<T = any> {
|
|
4
|
+
data: {
|
|
5
|
+
[datasetName: string]: T[];
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
/** Some metrics of the last executed query (startTime, endTime, executionTime, itemCount, totalItemCount) */
|
|
9
|
+
metrics?: Metrics;
|
|
10
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { BackendServiceApi, Observable } from '@slickgrid-universal/common';
|
|
2
|
+
|
|
3
|
+
import type { GraphqlResult } from './graphqlResult.interface';
|
|
4
|
+
import type { GraphqlPaginatedResult } from './graphqlPaginatedResult.interface';
|
|
5
|
+
import type { GraphqlServiceOption } from './graphqlServiceOption.interface';
|
|
6
|
+
import type { GraphqlService } from '../services/index';
|
|
7
|
+
|
|
8
|
+
export interface GraphqlServiceApi extends BackendServiceApi {
|
|
9
|
+
/** Backend Service Options */
|
|
10
|
+
options: GraphqlServiceOption;
|
|
11
|
+
|
|
12
|
+
/** Backend Service instance (could be OData or GraphQL Service) */
|
|
13
|
+
service: GraphqlService;
|
|
14
|
+
|
|
15
|
+
/** On init (or on page load), what action to perform? */
|
|
16
|
+
onInit?: (query: string) => Promise<GraphqlResult | GraphqlPaginatedResult> | Observable<GraphqlResult | GraphqlPaginatedResult>;
|
|
17
|
+
|
|
18
|
+
/** On Processing, we get the query back from the service, and we need to provide a Promise/Observable. For example: this.http.get(myGraphqlUrl) */
|
|
19
|
+
process: (query: string) => Promise<GraphqlResult | GraphqlPaginatedResult> | Observable<GraphqlResult | GraphqlPaginatedResult>;
|
|
20
|
+
|
|
21
|
+
/** After executing the query, what action to perform? For example, stop the spinner */
|
|
22
|
+
postProcess?: (response: GraphqlResult | GraphqlPaginatedResult) => void;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* INTERNAL USAGE ONLY by Slickgrid-Universal
|
|
26
|
+
* This internal process will be run just before postProcess and is meant to refresh the Dataset & Pagination after a GraphQL call
|
|
27
|
+
*/
|
|
28
|
+
internalPostProcess?: (result: GraphqlResult | GraphqlPaginatedResult) => void;
|
|
29
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { BackendServiceOption } from '@slickgrid-universal/common';
|
|
2
|
+
|
|
3
|
+
import type { GraphqlFilteringOption } from './graphqlFilteringOption.interface';
|
|
4
|
+
import type { GraphqlSortingOption } from './graphqlSortingOption.interface';
|
|
5
|
+
import type { GraphqlCursorPaginationOption } from './graphqlCursorPaginationOption.interface';
|
|
6
|
+
import type { GraphqlPaginationOption } from './graphqlPaginationOption.interface';
|
|
7
|
+
import type { QueryArgument } from './queryArgument.interface';
|
|
8
|
+
|
|
9
|
+
export interface GraphqlServiceOption extends BackendServiceOption {
|
|
10
|
+
/**
|
|
11
|
+
* When using Translation, we probably want to add locale as a query parameter for the filterBy/orderBy to work
|
|
12
|
+
* ex.: users(first: 10, offset: 0, locale: "en-CA", filterBy: [{field: name, operator: EQ, value:"John"}]) { }
|
|
13
|
+
*/
|
|
14
|
+
addLocaleIntoQuery?: boolean;
|
|
15
|
+
|
|
16
|
+
/** What is the dataset, this is required for the GraphQL query to be built */
|
|
17
|
+
datasetName: string;
|
|
18
|
+
|
|
19
|
+
/** Used for defining the operation name when building the GraphQL query */
|
|
20
|
+
operationName?: string;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Extra query arguments that be passed in addition to the default query arguments
|
|
24
|
+
* For example in GraphQL, if we want to pass "userId" and we want the query to look like
|
|
25
|
+
* users (first: 20, offset: 10, userId: 123) { ... }
|
|
26
|
+
*/
|
|
27
|
+
extraQueryArguments?: QueryArgument[];
|
|
28
|
+
|
|
29
|
+
/** array of Filtering Options, ex.: { field: name, operator: EQ, value: "John" } */
|
|
30
|
+
filteringOptions?: GraphqlFilteringOption[];
|
|
31
|
+
|
|
32
|
+
/** What are the pagination options? ex.: (first, last, offset) */
|
|
33
|
+
paginationOptions?: GraphqlPaginationOption | GraphqlCursorPaginationOption;
|
|
34
|
+
|
|
35
|
+
/** array of Filtering Options, ex.: { field: name, direction: DESC } */
|
|
36
|
+
sortingOptions?: GraphqlSortingOption[];
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Do we want to keep double quotes on field arguments of filterBy/sortBy (field: "name" instead of field: name)
|
|
40
|
+
* ex.: { field: "name", operator: EQ, value: "John" }
|
|
41
|
+
*/
|
|
42
|
+
keepArgumentFieldDoubleQuotes?: boolean;
|
|
43
|
+
|
|
44
|
+
/** Use Pagination Cursor in the GraphQL Server */
|
|
45
|
+
useCursor?: boolean;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* When false, searchTerms may be manipulated to be functional with certain filters eg: string only filters.
|
|
49
|
+
* When true, JSON.stringify is used on the searchTerms and used in the query "as-is". It is then the responsibility of the developer to sanitise the `searchTerms` property if necessary.
|
|
50
|
+
*/
|
|
51
|
+
useVerbatimSearchTerms?: boolean;
|
|
52
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './graphqlCursorPaginationOption.interface';
|
|
2
|
+
export * from './graphqlDatasetFilter.interface';
|
|
3
|
+
export * from './graphqlFilteringOption.interface';
|
|
4
|
+
export * from './graphqlPaginatedResult.interface';
|
|
5
|
+
export * from './graphqlPaginationOption.interface';
|
|
6
|
+
export * from './graphqlResult.interface';
|
|
7
|
+
export * from './graphqlServiceApi.interface';
|
|
8
|
+
export * from './graphqlServiceOption.interface';
|
|
9
|
+
export * from './graphqlSortingOption.interface';
|
|
10
|
+
export * from './queryArgument.interface';
|