Skip to content

Commit

Permalink
Make subtyping reflexive
Browse files Browse the repository at this point in the history
  • Loading branch information
lukel97 committed Jun 9, 2022
1 parent 8a71abf commit 0765b9f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Sources/GraphQL/Type/Definition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ extension GraphQLInputObjectType : GraphQLTypeReferenceContainer {}
/**
* These types may describe the parent context of a selection set.
*/
public protocol GraphQLAbstractType : GraphQLNamedType {
public protocol GraphQLAbstractType : GraphQLCompositeType {
var resolveType: GraphQLTypeResolve? { get }
}

Expand Down
6 changes: 5 additions & 1 deletion Sources/GraphQL/Type/Schema.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,17 @@ public final class GraphQLSchema {
}

public func isSubType(
abstractType: GraphQLAbstractType,
abstractType: GraphQLCompositeType,
maybeSubType: GraphQLNamedType
) -> Bool {
var map = subTypeMap[abstractType.name]

if map == nil {
map = [:]

if let objectType = abstractType as? GraphQLObjectType {
map?[objectType.name] = true
}

if let unionType = abstractType as? GraphQLUnionType {
for type in unionType.types {
Expand Down
10 changes: 10 additions & 0 deletions Tests/GraphQLTests/TypeTests/GraphQLSchemaTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,14 @@ class GraphQLSchemaTests: XCTestCase {
XCTAssertEqual(graphQLError.message, "Object.fieldWithoutArg includes required argument (addedRequiredArg:) that is missing from the Interface field Interface.fieldWithoutArg.")
}
}

func testSubtypingIsReflexive() throws {
let object = try GraphQLObjectType(
name: "Object",
fields: ["foo": GraphQLField(type: GraphQLInt)],
interfaces: []
)
let schema = try GraphQLSchema(query: object, types: [object])
XCTAssert(schema.isSubType(abstractType: object, maybeSubType: object))
}
}

0 comments on commit 0765b9f

Please sign in to comment.