Skip to content

Commit 3338389

Browse files
Reverts accidental push
Revert "test: Adds circular reference object test" Revert "feature: Adds type objects to TypeProvider types" Revert "feature: Replaces unknown type error with auto-reference" Revert "feature: Deprecates `Types` in preference of `Type`" Revert "chore: Updates packages" Revert "refactor: Removes unnecessary TypeReference usage"
1 parent 2aaaa5b commit 3338389

File tree

13 files changed

+22
-121
lines changed

13 files changed

+22
-121
lines changed

Package.resolved

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,26 @@
66
"repositoryURL": "https://github.com/GraphQLSwift/GraphQL.git",
77
"state": {
88
"branch": null,
9-
"revision": "17b96ed859072fca79dd562da2a79e1bc752756f",
10-
"version": "2.4.1"
11-
}
12-
},
13-
{
14-
"package": "swift-atomics",
15-
"repositoryURL": "https://github.com/apple/swift-atomics.git",
16-
"state": {
17-
"branch": null,
18-
"revision": "919eb1d83e02121cdb434c7bfc1f0c66ef17febe",
19-
"version": "1.0.2"
9+
"revision": "ebd2ea40676f8bcbdfd6088c408f3ed321c1a905",
10+
"version": "2.4.0"
2011
}
2112
},
2213
{
2314
"package": "swift-collections",
2415
"repositoryURL": "https://github.com/apple/swift-collections",
2516
"state": {
2617
"branch": null,
27-
"revision": "f504716c27d2e5d4144fa4794b12129301d17729",
28-
"version": "1.0.3"
18+
"revision": "48254824bb4248676bf7ce56014ff57b142b77eb",
19+
"version": "1.0.2"
2920
}
3021
},
3122
{
3223
"package": "swift-nio",
3324
"repositoryURL": "https://github.com/apple/swift-nio.git",
3425
"state": {
3526
"branch": null,
36-
"revision": "a16e2f54a25b2af217044e5168997009a505930f",
37-
"version": "2.42.0"
27+
"revision": "124119f0bb12384cef35aa041d7c3a686108722d",
28+
"version": "2.40.0"
3829
}
3930
}
4031
]

Sources/Graphiti/Definition/TypeProvider.swift

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,11 @@ extension TypeProvider {
5656
return try getGraphQLOptionalType(from: referenceType, isOptional: isOptional)
5757
}
5858
} else {
59-
if let graphQLType = graphQLTypeMap[AnyType(type)] {
60-
return try getGraphQLOptionalType(from: graphQLType, isOptional: isOptional)
61-
} else {
62-
// If we haven't seen this type yet, just store it as a type reference and resolve later.
63-
let name = Reflection.name(for: type)
64-
let referenceType = GraphQLTypeReference(name)
65-
66-
return try getGraphQLOptionalType(from: referenceType, isOptional: isOptional)
59+
guard let graphQLType = graphQLTypeMap[AnyType(type)] else {
60+
throw GraphQLError(message: "Type \"\(type)\" is not registered.")
6761
}
62+
63+
return try getGraphQLOptionalType(from: graphQLType, isOptional: isOptional)
6864
}
6965
}
7066

Sources/Graphiti/Enum/Enum.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public final class Enum<
2424
)
2525

2626
try typeProvider.map(EnumType.self, to: enumType)
27-
typeProvider.types.append(enumType)
2827
}
2928

3029
private init(

Sources/Graphiti/Input/Input.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ public final class Input<
1818
)
1919

2020
try typeProvider.map(InputObjectType.self, to: inputObjectType)
21-
typeProvider.types.append(inputObjectType)
2221
}
2322

2423
func fields(typeProvider: TypeProvider) throws -> InputObjectFieldMap {

Sources/Graphiti/Interface/Interface.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ public final class Interface<Resolver, Context, InterfaceType>: Component<Resolv
1212
)
1313

1414
try typeProvider.map(InterfaceType.self, to: interfaceType)
15-
typeProvider.types.append(interfaceType)
1615
}
1716

1817
func fields(typeProvider: TypeProvider, coders: Coders) throws -> GraphQLFieldMap {

Sources/Graphiti/Scalar/Scalar.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ open class Scalar<Resolver, Context, ScalarType: Codable>: Component<Resolver, C
3434
)
3535

