@@ -2,7 +2,7 @@ import type { FieldSelection as BuilderFieldSelection, BuilderOperation, Variabl
2
2
import { Call , Var , compileWithVariableValues } from "tiny-graphql-query-compiler" ;
3
3
import type { FieldSelection } from "./FieldSelection.js" ;
4
4
import { filterTypeName , sortTypeName } from "./support.js" ;
5
- import type { FindManyOptions , SelectionOptions , VariablesOptions } from "./types.js" ;
5
+ import type { BaseFindOptions , FindManyOptions , VariablesOptions } from "./types.js" ;
6
6
7
7
const hydrationOptions = ( modelApiIdentifier : string ) : BuilderFieldSelection => {
8
8
return {
@@ -23,12 +23,17 @@ const fieldSelectionToQueryCompilerFields = (selection: FieldSelection, includeT
23
23
24
24
export type FindFirstPaginationOptions = Omit < FindManyOptions , "first" | "last" | "before" | "after" > ;
25
25
26
+ const directivesForOptions = ( options ?: BaseFindOptions | null ) => {
27
+ if ( options ?. live ) return [ "@live" ] ;
28
+ return undefined ;
29
+ } ;
30
+
26
31
export const findOneOperation = (
27
32
operation : string ,
28
33
id : string | undefined ,
29
34
defaultSelection : FieldSelection ,
30
35
modelApiIdentifier : string ,
31
- options ?: SelectionOptions | null
36
+ options ?: BaseFindOptions | null
32
37
) => {
33
38
const variables : Record < string , Variable > = { } ;
34
39
if ( typeof id !== "undefined" ) variables . id = Var ( { type : "GadgetID!" , value : id } ) ;
@@ -39,6 +44,7 @@ export const findOneOperation = (
39
44
[ operation ] : Call ( variables , fieldSelectionToQueryCompilerFields ( options ?. select || defaultSelection , true ) ) ,
40
45
...hydrationOptions ( modelApiIdentifier ) ,
41
46
} ,
47
+ directives : directivesForOptions ( options ) ,
42
48
} ) ;
43
49
} ;
44
50
@@ -48,10 +54,10 @@ export const findOneByFieldOperation = (
48
54
fieldValue : string ,
49
55
defaultSelection : FieldSelection ,
50
56
modelApiIdentifier : string ,
51
- options ?: SelectionOptions | null
57
+ options ?: BaseFindOptions | null
52
58
) => {
53
59
return findManyOperation ( operation , defaultSelection , modelApiIdentifier , {
54
- select : options ?. select ,
60
+ ... options ,
55
61
first : 2 ,
56
62
filter : {
57
63
[ fieldName ] : {
@@ -91,6 +97,7 @@ export const findManyOperation = (
91
97
) ,
92
98
...hydrationOptions ( modelApiIdentifier ) ,
93
99
} ,
100
+ directives : directivesForOptions ( options ) ,
94
101
} ) ;
95
102
} ;
96
103
@@ -115,7 +122,7 @@ export const actionOperation = (
115
122
modelApiIdentifier : string ,
116
123
modelSelectionField : string ,
117
124
variables : VariablesOptions ,
118
- options ?: SelectionOptions | null ,
125
+ options ?: BaseFindOptions | null ,
119
126
namespace ?: string | null ,
120
127
isBulkAction ?: boolean | null ,
121
128
hasReturnType ?: boolean | null
@@ -144,12 +151,18 @@ export const actionOperation = (
144
151
...fields ,
145
152
...hydrationOptions ( modelApiIdentifier ) ,
146
153
} ,
154
+ directives : directivesForOptions ( options ) ,
147
155
} ;
148
156
149
157
return compileWithVariableValues ( actionOperation ) ;
150
158
} ;
151
159
152
- export const globalActionOperation = ( operation : string , variables : VariablesOptions , namespace ?: string | null ) => {
160
+ export const globalActionOperation = (
161
+ operation : string ,
162
+ variables : VariablesOptions ,
163
+ namespace ?: string | null ,
164
+ options ?: { live ?: boolean }
165
+ ) => {
153
166
let fields : BuilderFieldSelection = {
154
167
[ operation ] : Call ( variableOptionsToVariables ( variables ) , {
155
168
success : true ,
@@ -170,5 +183,6 @@ export const globalActionOperation = (operation: string, variables: VariablesOpt
170
183
type : "mutation" ,
171
184
name : operation ,
172
185
fields,
186
+ directives : directivesForOptions ( options ) ,
173
187
} ) ;
174
188
} ;
0 commit comments