Skip to content

Commit

Permalink
No longer adding types to context for simple inlines
Browse files Browse the repository at this point in the history
  • Loading branch information
nerdsupremacist committed May 10, 2021
1 parent 5b033e8 commit 51042a6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,22 @@ import NIO
extension GraphQLObject {

static func resolveObject(using context: inout Resolution.Context) throws -> GraphQLObjectType {
let (typeProperties, typeMethods, inheritance) = try typeInfo(of: Self.self, .properties, .methods, .inheritance)
let inheritance = try typeInfo(of: Self.self, .inheritance)
let fieldsAndInterfaces = try self.fieldsAndInterfaces(using: &context)

let interfaces = try inheritance
.compactMap { $0 as? GraphQLObject.Type }
.map { try context.resolveInterface(object: $0) } + fieldsAndInterfaces.interfaces

let type = try GraphQLObjectType(name: concreteTypeName,
fields: fieldsAndInterfaces.fields,
interfaces: interfaces.distinct(by: \.name)) { value, _, _ in value is Self }

return type
}

static func fieldsAndInterfaces(using context: inout Resolution.Context) throws -> FieldsAndInterfaces {
let (typeProperties, typeMethods) = try typeInfo(of: Self.self, .properties, .methods)

let isNode: Bool
if let type = Self.self as? Node.Type {
Expand All @@ -31,17 +46,16 @@ extension GraphQLObject {
.merging(methods) { $1 }
.merging(nodeFields) { $1 }

let interfaces = try inheritance
.compactMap { $0 as? GraphQLObject.Type }
.map { try context.resolveInterface(object: $0) } + propertyResults.flatMap(\.interfaces) + [isNode ? GraphQLNode : nil].compactMap { $0 }

let type = try GraphQLObjectType(name: concreteTypeName, fields: fields, interfaces: interfaces.distinct(by: \.name)) { value, _, _ in value is Self }

return type
return FieldsAndInterfaces(interfaces: propertyResults.flatMap(\.interfaces) + [isNode ? GraphQLNode : nil].compactMap { $0 }, fields: fields)
}

}

struct FieldsAndInterfaces {
let interfaces: [GraphQLInterfaceType]
let fields: GraphQLFieldMap
}

extension Sequence {

fileprivate func distinct<T : Hashable>(by id: (Element) -> T) -> [Element] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,13 @@ extension Inline: CustomGraphQLProperty {
for receiverType: GraphQLObject.Type,
using context: inout Resolution.Context) throws -> PropertyResult {

let object = try Wrapped.resolveObject(using: &context)

let fields = object.fields.mapValues { field in
let fields = try Wrapped.fieldsAndInterfaces(using: &context).fields.mapValues { field in
return GraphQLField(
type: field.type,
description: field.description,
deprecationReason: field.deprecationReason,
args: Dictionary(
uniqueKeysWithValues: field.args.map { ($0.name, $0.type) }
)
.mapValues { GraphQLArgument(type: $0) }
args: field.args
) { source, arguments, context, eventLoop, info in

let object = receiverType.object(from: source)
let result = try property.get(from: object) as! Self
return try field.resolve!(result.wrappedValue, arguments, context, eventLoop, info)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,12 @@ extension LazyInline: CustomGraphQLProperty {
for receiverType: GraphQLObject.Type,
using context: inout Resolution.Context) throws -> PropertyResult {

let object = try Wrapped.resolveObject(using: &context)

let fields = object.fields.mapValues { field in
let fields = try Wrapped.fieldsAndInterfaces(using: &context).fields.mapValues { field in
return GraphQLField(
type: field.type,
description: field.description,
deprecationReason: field.deprecationReason,
args: Dictionary(
uniqueKeysWithValues: field.args.map { ($0.name, $0.type) }
)
.mapValues { GraphQLArgument(type: $0) }
args: field.args
) { source, arguments, context, eventLoop, info in

let object = receiverType.object(from: source)
Expand Down

0 comments on commit 51042a6

Please sign in to comment.