Skip to content

Commit 8811ad6

Browse files
feat!: Removes Field/InputField as instantiate arg
This was typically used to override a resolver type into a TypeReference. With TypeReference no longer necessary, allowing this simply reduces type safety.
1 parent e9853e2 commit 8811ad6

File tree

9 files changed

+21
-144
lines changed

9 files changed

+21
-144
lines changed

Sources/Graphiti/Field/Field/Field.swift

Lines changed: 0 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -131,27 +131,6 @@ public extension Field {
131131
}
132132
}
133133

134-
public extension Field {
135-
convenience init<ResolveType>(
136-
_ name: String,
137-
at function: @escaping AsyncResolve<ObjectType, Context, Arguments, ResolveType>,
138-
as: FieldType.Type,
139-
@ArgumentComponentBuilder<Arguments> _ argument: () -> ArgumentComponent<Arguments>
140-
) {
141-
self.init(name: name, arguments: [argument()], asyncResolve: function)
142-
}
143-
144-
convenience init<ResolveType>(
145-
_ name: String,
146-
at function: @escaping AsyncResolve<ObjectType, Context, Arguments, ResolveType>,
147-
as: FieldType.Type,
148-
@ArgumentComponentBuilder<Arguments> _ arguments: ()
149-
-> [ArgumentComponent<Arguments>] = { [] }
150-
) {
151-
self.init(name: name, arguments: arguments(), asyncResolve: function)
152-
}
153-
}
154-
155134
// MARK: SimpleAsyncResolve Initializers
156135

157136
public extension Field {
@@ -173,27 +152,6 @@ public extension Field {
173152
}
174153
}
175154

176-
public extension Field {
177-
convenience init<ResolveType>(
178-
_ name: String,
179-
at function: @escaping SimpleAsyncResolve<ObjectType, Context, Arguments, ResolveType>,
180-
as: FieldType.Type,
181-
@ArgumentComponentBuilder<Arguments> _ argument: () -> ArgumentComponent<Arguments>
182-
) {
183-
self.init(name: name, arguments: [argument()], simpleAsyncResolve: function)
184-
}
185-
186-
convenience init<ResolveType>(
187-
_ name: String,
188-
at function: @escaping SimpleAsyncResolve<ObjectType, Context, Arguments, ResolveType>,
189-
as: FieldType.Type,
190-
@ArgumentComponentBuilder<Arguments> _ arguments: ()
191-
-> [ArgumentComponent<Arguments>] = { [] }
192-
) {
193-
self.init(name: name, arguments: arguments(), simpleAsyncResolve: function)
194-
}
195-
}
196-
197155
// MARK: SyncResolve Initializers
198156

199157
// '@_disfavoredOverload' is included below because otherwise `SimpleAsyncResolve` initializers also match this signature, causing the
@@ -220,29 +178,6 @@ public extension Field {
220178
}
221179
}
222180

223-
public extension Field {
224-
@_disfavoredOverload
225-
convenience init<ResolveType>(
226-
_ name: String,
227-
at function: @escaping SyncResolve<ObjectType, Context, Arguments, ResolveType>,
228-
as: FieldType.Type,
229-
@ArgumentComponentBuilder<Arguments> _ argument: () -> ArgumentComponent<Arguments>
230-
) {
231-
self.init(name: name, arguments: [argument()], syncResolve: function)
232-
}
233-
234-
@_disfavoredOverload
235-
convenience init<ResolveType>(
236-
_ name: String,
237-
at function: @escaping SyncResolve<ObjectType, Context, Arguments, ResolveType>,
238-
as: FieldType.Type,
239-
@ArgumentComponentBuilder<Arguments> _ arguments: ()
240-
-> [ArgumentComponent<Arguments>] = { [] }
241-
) {
242-
self.init(name: name, arguments: arguments(), syncResolve: function)
243-
}
244-
}
245-
246181
// MARK: Keypath Initializers
247182

248183
public extension Field where Arguments == NoArguments {
@@ -260,22 +195,6 @@ public extension Field where Arguments == NoArguments {
260195
}
261196
}
262197