3636
try typeProvider.map(ScalarType.self, to: scalarType)
37-
typeProvider.types.append(scalarType)
3837
}
3938

4039
open func serialize(scalar: ScalarType, encoder: MapEncoder) throws -> Map {

Sources/Graphiti/Type/Type.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public final class Type<Resolver, Context, ObjectType: Encodable>: Component<Res
2020
)
2121

2222
try typeProvider.map(ObjectType.self, to: objectType)
23-
typeProvider.types.append(objectType)
2423
}
2524

2625
func fields(typeProvider: TypeProvider, coders: Coders) throws -> GraphQLFieldMap {

Sources/Graphiti/Types/Types.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import GraphQL
22

3-
@available(*, deprecated, message: "No longer use this. Instead define types using `Type`.")
43
public final class Types<Resolver, Context>: Component<Resolver, Context> {
54
let types: [Any.Type]
65

@@ -14,8 +13,10 @@ public final class Types<Resolver, Context>: Component<Resolver, Context> {
1413
self.types = types
1514
super.init(name: "")
1615
}
16+
}
1717

18-
public convenience init(_ types: Any.Type...) {
18+
public extension Types {
19+
convenience init(_ types: Any.Type...) {
1920
self.init(types: types)
2021
}
2122
}

Tests/GraphitiTests/HelloWorldTests/HelloWorldAsyncTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ import XCTest
6161
Type(User.self) {
6262
Field("id", at: \.id)
6363
Field("name", at: \.name)
64-
Field("friends", at: \.friends)
64+
Field("friends", at: \.friends, as: [TypeReference<User>]?.self)
6565
}
6666

6767
Input(UserInput.self) {
6868
InputField("id", at: \.id)
6969
InputField("name", at: \.name)
70-
InputField("friends", at: \.friends)
70+
InputField("friends", at: \.friends, as: [TypeReference<UserInput>]?.self)
7171
}
7272

7373
Type(UserEvent.self) {

Tests/GraphitiTests/HelloWorldTests/HelloWorldTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,13 @@ struct HelloAPI: API {
121121
Type(User.self) {
122122
Field("id", at: \.id)
123123
Field("name", at: \.name)
124-
Field("friends", at: \.friends)
124+
Field("friends", at: \.friends, as: [TypeReference<User>]?.self)
125125
}
126126

127127
Input(UserInput.self) {
128128
InputField("id", at: \.id)
129129
InputField("name", as: String?.self)
130-
InputField("friends", at: \.friends)
130+
InputField("friends", at: \.friends, as: [TypeReference<UserInput>]?.self)
131131
}
132132

133133
Type(UserEvent.self) {

Tests/GraphitiTests/SchemaTests.swift

Lines changed: 0 additions & 84 deletions
This file was deleted.

Tests/GraphitiTests/StarWarsAPI/StarWarsAPI.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public struct StarWarsAPI: API {
4040
Field("diameter", at: \.diameter)
4141
Field("rotationPeriod", at: \.rotationPeriod)
4242
Field("orbitalPeriod", at: \.orbitalPeriod)
43-
Field("residents", at: \.residents)
43+
Field("residents", at: \.residents, as: [TypeReference<Human>].self)
4444
}
4545
.description(
4646
"A large mass, planet or planetoid in the Star Wars Universe, at the time of 0 ABY."
@@ -100,5 +100,7 @@ public struct StarWarsAPI: API {
100100
.defaultValue("R2-D2")
101101
}
102102
}
103+
104+
Types(Human.self, Droid.self)
103105
}
104106
}

Tests/GraphitiTests/StarWarsTests/StarWarsQueryTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,8 +655,8 @@ class StarWarsQueryTests: XCTestCase {
655655

656656
let schema = try! Schema<TestResolver, NoContext> {
657657
Type(A.self) {
658-
Field("nullableA", at: A.nullableA)
659-
Field("nonNullA", at: A.nonNullA)
658+
Field("nullableA", at: A.nullableA, as: (TypeReference<A>?).self)
659+
Field("nonNullA", at: A.nonNullA, as: TypeReference<A>.self)
660660
Field("throws", at: A.throws)
661661
}
662662

0 commit comments

Comments
 (0)