|
1 | 1 | import GraphQL
|
2 | 2 | import Runtime
|
3 | 3 |
|
4 |
| -public class Field<ObjectType, Context, Arguments : Decodable, FieldType, ResolveType> : FieldComponent<ObjectType, Context> { |
| 4 | +public class Field<ObjectType, Context, FieldType, Arguments : Decodable> : FieldComponent<ObjectType, Context> { |
5 | 5 | let name: String
|
6 | 6 | let arguments: [ArgumentComponent<Arguments>]
|
7 | 7 | let resolve: GraphQLFieldResolve
|
@@ -92,104 +92,104 @@ public class Field<ObjectType, Context, Arguments : Decodable, FieldType, Resolv
|
92 | 92 | }
|
93 | 93 | }
|
94 | 94 |
|
95 |
| -// MARK: Keypath Initializers |
| 95 | +// MARK: AsyncResolve Initializers |
96 | 96 |
|
97 |
| -public extension Field where FieldType == ResolveType, Arguments == NoArguments { |
| 97 | +public extension Field where FieldType : Encodable { |
98 | 98 | convenience init(
|
99 | 99 | _ name: String,
|
100 |
| - at keyPath: KeyPath<ObjectType, ResolveType> |
| 100 | + at function: @escaping AsyncResolve<ObjectType, Context, Arguments, FieldType>, |
| 101 | + _ arguments: ArgumentComponent<Arguments>... |
101 | 102 | ) {
|
102 |
| - let syncResolve: SyncResolve<ObjectType, Context, NoArguments, ResolveType> = { type in |
103 |
| - { context, _ in |
104 |
| - type[keyPath: keyPath] |
105 |
| - } |
106 |
| - } |
107 |
| - |
108 |
| - self.init(name: name, arguments: [], syncResolve: syncResolve) |
| 103 | + self.init(name: name, arguments: arguments, asyncResolve: function) |
109 | 104 | }
|
110 | 105 | }
|
111 | 106 |
|
112 |
| -public extension Field where Arguments == NoArguments { |
113 |
| - convenience init( |
| 107 | +public extension Field { |
| 108 | + convenience init<ResolveType>( |
114 | 109 | _ name: String,
|
115 |
| - at keyPath: KeyPath<ObjectType, ResolveType>, |
116 |
| - overridingType: FieldType.Type = FieldType.self |
| 110 | + at function: @escaping AsyncResolve<ObjectType, Context, Arguments, ResolveType>, |
| 111 | + as: FieldType.Type, |
| 112 | + _ arguments: ArgumentComponent<Arguments>... |
117 | 113 | ) {
|
118 |
| - let syncResolve: SyncResolve<ObjectType, Context, NoArguments, ResolveType> = { type in |
119 |
| - return { context, _ in |
120 |
| - return type[keyPath: keyPath] |
121 |
| - } |
122 |
| - } |
123 |
| - |
124 |
| - self.init(name: name, arguments: [], syncResolve: syncResolve) |
| 114 | + self.init(name: name, arguments: arguments, asyncResolve: function) |
125 | 115 | }
|
126 | 116 | }
|
127 | 117 |
|
128 |
| -// MARK: SyncResolve Initializers |
| 118 | +// MARK: SimpleAsyncResolve Initializers |
129 | 119 |
|
130 |
| -public extension Field where FieldType == ResolveType { |
| 120 | +public extension Field where FieldType : Encodable { |
131 | 121 | convenience init(
|
132 | 122 | _ name: String,
|
133 |
| - at function: @escaping SyncResolve<ObjectType, Context, Arguments, ResolveType>, |
| 123 | + at function: @escaping SimpleAsyncResolve<ObjectType, Context, Arguments, FieldType>, |
134 | 124 | _ arguments: ArgumentComponent<Arguments>...
|
135 | 125 | ) {
|
136 |
| - self.init(name: name, arguments: arguments, syncResolve: function) |
| 126 | + self.init(name: name, arguments: arguments, simpleAsyncResolve: function) |
137 | 127 | }
|
138 | 128 | }
|
139 | 129 |
|
140 | 130 | public extension Field {
|
141 |
| - convenience init( |
| 131 | + convenience init<ResolveType>( |
142 | 132 | _ name: String,
|
143 |
| - at function: @escaping SyncResolve<ObjectType, Context, Arguments, ResolveType>, |
144 |
| - overridingType: FieldType.Type = FieldType.self, |
| 133 | + at function: @escaping SimpleAsyncResolve<ObjectType, Context, Arguments, ResolveType>, |
| 134 | + as: FieldType.Type, |
145 | 135 | _ arguments: ArgumentComponent<Arguments>...
|
146 | 136 | ) {
|
147 |
| - self.init(name: name, arguments: arguments, syncResolve: function) |
| 137 | + self.init(name: name, arguments: arguments, simpleAsyncResolve: function) |
148 | 138 | }
|
149 | 139 | }
|
150 | 140 |
|
151 |
| -// MARK: AsyncResolve Initializers |
| 141 | +// MARK: SyncResolve Initializers |
152 | 142 |
|
153 |
| -public extension Field where FieldType == ResolveType { |
| 143 | +public extension Field where FieldType : Encodable { |
154 | 144 | convenience init(
|
155 | 145 | _ name: String,
|
156 |
| - at function: @escaping AsyncResolve<ObjectType, Context, Arguments, ResolveType>, |
| 146 | + at function: @escaping SyncResolve<ObjectType, Context, Arguments, FieldType>, |
157 | 147 | _ arguments: ArgumentComponent<Arguments>...
|
158 | 148 | ) {
|
159 |
| - self.init(name: name, arguments: arguments, asyncResolve: function) |
| 149 | + self.init(name: name, arguments: arguments, syncResolve: function) |
160 | 150 | }
|
161 | 151 | }
|
162 | 152 |
|
163 | 153 | public extension Field {
|
164 |
| - convenience init( |
| 154 | + convenience init<ResolveType>( |
165 | 155 | _ name: String,
|
166 |
| - at function: @escaping AsyncResolve<ObjectType, Context, Arguments, ResolveType>, |
167 |
| - overridingType: FieldType.Type = FieldType.self, |
| 156 | + at function: @escaping SyncResolve<ObjectType, Context, Arguments, ResolveType>, |
| 157 | + as: FieldType.Type, |
168 | 158 | _ arguments: ArgumentComponent<Arguments>...
|
169 | 159 | ) {
|
170 |
| - self.init(name: name, arguments: arguments, asyncResolve: function) |
| 160 | + self.init(name: name, arguments: arguments, syncResolve: function) |
171 | 161 | }
|
172 | 162 | }
|
173 | 163 |
|
174 |
| -// MARK: SimpleAsyncResolve Initializers |
| 164 | +// MARK: Keypath Initializers |
175 | 165 |
|
176 |
| -public extension Field where FieldType == ResolveType { |
| 166 | +public extension Field where Arguments == NoArguments { |
177 | 167 | convenience init(
|
178 | 168 | _ name: String,
|
179 |
| - at function: @escaping SimpleAsyncResolve<ObjectType, Context, Arguments, ResolveType>, |
180 |
| - _ arguments: ArgumentComponent<Arguments>... |
| 169 | + at keyPath: KeyPath<ObjectType, FieldType> |
181 | 170 | ) {
|
182 |
| - self.init(name: name, arguments: arguments, simpleAsyncResolve: function) |
| 171 | + let syncResolve: SyncResolve<ObjectType, Context, NoArguments, FieldType> = { type in |
| 172 | + { context, _ in |
| 173 | + type[keyPath: keyPath] |
| 174 | + } |
| 175 | + } |
| 176 | + |
| 177 | + self.init(name: name, arguments: [], syncResolve: syncResolve) |
183 | 178 | }
|
184 | 179 | }
|
185 | 180 |
|
186 |
| -public extension Field { |
187 |
| - convenience init( |
| 181 | +public extension Field where Arguments == NoArguments { |
| 182 | + convenience init<ResolveType>( |
188 | 183 | _ name: String,
|
189 |
| - at function: @escaping SimpleAsyncResolve<ObjectType, Context, Arguments, ResolveType>, |
190 |
| - overridingType: FieldType.Type = FieldType.self, |
191 |
| - _ arguments: ArgumentComponent<Arguments>... |
| 184 | + at keyPath: KeyPath<ObjectType, ResolveType>, |
| 185 | + as: FieldType.Type |
192 | 186 | ) {
|
193 |
| - self.init(name: name, arguments: arguments, simpleAsyncResolve: function) |
| 187 | + let syncResolve: SyncResolve<ObjectType, Context, NoArguments, ResolveType> = { type in |
| 188 | + return { context, _ in |
| 189 | + return type[keyPath: keyPath] |
| 190 | + } |
| 191 | + } |
| 192 | + |
| 193 | + self.init(name: name, arguments: [], syncResolve: syncResolve) |
194 | 194 | }
|
195 | 195 | }
|
0 commit comments