Skip to content

Commit 0765b9f

Browse files
committed
Make subtyping reflexive
1 parent 8a71abf commit 0765b9f

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

Sources/GraphQL/Type/Definition.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ extension GraphQLInputObjectType : GraphQLTypeReferenceContainer {}
8484
/**
8585
* These types may describe the parent context of a selection set.
8686
*/
87-
public protocol GraphQLAbstractType : GraphQLNamedType {
87+
public protocol GraphQLAbstractType : GraphQLCompositeType {
8888
var resolveType: GraphQLTypeResolve? { get }
8989
}
9090

Sources/GraphQL/Type/Schema.swift

+5-1
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,17 @@ public final class GraphQLSchema {
120120
}
121121

122122
public func isSubType(
123-
abstractType: GraphQLAbstractType,
123+
abstractType: GraphQLCompositeType,
124124
maybeSubType: GraphQLNamedType
125125
) -> Bool {
126126
var map = subTypeMap[abstractType.name]
127127

128128
if map == nil {
129129
map = [:]
130+
131+
if let objectType = abstractType as? GraphQLObjectType {
132+
map?[objectType.name] = true
133+
}
130134

131135
if let unionType = abstractType as? GraphQLUnionType {
132136
for type in unionType.types {

Tests/GraphQLTests/TypeTests/GraphQLSchemaTests.swift

+10
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,14 @@ class GraphQLSchemaTests: XCTestCase {
151151
XCTAssertEqual(graphQLError.message, "Object.fieldWithoutArg includes required argument (addedRequiredArg:) that is missing from the Interface field Interface.fieldWithoutArg.")
152152
}
153153
}
154+
155+
func testSubtypingIsReflexive() throws {
156+
let object = try GraphQLObjectType(
157+
name: "Object",
158+
fields: ["foo": GraphQLField(type: GraphQLInt)],
159+
interfaces: []
160+
)
161+
let schema = try GraphQLSchema(query: object, types: [object])
162+
XCTAssert(schema.isSubType(abstractType: object, maybeSubType: object))
163+
}
154164
}

0 commit comments

Comments
 (0)