263-
public extension Field where Arguments == NoArguments {
264-
convenience init<ResolveType>(
265-
_ name: String,
266-
at keyPath: KeyPath<ObjectType, ResolveType>,
267-
as _: FieldType.Type
268-
) {
269-
let syncResolve: SyncResolve<ObjectType, Context, NoArguments, ResolveType> = { type in
270-
{ _, _ in
271-
type[keyPath: keyPath]
272-
}
273-
}
274-
275-
self.init(name: name, arguments: [], syncResolve: syncResolve)
276-
}
277-
}
278-
279198
public extension Field {
280199
@available(macOS 10.15, iOS 15, watchOS 8, tvOS 15, *)
281200
convenience init<ResolveType>(
@@ -323,26 +242,3 @@ public extension Field {
323242
self.init(name: name, arguments: arguments(), concurrentResolve: function)
324243
}
325244
}
326-
327-
public extension Field {
328-
@available(macOS 10.15, iOS 15, watchOS 8, tvOS 15, *)
329-
convenience init<ResolveType>(
330-
_ name: String,
331-
at function: @escaping ConcurrentResolve<ObjectType, Context, Arguments, ResolveType>,
332-
as: FieldType.Type,
333-
@ArgumentComponentBuilder<Arguments> _ argument: () -> ArgumentComponent<Arguments>
334-
) {
335-
self.init(name: name, arguments: [argument()], concurrentResolve: function)
336-
}
337-
338-
@available(macOS 10.15, iOS 15, watchOS 8, tvOS 15, *)
339-
convenience init<ResolveType>(
340-
_ name: String,
341-
at function: @escaping ConcurrentResolve<ObjectType, Context, Arguments, ResolveType>,
342-
as: FieldType.Type,
343-
@ArgumentComponentBuilder<Arguments> _ arguments: ()
344-
-> [ArgumentComponent<Arguments>] = { [] }
345-
) {
346-
self.init(name: name, arguments: arguments(), concurrentResolve: function)
347-
}
348-
}

Sources/Graphiti/InputField/InputField.swift

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,6 @@ public extension InputField {
3939
}
4040
}
4141

