|
1 | 1 | importtype{ExecutionResult}from'graphql'
|
2 | 2 | import{typeDocumentNode,execute,graphql,typeGraphQLSchema}from'graphql'
|
3 |
| -importtype{MergeExclusive,NonEmptyObject}from'type-fest' |
4 | 3 | importtype{ExcludeUndefined}from'type-fest/source/required-deep.js'
|
5 | 4 | importrequestfrom'../entrypoints/main.js'
|
6 |
| -importtype{RootTypeName}from'../lib/graphql.js' |
7 |
| -importtype{Exact,IsMultipleKeys}from'../lib/prelude.js' |
8 |
| -importtype{TSError}from'../lib/TSError.js' |
9 |
| -importtype{InputFieldsAllNullable,Object$2}from'../Schema/__.js' |
| 5 | +importtype{RootTypeName,Variables}from'../lib/graphql.js' |
| 6 | +importtype{Object$2}from'../Schema/__.js' |
10 | 7 | import{Schema}from'../Schema/__.js'
|
11 | 8 | import{readMaybeThunk}from'../Schema/core/helpers.js'
|
| 9 | +importtype{ApplyInputDefaults,OptionsInputDefaults,ReturnModeType}from'./Config.js' |
12 | 10 | import*asCustomScalarsfrom'./customScalars.js'
|
| 11 | +importtype{DocumentFn}from'./document.js' |
13 | 12 | import{toDocumentExpression}from'./document.js'
|
14 |
| -importtype{ResultSet}from'./ResultSet/__.js' |
| 13 | +importtype{GetRootTypeMethods}from'./RootTypeMethods.js' |
15 | 14 | import{SelectionSet}from'./SelectionSet/__.js'
|
16 | 15 | importtype{DocumentObject,GraphQLObjectSelection}from'./SelectionSet/toGraphQLDocumentString.js'
|
17 | 16 |
|
18 |
| -typeVariables=Record<string,string|number|boolean|null>// todo or any custom scalars too |
19 |
| - |
20 |
| -typeRootTypeFieldContext={ |
21 |
| -Config:Config |
22 |
| -Index:Schema.Index |
23 |
| -RootTypeName:Schema.RootTypeName |
24 |
| -RootTypeFieldName:string |
25 |
| -Field:Schema.SomeField |
26 |
| -} |
27 |
| - |
28 |
| -// dprint-ignore |
29 |
| -typeRootTypeMethods<$ConfigextendsOptionsInputDefaults,$IndexextendsSchema.Index,$RootTypeNameextendsSchema.RootTypeName>= |
30 |
| -$Index['Root'][$RootTypeName]extendsSchema.Object$2 ? |
31 |
| -( |
32 |
| -&{ |
33 |
| -$batch:RootMethod<$Config,$Index,$RootTypeName> |
34 |
| -} |
35 |
| -&{ |
36 |
| -[$RootTypeFieldNameinkeyof$Index['Root'][$RootTypeName]['fields']&string]: |
37 |
| -RootTypeFieldMethod<{ |
38 |
| -Config:$Config, |
39 |
| -Index:$Index, |
40 |
| -RootTypeName:$RootTypeName, |
41 |
| -RootTypeFieldName:$RootTypeFieldName |
42 |
| -Field:$Index['Root'][$RootTypeName]['fields'][$RootTypeFieldName] |
43 |
| -}> |
44 |
| -} |
45 |
| -) |
46 |
| - :TSError<'RootTypeMethods', `Your schema does not have the root type "${$RootTypeName}".`> |
47 |
| - |
48 |
| -// dprint-ignore |
49 |
| -typeRootMethod<$ConfigextendsConfig,$IndexextendsSchema.Index,$RootTypeNameextendsSchema.RootTypeName>= |
50 |
| -<$SelectionSetextendsobject>(selectionSet:Exact<$SelectionSet,SelectionSet.Root<$Index,$RootTypeName>>)=> |
51 |
| -Promise<ReturnMode<$Config,ResultSet.Root<$SelectionSet,$Index,$RootTypeName>>> |
52 |
| - |
53 |
| -// dprint-ignore |
54 |
| -// type RootTypeFieldMethod<$Config extends OptionsInputDefaults, $Index extends Schema.Index, $RootTypeName extends Schema.RootTypeName, $RootTypeFieldName extends string> = |
55 |
| -typeRootTypeFieldMethod<$ContextextendsRootTypeFieldContext>= |
56 |
| -RootTypeFieldMethod_<$Context,$Context['Field']['type']> |
57 |
| - |
58 |
| -// dprint-ignore |
59 |
| -typeRootTypeFieldMethod_<$ContextextendsRootTypeFieldContext,$TypeextendsSchema.Output.Any>= |
60 |
| -$TypeextendsSchema.Output.Nullable<infer$InnerType> ?RootTypeFieldMethod_<$Context,$InnerType> : |
61 |
| -$TypeextendsSchema.Output.List<infer$InnerType> ?RootTypeFieldMethod_<$Context,$InnerType> : |
62 |
| -$TypeextendsSchema.Scalar.Any ?ScalarFieldMethod<$Context> : |
63 |
| -// todo test this case |
64 |
| -$TypeextendsSchema.__typename ?ScalarFieldMethod<$Context> : |
65 |
| -ObjectLikeFieldMethod<$Context> |
66 |
| - |
67 |
| -// dprint-ignore |
68 |
| -typeObjectLikeFieldMethod<$ContextextendsRootTypeFieldContext>= |
69 |
| -<$SelectionSet>(selectionSet:Exact<$SelectionSet,SelectionSet.Field<$Context['Field'],$Context['Index'],{hideDirectives:true}>>)=> |
70 |
| -Promise<ReturnModeForFieldMethod<$Context,ResultSet.Field<$SelectionSet,$Context['Field'],$Context['Index']>>> |
71 |
| - |
72 |
| -// dprint-ignore |
73 |
| -typeScalarFieldMethod<$ContextextendsRootTypeFieldContext>= |
74 |
| -$Context['Field']['args']extendsSchema.Args<infer$Fields> ?InputFieldsAllNullable<$Fields>extendstrue ?<$SelectionSet>(args?:Exact<$SelectionSet,SelectionSet.Args<$Context['Field']['args']>>)=>Promise<ReturnModeForFieldMethod<$Context,ResultSet.Field<$SelectionSet,$Context['Field'],$Context['Index']>>> : |
75 |
| -<$SelectionSet>(args:Exact<$SelectionSet,SelectionSet.Args<$Context['Field']['args']>>)=>Promise<ReturnModeForFieldMethod<$Context,ResultSet.Field<$SelectionSet,$Context['Field'],$Context['Index']>>> : |
76 |
| -(()=>Promise<ReturnModeForFieldMethod<$Context,ResultSet.Field<true,$Context['Field'],$Context['Index']>>>) |
77 |
| -// dprint-ignore |
78 |
| -typeReturnModeForFieldMethod<$ContextextendsRootTypeFieldContext,$Data>= |
79 |
| -$Context['Config']['returnMode']extends'data' |
80 |
| - ?$Data |
81 |
| - :ExecutionResult<{[kin$Context['RootTypeFieldName']] :$Data}> |
82 |
| - |
83 |
| -// dprint-ignore |
84 |
| -typeDocument<$IndexextendsSchema.Index>= |
85 |
| -{ |
86 |
| -[name:string]: |
87 |
| -$Index['Root']['Query']extendsnull ?{mutation:SelectionSet.Root<$Index,'Mutation'>} : |
88 |
| -$Index['Root']['Mutation']extendsnull ?{query:SelectionSet.Root<$Index,'Query'>} : |
89 |
| -MergeExclusive< |
90 |
| -{ |
91 |
| -query:SelectionSet.Root<$Index,'Query'> |
92 |
| -}, |
93 |
| -{ |
94 |
| -mutation:SelectionSet.Root<$Index,'Mutation'> |
95 |
| -} |
96 |
| -> |
97 |
| -} |
98 |
| - |
99 |
| -// dprint-ignore |
100 |
| -typeGetOperation<Textends{query:any}|{mutation:any}>= |
101 |
| -Textends{query:inferU} ?U : |
102 |
| -Textends{mutation:inferU} ?U : |
103 |
| -never |
104 |
| - |
105 |
| -// dprint-ignore |
106 |
| -typeValidateDocumentOperationNames<$Document>= |
107 |
| -// This initial condition checks that the document is not already in an error state. |
108 |
| -// Namely from for example { x: { mutation: { ... }}} where the schema has no mutations. |
109 |
| -// Which is statically caught by the `Document` type. In that case the document type variable |
110 |
| -// no longer functions per normal with regards to keyof utility, not returning exact keys of the object |
111 |
| -// but instead this more general union. Not totally clear _why_, but we have tests covering this... |
112 |
| -string|numberextendskeyof$Document |
113 |
| - ?$Document |
114 |
| - :keyof{[Kinkeyof$Document&stringasSchema.Named.NameParse<K>extendsnever ?K :never]:K}extendsnever |
115 |
| - ?$Document |
116 |
| - :TSError<'ValidateDocumentOperationNames', `One or more Invalid operation name in document: ${keyof{[Kinkeyof$Document&stringasSchema.Named.NameParse<K>extendsnever ?K :never]:K}}`> |
117 |
| - |
118 |
| -// todo: dataAndErrors | dataAndSchemaErrors |
119 |
| -typeReturnModeType='graphql'|'data' |
120 |
| - |
121 |
| -typeOptionsInput={ |
122 |
| -returnMode:ReturnModeType|undefined |
123 |
| -} |
124 |
| - |
125 |
| -typeOptionsInputDefaults={ |
126 |
| -returnMode:'data' |
127 |
| -} |
128 |
| - |
129 |
| -typeConfig={ |
130 |
| -returnMode:ReturnModeType |
131 |
| -} |
132 |
| - |
133 |
| -typeApplyInputDefaults<InputextendsOptionsInput>={ |
134 |
| -[KeyinkeyofOptionsInputDefaults]:undefinedextendsInput[Key] ?OptionsInputDefaults[Key] :Input[Key] |
135 |
| -} |
136 |
| - |
137 |
| -// dprint-ignore |
138 |
| -typeReturnMode<$ConfigextendsConfig,$Data>= |
139 |
| -$Config['returnMode']extends'graphql' ?ExecutionResult<$Data> :$Data |
140 |
| - |
141 | 17 | // dprint-ignore
|
142 | 18 | exporttypeClient<$IndexextendsSchema.Index,$ConfigextendsOptionsInputDefaults>=
|
143 | 19 | &{
|
144 | 20 | // todo test raw
|
145 |
| -raw:(document:string|DocumentNode,variables?:Variables,operationName?:string)=>Promise<ExecutionResult> |
146 |
| -document:<$DocumentextendsDocument<$Index>> |
147 |
| -(document:ValidateDocumentOperationNames<NonEmptyObject<$Document>>)=> |
148 |
| -// (document: $Document) => |
149 |
| -{ |
150 |
| -run:<$Nameextendskeyof$Document&string,$Paramsextends(IsMultipleKeys<$Document>extendstrue ?[name:$Name] :([]|[name:$Name|undefined]))> |
151 |
| -(...params:$Params)=> |
152 |
| -Promise< |
153 |
| -ReturnMode<$Config,ResultSet.Root<GetOperation<$Document[$Name]>,$Index,'Query'>> |
154 |
| -> |
155 |
| -} |
| 21 | +raw:(document:string|DocumentNode,variables?:Variables,operationName?:string)=>Promise<ExecutionResult> |
| 22 | +document:DocumentFn<$Config,$Index> |
156 | 23 | }
|
157 |
| -&( |
158 |
| -$Index['Root']['Query']extendsnull |
159 |
| - ?unknown |
160 |
| - :{ |
161 |
| -query:RootTypeMethods<$Config,$Index,'Query'> |
162 |
| -} |
163 |
| -) |
164 |
| -&( |
165 |
| -$Index['Root']['Mutation']extendsnull |
166 |
| - ?unknown |
167 |
| - :{ |
168 |
| -mutation:RootTypeMethods<$Config,$Index,'Mutation'> |
169 |
| -} |
170 |
| -) |
171 |
| -// todo |
172 |
| -// & ($SchemaIndex['Root']['Subscription'] extends null ? { |
173 |
| -// subscription: <$SelectionSet extends SelectionSet.Subscription<$SchemaIndex>>(selectionSet: $SelectionSet) => Promise<ResultSet.Subscription<$SelectionSet,$SchemaIndex>> |
174 |
| -// } |
175 |
| -// : unknown) |
176 |
| -// |
| 24 | +&GetRootTypeMethods<$Config,$Index> |
177 | 25 |
|
178 | 26 | interfaceHookInputDocumentEncode{
|
179 | 27 | rootIndex:Object$2
|
|