@enonic-types/guillotine 0.0.2 → 7.1.0-B1
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/README.md +3 -1
- package/extensions/Resolvers.d.ts +11 -9
- package/graphQL/CreateDataFetcherResult.d.ts +38 -7
- package/graphQL/LocalContext.d.ts +12 -2
- package/graphQL/index.d.ts +5 -1
- package/index.ts +22 -35
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -6,20 +6,22 @@ import type {LocalContext} from '../graphQL/LocalContext'
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
export declare interface DataFetchingEnvironment<
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
ARGS extends Record<string, any> = Record<string, any>,
|
|
10
|
+
LOCAL_CONTEXT extends LocalContextRecord = LocalContextRecord,
|
|
11
|
+
SOURCE extends unknown = unknown,
|
|
11
12
|
> {
|
|
12
|
-
args:
|
|
13
|
-
localContext: LocalContext
|
|
14
|
-
source:
|
|
13
|
+
args: ARGS
|
|
14
|
+
localContext: LocalContext<LOCAL_CONTEXT>
|
|
15
|
+
source: SOURCE
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
export declare interface Resolver<
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
ARGS extends Record<string, any> = Record<string, any>,
|
|
20
|
+
LOCAL_CONTEXT extends LocalContextRecord = LocalContextRecord,
|
|
21
|
+
SOURCE extends unknown = unknown,
|
|
22
|
+
RETURN_TYPE = any
|
|
21
23
|
> {
|
|
22
|
-
(env: DataFetchingEnvironment<
|
|
24
|
+
(env: DataFetchingEnvironment<ARGS,LOCAL_CONTEXT,SOURCE>): RETURN_TYPE
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
export declare type Resolvers = PartialRecord<
|
|
@@ -8,16 +8,47 @@ import type {
|
|
|
8
8
|
} from './LocalContext'
|
|
9
9
|
|
|
10
10
|
|
|
11
|
+
// https://developer.enonic.com/docs/guillotine/stable/extending/resolvers#createdatafetcherresult
|
|
12
|
+
//
|
|
13
|
+
// If parentLocalContext is not provided, then localContext will override
|
|
14
|
+
// parentLocalContext.
|
|
15
|
+
//
|
|
16
|
+
// Otherwise, localContext will be merged with parentLocalContext and
|
|
17
|
+
// localContext will override parentLocalContext if they have the same keys.
|
|
18
|
+
//
|
|
19
|
+
// If localContext is not provided, then parentLocalContext will be used as
|
|
20
|
+
// localContext.
|
|
21
|
+
|
|
22
|
+
|
|
11
23
|
export declare interface CreateDataFetcherResultParams<
|
|
12
|
-
|
|
13
|
-
|
|
24
|
+
DATA extends any,
|
|
25
|
+
LOCAL_CONTEXT extends LocalContextRecord = LocalContext,
|
|
26
|
+
PARENT_LOCAL_CONTEXT extends LocalContextRecord = LocalContext
|
|
14
27
|
> {
|
|
15
28
|
data: ScriptValue // NOTE: ScriptValue type is expected to exist in global scope
|
|
16
|
-
localContext?: LocalContext<
|
|
17
|
-
parentLocalContext?: LocalContext<
|
|
29
|
+
localContext?: LocalContext<LOCAL_CONTEXT>
|
|
30
|
+
parentLocalContext?: LocalContext<PARENT_LOCAL_CONTEXT>
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// NOTE: Same as DataFetchingEnvironment without args.
|
|
34
|
+
export interface DataFetcherResult<
|
|
35
|
+
DATA extends any,
|
|
36
|
+
LOCAL_CONTEXT extends LocalContextRecord = LocalContext
|
|
37
|
+
> {
|
|
38
|
+
// args, // Depends on the field resolver
|
|
39
|
+
localContext: LocalContext<LOCAL_CONTEXT>
|
|
40
|
+
source: DATA,
|
|
18
41
|
}
|
|
19
42
|
|
|
20
43
|
export declare type CreateDataFetcherResult = <
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
44
|
+
DATA extends any,
|
|
45
|
+
LOCAL_CONTEXT extends LocalContextRecord = LocalContext,
|
|
46
|
+
PARENT_LOCAL_CONTEXT extends LocalContextRecord = LocalContext
|
|
47
|
+
>(params: CreateDataFetcherResultParams<
|
|
48
|
+
DATA,
|
|
49
|
+
LOCAL_CONTEXT,
|
|
50
|
+
PARENT_LOCAL_CONTEXT,
|
|
51
|
+
>) => DataFetcherResult<
|
|
52
|
+
DATA,
|
|
53
|
+
LocalContext<PARENT_LOCAL_CONTEXT & LOCAL_CONTEXT>
|
|
54
|
+
>
|
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
export declare type LocalContextRecord = Record<string,string|number|boolean|null>
|
|
2
2
|
|
|
3
|
+
|
|
4
|
+
// The documentation:
|
|
5
|
+
// https://developer.enonic.com/docs/guillotine/stable/extending/resolvers
|
|
6
|
+
//
|
|
7
|
+
// Says:
|
|
8
|
+
// If parentLocalContext is not provided, then localContext will override
|
|
9
|
+
// parentLocalContext.
|
|
10
|
+
//
|
|
11
|
+
// This means that is possible to remove branch, project and siteKey in some
|
|
12
|
+
// parent createDataFetcherResult. Which is why the Partial<> is used.
|
|
3
13
|
export declare type LocalContext<
|
|
4
14
|
T extends LocalContextRecord = LocalContextRecord
|
|
5
|
-
> = {
|
|
15
|
+
> = Partial<{
|
|
6
16
|
branch: string
|
|
7
17
|
project: string
|
|
8
18
|
siteKey?: string
|
|
9
|
-
} & T
|
|
19
|
+
}> & T
|
package/graphQL/index.d.ts
CHANGED
|
@@ -12,7 +12,11 @@ import type {
|
|
|
12
12
|
PartialRecord,
|
|
13
13
|
ValueOf,
|
|
14
14
|
} from '../Utils'
|
|
15
|
-
import type {
|
|
15
|
+
import type {
|
|
16
|
+
CreateDataFetcherResult,
|
|
17
|
+
CreateDataFetcherResultParams,
|
|
18
|
+
DataFetcherResult,
|
|
19
|
+
} from './CreateDataFetcherResult'
|
|
16
20
|
import type {
|
|
17
21
|
GraphQLEnumType,
|
|
18
22
|
GraphQLEnumTypeName,
|
package/index.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// Make sure ScriptValue type exists in global scope:
|
|
2
2
|
/// <reference types="@enonic-types/global"/>
|
|
3
3
|
|
|
4
|
+
import type {CreateDataFetcherResult} from './graphQL/CreateDataFetcherResult'
|
|
5
|
+
import type {Resolver} from './extensions/Resolvers'
|
|
4
6
|
|
|
5
7
|
declare const __name: unique symbol
|
|
6
8
|
|
|
@@ -11,6 +13,25 @@ declare type BrandGraphQLScalarType<
|
|
|
11
13
|
[__name]: GQL_SCALAR_TYPE_NAME
|
|
12
14
|
}
|
|
13
15
|
|
|
16
|
+
|
|
17
|
+
export type {
|
|
18
|
+
CreateDataFetcherResult,
|
|
19
|
+
CreateDataFetcherResultParams,
|
|
20
|
+
DataFetcherResult,
|
|
21
|
+
} from './graphQL/CreateDataFetcherResult'
|
|
22
|
+
|
|
23
|
+
export type {
|
|
24
|
+
LocalContext,
|
|
25
|
+
LocalContextRecord,
|
|
26
|
+
} from './graphQL/LocalContext'
|
|
27
|
+
|
|
28
|
+
export type {
|
|
29
|
+
DataFetchingEnvironment,
|
|
30
|
+
Resolver,
|
|
31
|
+
// Resolvers, // NOTE: This is not exported because it the advanced version of Resolvers
|
|
32
|
+
} from './extensions/Resolvers'
|
|
33
|
+
|
|
34
|
+
|
|
14
35
|
export declare type GraphQLBoolean = BrandGraphQLScalarType<'GraphQLBoolean', boolean>
|
|
15
36
|
export declare type GraphQLDate = BrandGraphQLScalarType<'Date', string>
|
|
16
37
|
export declare type GraphQLDateTime = BrandGraphQLScalarType<'DateTime', string>
|
|
@@ -35,14 +56,7 @@ export declare interface GraphQL {
|
|
|
35
56
|
Json: GraphQLJson
|
|
36
57
|
LocalDateTime: GraphQLLocalDateTime
|
|
37
58
|
LocalTime: GraphQLLocalTime
|
|
38
|
-
createDataFetcherResult:
|
|
39
|
-
In extends LocalContextRecord = LocalContext,
|
|
40
|
-
Out extends LocalContextRecord = LocalContext
|
|
41
|
-
> () => {
|
|
42
|
-
data: ScriptValue // NOTE: ScriptValue type is expected to exist in global scope
|
|
43
|
-
localContext?: LocalContext<Out>
|
|
44
|
-
parentLocalContext?: LocalContext<In>
|
|
45
|
-
}
|
|
59
|
+
createDataFetcherResult: CreateDataFetcherResult
|
|
46
60
|
nonNull: (type: GraphQLType) => GraphQLType
|
|
47
61
|
list: (type: GraphQLType) => GraphQLType[]
|
|
48
62
|
reference: (typeName: string) => GraphQLType
|
|
@@ -71,33 +85,6 @@ export declare interface Enum {
|
|
|
71
85
|
values: Record<string, string>
|
|
72
86
|
}
|
|
73
87
|
|
|
74
|
-
export declare type LocalContextRecord = Record<string,string|number|boolean|null>
|
|
75
|
-
|
|
76
|
-
export declare type LocalContext<
|
|
77
|
-
T extends LocalContextRecord = LocalContextRecord
|
|
78
|
-
> = {
|
|
79
|
-
branch: string
|
|
80
|
-
project: string
|
|
81
|
-
siteKey?: string
|
|
82
|
-
} & T
|
|
83
|
-
|
|
84
|
-
export declare interface DataFetchingEnvironment<
|
|
85
|
-
Args extends Record<string, any> = Record<string, any>,
|
|
86
|
-
Source extends unknown = unknown,
|
|
87
|
-
> {
|
|
88
|
-
args: Args
|
|
89
|
-
localContext: LocalContext
|
|
90
|
-
source: Source
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export declare interface Resolver<
|
|
94
|
-
Args extends Record<string, any> = Record<string, any>,
|
|
95
|
-
Source extends unknown = unknown,
|
|
96
|
-
Return = any
|
|
97
|
-
> {
|
|
98
|
-
(env: DataFetchingEnvironment<Args,Source>): Return
|
|
99
|
-
}
|
|
100
|
-
|
|
101
88
|
export declare interface Extensions {
|
|
102
89
|
creationCallbacks?: Record<string, CreationCallback>
|
|
103
90
|
enums?: Record<
|