42-
public extension InputField {
43-
convenience init<KeyPathType>(
44-
_ name: String,
45-
at _: KeyPath<InputObjectType, KeyPathType>,
46-
as _: FieldType.Type
47-
) {
48-
self.init(name: name)
49-
}
50-
}
51-
52-
public extension InputField {
53-
convenience init(
54-
_ name: String,
55-
as _: FieldType.Type
56-
) {
57-
self.init(name: name)
58-
}
59-
}
60-
6142
public extension InputField where FieldType: Encodable {
6243
func defaultValue(_ defaultValue: FieldType) -> Self {
6344
self.defaultValue = AnyEncodable(defaultValue)

Tests/GraphitiTests/ConnectionTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ class ConnectionTests: XCTestCase {
489489

490490
let schema = try Schema<Resolver, NoContext> {
491491
Type(ChatObject.self, as: "Chat") {
492-
Field("messages", at: ChatObject.messages, as: Connection<MessageObject>.self) {
492+
Field("messages", at: ChatObject.messages) {
493493
Argument("first", at: \.first)
494494
Argument("after", at: \.after)
495495
Argument("last", at: \.last)

Tests/GraphitiTests/DirectiveTests/DirectiveTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class DirectiveTests: XCTestCase {
153153
}
154154

155155
Query {
156-
Field("test", at: OneOfResolver.test, as: TestObject.self) {
156+
Field("test", at: OneOfResolver.test) {
157157
Argument("input", at: \.input)
158158
}
159159
}

Tests/GraphitiTests/HelloWorldTests/HelloWorldTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ struct HelloAPI: API {
126126

127127
Input(UserInput.self) {
128128
InputField("id", at: \.id)
129-
InputField("name", as: String?.self)
129+
InputField("name", at: \.name)
130130
InputField("friends", at: \.friends)
131131
}
132132

Tests/GraphitiTests/PartialSchemaTests.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class PartialSchemaTests: XCTestCase {
3434

3535
@FieldDefinitions
3636
override var query: Fields {
37-
Field("hero", at: StarWarsResolver.hero, as: Character.self) {
37+
Field("hero", at: StarWarsResolver.hero) {
3838
Argument("episode", at: \.episode)
3939
.description(
4040
"If omitted, returns the hero of the whole saga. If provided, returns the hero of that particular episode."
@@ -61,7 +61,7 @@ class PartialSchemaTests: XCTestCase {
6161
Field("name", at: \.name)
6262
Field("appearsIn", at: \.appearsIn)
6363
Field("homePlanet", at: \.homePlanet)
64-
Field("friends", at: Human.getFriends, as: [Character].self)
64+
Field("friends", at: Human.getFriends)
6565
.description("The friends of the human, or an empty list if they have none.")
6666
Field("secretBackstory", at: Human.getSecretBackstory)
6767
.description("Where are they from and how they came to be who they are.")
@@ -71,7 +71,7 @@ class PartialSchemaTests: XCTestCase {
7171
Field("name", at: \.name)
7272
Field("appearsIn", at: \.appearsIn)
7373
Field("primaryFunction", at: \.primaryFunction)
74-
Field("friends", at: Droid.getFriends, as: [Character].self)
74+
Field("friends", at: Droid.getFriends)
7575
.description("The friends of the droid, or an empty list if they have none.")
7676
Field("secretBackstory", at: Droid.getSecretBackstory)
7777
.description("Where are they from and how they came to be who they are.")
@@ -89,7 +89,7 @@ class PartialSchemaTests: XCTestCase {
8989
Argument("id", at: \.id)
9090
.description("Id of the droid.")
9191
}
92-
Field("search", at: StarWarsResolver.search, as: [SearchResult].self) {
92+
Field("search", at: StarWarsResolver.search) {
9393
Argument("query", at: \.query)
9494
.defaultValue("R2-D2")
9595
}
@@ -238,7 +238,7 @@ class PartialSchemaTests: XCTestCase {
238238
}.description("One of the films in the Star Wars Trilogy.")
239239
},
240240
query: {
241-
Field("hero", at: StarWarsResolver.hero, as: Character.self) {
241+
Field("hero", at: StarWarsResolver.hero) {
242242
Argument("episode", at: \.episode)
243243
.description(
244244
"If omitted, returns the hero of the whole saga. If provided, returns the hero of that particular episode."
@@ -264,7 +264,7 @@ class PartialSchemaTests: XCTestCase {
264264
Field("name", at: \.name)
265265
Field("appearsIn", at: \.appearsIn)
266266
Field("homePlanet", at: \.homePlanet)
267-
Field("friends", at: Human.getFriends, as: [Character].self)
267+
Field("friends", at: Human.getFriends)
268268
.description(
269269
"The friends of the human, or an empty list if they have none."
270270
)
@@ -276,7 +276,7 @@ class PartialSchemaTests: XCTestCase {
276276
Field("name", at: \.name)
277277
Field("appearsIn", at: \.appearsIn)
278278
Field("primaryFunction", at: \.primaryFunction)
279-
Field("friends", at: Droid.getFriends, as: [Character].self)
279+
Field("friends", at: Droid.getFriends)
280280
.description(
281281
"The friends of the droid, or an empty list if they have none."
282282
)
@@ -294,7 +294,7 @@ class PartialSchemaTests: XCTestCase {
294294
Argument("id", at: \.id)
295295
.description("Id of the droid.")
296296
}
297-
Field("search", at: StarWarsResolver.search, as: [SearchResult].self) {
297+
Field("search", at: StarWarsResolver.search) {
298298
Argument("query", at: \.query)
299299
.defaultValue("R2-D2")
300300
}

Tests/GraphitiTests/SchemaBuilderTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class SchemaBuilderTests: XCTestCase {
1111

1212
// Add assets slightly out of order
1313
builder.addQuery {
14-
Field("hero", at: StarWarsResolver.hero, as: Character.self) {
14+
Field("hero", at: StarWarsResolver.hero) {
1515
Argument("episode", at: \.episode)
1616
.description(
1717
"If omitted, returns the hero of the whole saga. If provided, returns the hero of that particular episode."
@@ -49,7 +49,7 @@ class SchemaBuilderTests: XCTestCase {
4949
Field("name", at: \.name)
5050
Field("appearsIn", at: \.appearsIn)
5151
Field("homePlanet", at: \.homePlanet)
52-
Field("friends", at: Human.getFriends, as: [Character].self)
52+
Field("friends", at: Human.getFriends)
5353
.description("The friends of the human, or an empty list if they have none.")
5454
Field("secretBackstory", at: Human.getSecretBackstory)
5555
.description("Where are they from and how they came to be who they are.")
@@ -59,7 +59,7 @@ class SchemaBuilderTests: XCTestCase {
5959
Field("name", at: \.name)
6060
Field("appearsIn", at: \.appearsIn)
6161
Field("primaryFunction", at: \.primaryFunction)
62-
Field("friends", at: Droid.getFriends, as: [Character].self)
62+
Field("friends", at: Droid.getFriends)
6363
.description("The friends of the droid, or an empty list if they have none.")
6464
Field("secretBackstory", at: Droid.getSecretBackstory)
6565
.description("Where are they from and how they came to be who they are.")
@@ -89,7 +89,7 @@ class SchemaBuilderTests: XCTestCase {
8989
Argument("id", at: \.id)
9090
.description("Id of the droid.")
9191
}
92-
Field("search", at: StarWarsResolver.search, as: [SearchResult].self) {
92+
Field("search", at: StarWarsResolver.search) {
9393
Argument("query", at: \.query)
9494
.defaultValue("R2-D2")
9595
}

Tests/GraphitiTests/StarWarsAPI/StarWarsAPI.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public struct StarWarsAPI: API {
5252
Field("appearsIn", at: \.appearsIn)
5353
Field("homePlanet", at: \.homePlanet)
5454

55-
Field("friends", at: Human.getFriends, as: [Character].self)
55+
Field("friends", at: Human.getFriends)
5656
.description("The friends of the human, or an empty list if they have none.")
5757

5858
Field("secretBackstory", at: Human.getSecretBackstory)
@@ -66,7 +66,7 @@ public struct StarWarsAPI: API {
6666
Field("appearsIn", at: \.appearsIn)
6767
Field("primaryFunction", at: \.primaryFunction)
6868

69-
Field("friends", at: Droid.getFriends, as: [Character].self)
69+
Field("friends", at: Droid.getFriends)
7070
.description("The friends of the droid, or an empty list if they have none.")
7171

7272
Field("secretBackstory", at: Droid.getSecretBackstory)
@@ -77,7 +77,7 @@ public struct StarWarsAPI: API {
7777
Union(SearchResult.self, members: Planet.self, Human.self, Droid.self)
7878

7979
Query {
80-
Field("hero", at: StarWarsResolver.hero, as: Character.self) {
80+
Field("hero", at: StarWarsResolver.hero) {
8181
Argument("episode", at: \.episode)
8282
.description(
8383
"If omitted, returns the hero of the whole saga. If provided, returns the hero of that particular episode."
@@ -95,7 +95,7 @@ public struct StarWarsAPI: API {
9595
.description("Id of the droid.")
9696
}
9797

98-
Field("search", at: StarWarsResolver.search, as: [SearchResult].self) {
98+
Field("search", at: StarWarsResolver.search) {
9999
Argument("query", at: \.query)
100100
.defaultValue("R2-D2")
101101
}

Tests/GraphitiTests/UnionTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class UnionTests: XCTestCase {
2222
Union(SearchResult.self, members: Planet.self, Human.self, Droid.self)
2323

2424
Query {
25-
Field("search", at: StarWarsResolver.search, as: [SearchResult].self) {
25+
Field("search", at: StarWarsResolver.search) {
2626
Argument("query", at: \.query)
2727
}
2828
}
@@ -48,7 +48,7 @@ class UnionTests: XCTestCase {
4848
])
4949

5050
Query {
51-
Field("search", at: StarWarsResolver.search, as: [SearchResult].self) {
51+
Field("search", at: StarWarsResolver.search) {
5252
Argument("query", at: \.query)
5353
}
5454
}

0 commit comments

Comments
 (0)