Skip to content

Replace Runtime package with Mirror #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.build
.git
18 changes: 0 additions & 18 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/apple/swift-nio.git", .upToNextMajor(from: "2.10.1")),
.package(url: "https://github.com/wickwirew/Runtime.git", .upToNextMinor(from: "2.1.0"))
],
targets: [
.target(
name: "GraphQL",
dependencies: [
.product(name: "NIO", package: "swift-nio"),
.product(name: "Runtime", package: "Runtime")
]
),
.testTarget(name: "GraphQLTests", dependencies: ["GraphQL"]),
Expand Down
27 changes: 2 additions & 25 deletions Sources/GraphQL/Execution/Execute.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Dispatch
import Runtime
import NIO

/**
Expand Down Expand Up @@ -1175,33 +1174,11 @@ func defaultResolve(
return eventLoopGroup.next().makeSucceededFuture(value)
}

guard let encodable = source as? Encodable else {
let mirror = Mirror(reflecting: source)
guard let value = mirror.getValue(named: info.fieldName) else {
return eventLoopGroup.next().makeSucceededFuture(nil)
}

guard
let typeInfo = try? typeInfo(of: type(of: encodable)),
let property = try? typeInfo.property(named: info.fieldName)
else {
return eventLoopGroup.next().makeSucceededFuture(nil)
}

guard let value = try? property.get(from: encodable) else {
return eventLoopGroup.next().makeSucceededFuture(nil)
}

return eventLoopGroup.next().makeSucceededFuture(value)

// guard let any = try? AnyEncoder().encode(AnyEncodable(encodable)) else {
// return eventLoopGroup.next().newSucceededFuture(result: nil)
// }
//
// guard let dictionary = any as? [String: Any] else {
// return eventLoopGroup.next().newSucceededFuture(result: nil)
// }
//
// let value = dictionary[info.fieldName]
// return eventLoopGroup.next().newSucceededFuture(result: value)
}

/**
Expand Down
2 changes: 0 additions & 2 deletions Sources/GraphQL/Subscription/Subscribe.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import Dispatch
import Runtime
import NIO

/**
Expand Down
22 changes: 22 additions & 0 deletions Sources/GraphQL/SwiftUtilities/Mirror.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
func unwrap(_ value: Any) -> Any? {
let mirror = Mirror(reflecting: value)

if mirror.displayStyle != .optional {
return value
}

guard let child = mirror.children.first else {
return nil
}

return child.value
}

extension Mirror {
func getValue(named key: String) -> Any? {
guard let matched = children.filter({ $0.label == key }).first else {
return nil
}
return unwrap(matched.value)
}
}
14 changes: 0 additions & 14 deletions Sources/GraphQL/SwiftUtilities/Unwrap.swift

This file was deleted.