Skip to content

Commit 13a95b0

Browse files
committed
Lazily reoslve interface's interfaces in BuildClientSchema
1 parent f12c6ba commit 13a95b0

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

Sources/GraphQL/Type/Definition.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,10 @@ public final class GraphQLInterfaceType {
791791
fields: fieldsThunk()
792792
)
793793
}()
794-
public let interfaces: [GraphQLInterfaceType]
794+
public lazy var interfaces: [GraphQLInterfaceType] = {
795+
try! interfacesThunk()
796+
}()
797+
private let interfacesThunk: () throws -> [GraphQLInterfaceType]
795798
public let kind: TypeKind = .interface
796799

797800
public convenience init(
@@ -804,7 +807,7 @@ public final class GraphQLInterfaceType {
804807
try self.init(
805808
name: name,
806809
description: description,
807-
interfaces: interfaces,
810+
interfaces: { interfaces },
808811
fields: { fields },
809812
resolveType: resolveType
810813
)
@@ -813,7 +816,7 @@ public final class GraphQLInterfaceType {
813816
public init(
814817
name: String,
815818
description: String? = nil,
816-
interfaces: [GraphQLInterfaceType] = [],
819+
interfaces: @escaping () throws -> [GraphQLInterfaceType],
817820
fields: @escaping () -> GraphQLFieldMap,
818821
resolveType: GraphQLTypeResolve? = nil
819822
) throws {
@@ -823,7 +826,7 @@ public final class GraphQLInterfaceType {
823826

824827
self.fieldsThunk = fields
825828

826-
self.interfaces = interfaces
829+
self.interfacesThunk = interfaces
827830
self.resolveType = resolveType
828831
}
829832

Sources/GraphQL/Utilities/BuildClientSchema.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public func buildClientSchema(introspection: IntrospectionQuery) throws -> Graph
105105
return try GraphQLInterfaceType(
106106
name: type.name,
107107
description: type.description,
108-
interfaces: buildImplementationsList(interfaces: type.interfaces ?? []),
108+
interfaces: { try buildImplementationsList(interfaces: type.interfaces ?? []) },
109109
fields: { try! buildFieldDefMap(fields: type.fields ?? []) },
110110
resolveType: nil
111111
)

0 commit comments

Comments
 (0)