Skip to content

Commit 1d90f4f

Browse files
Merge pull request #95 from NeedleInAJayStack/fix/schema-builder-connectiontype-support
Adds ConnectionType support to SchemaBuilder
2 parents 9845fb4 + 238025a commit 1d90f4f

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

Sources/Graphiti/Connection/ConnectionType.swift

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ public final class ConnectionType<
44
Resolver,
55
Context,
66
ObjectType: Encodable
7-
>: Component<
7+
>: TypeComponent<
88
Resolver,
99
Context
1010
> {
@@ -20,16 +20,19 @@ public final class ConnectionType<
2020
try pageInfo.update(typeProvider: typeProvider, coders: coders)
2121
}
2222

23-
let edge = Type<Resolver, Context, Edge<ObjectType>>(Edge<ObjectType>.self) {
23+
let edge = Type<Resolver, Context, Edge<ObjectType>>(
24+
Edge<ObjectType>.self,
25+
as: name+"Edge"
26+
) {
2427
Field("node", at: \.node)
2528
Field("cursor", at: \.cursor)
2629
}
2730

2831
try edge.update(typeProvider: typeProvider, coders: coders)
2932

3033
let connection = Type<Resolver, Context, Connection<ObjectType>>(
31-
Connection<ObjectType>
32-
.self
34+
Connection<ObjectType>.self,
35+
as: name+"Connection"
3336
) {
3437
Field("edges", at: \.edges)
3538
Field("pageInfo", at: \.pageInfo)
@@ -38,13 +41,19 @@ public final class ConnectionType<
3841
try connection.update(typeProvider: typeProvider, coders: coders)
3942
}
4043

41-
private init(type _: ObjectType.Type) {
42-
super.init(name: "")
44+
private init(
45+
type _: ObjectType.Type,
46+
name: String?
47+
) {
48+
super.init(name: name ?? Reflection.name(for: ObjectType.self))
4349
}
4450
}
4551

4652
public extension ConnectionType {
47-
convenience init(_ type: ObjectType.Type) {
48-
self.init(type: type)
53+
convenience init(
54+
_ type: ObjectType.Type,
55+
as name: String? = nil
56+
) {
57+
self.init(type: type, name: name)
4958
}
5059
}

Tests/GraphitiTests/SchemaBuilderTests.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class SchemaBuilderTests: XCTestCase {
2929
}.description(
3030
"A large mass, planet or planetoid in the Star Wars Universe, at the time of 0 ABY."
3131
)
32+
}.add {
33+
ConnectionType(Planet.self)
3234
}.add {
3335
Enum(Episode.self) {
3436
Value(.newHope)
@@ -120,5 +122,11 @@ class SchemaBuilderTests: XCTestCase {
120122
],
121123
])
122124
)
125+
126+
XCTAssert(
127+
api.schema.schema.typeMap.contains(where: { key, _ in
128+
key == "PlanetConnection"
129+
})
130+
)
123131
}
124132
}

0 commit comments

Comments
 (0)