Skip to content

Commit 2fe3b0b

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents f266324 + 9202d5a commit 2fe3b0b

37 files changed

+183
-146
lines changed

.swift-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.1
1+
4.0

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ matrix:
55
include:
66
- os: osx
77
env: JOB=SwiftPM_OSX
8-
osx_image: xcode8.3
8+
osx_image: xcode9
99
- os: linux
1010
env: JOB=SwiftPM_linux
1111
dist: trusty

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ The following strategies are available:
138138

139139
This project is released under the MIT license. See [LICENSE](LICENSE) for details.
140140

141-
[swift-badge]: https://img.shields.io/badge/Swift-3.0-orange.svg?style=flat
141+
[swift-badge]: https://img.shields.io/badge/Swift-4-orange.svg?style=flat
142142
[swift-url]: https://swift.org
143143
[mit-badge]: https://img.shields.io/badge/License-MIT-blue.svg?style=flat
144144
[mit-url]: https://tldrlegal.com/license/mit-license

Sources/GraphQL/Instrumentation/Instrumentation.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import Foundation
12
import Dispatch
23

34
/// Provides the capability to instrument the execution steps of a GraphQL query.
@@ -62,7 +63,11 @@ extension Instrumentation {
6263
}
6364

6465
func threadId() -> Int {
65-
return Int(pthread_mach_thread_np(pthread_self()))
66+
#if os(Linux)
67+
return Int(pthread_self())
68+
#else
69+
return Int(pthread_mach_thread_np(pthread_self()))
70+
#endif
6671
}
6772

6873
func processId() -> Int {

Sources/GraphQL/Reflection/Advance.swift

100755100644
File mode changed.

Sources/GraphQL/Reflection/Any+Extensions.swift

100755100644
Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,32 @@
66
//
77
//
88

9-
public protocol AnyExtensions {}
9+
protocol AnyExtensions {}
1010

11-
public extension AnyExtensions {
11+
extension AnyExtensions {
1212

1313
static func construct(constructor: (Property.Description) throws -> Any) throws -> Any {
14-
return try GraphQL.construct(self, constructor: constructor)
14+
return try GraphQL.constructGenericType(self, constructor: constructor)
1515
}
1616

17-
static func construct(dictionary: [String: Any]) throws -> Any {
18-
return try GraphQL.construct(self, dictionary: dictionary)
17+
static func isValueTypeOrSubtype(_ value: Any) -> Bool {
18+
return value is Self
1919
}
2020

21-
func write(to pointer: UnsafeMutableRawPointer) {
22-
pointer.assumingMemoryBound(to: type(of: self)).initialize(to: self)
21+
static func value(from storage: UnsafeRawPointer) -> Any {
22+
return storage.assumingMemoryBound(to: self).pointee
23+
}
24+
25+
static func write(_ value: Any, to storage: UnsafeMutableRawPointer) throws {
26+
guard let this = value as? Self else {
27+
throw ReflectionError.valueIsNotType(value: value, type: self)
28+
}
29+
storage.assumingMemoryBound(to: self).initialize(to: this)
2330
}
2431

2532
}
2633

27-
public func extensions(of type: Any.Type) -> AnyExtensions.Type {
34+
func extensions(of type: Any.Type) -> AnyExtensions.Type {
2835
struct Extensions : AnyExtensions {}
2936
var extensions: AnyExtensions.Type = Extensions.self
3037
withUnsafePointer(to: &extensions) { pointer in
@@ -33,7 +40,7 @@ public func extensions(of type: Any.Type) -> AnyExtensions.Type {
3340
return extensions
3441
}
3542

36-
public func extensions(of value: Any) -> AnyExtensions {
43+
func extensions(of value: Any) -> AnyExtensions {
3744
struct Extensions : AnyExtensions {}
3845
var extensions: AnyExtensions = Extensions()
3946
withUnsafePointer(to: &extensions) { pointer in

Sources/GraphQL/Reflection/AnyExistentialContainer.swift

Lines changed: 0 additions & 17 deletions
This file was deleted.

Sources/GraphQL/Reflection/Array+Extensions.swift

100755100644
File mode changed.

Sources/GraphQL/Reflection/Buffer.swift

Lines changed: 0 additions & 20 deletions
This file was deleted.

Sources/GraphQL/Reflection/Construct.swift

100755100644
Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
/// Create a struct with a constructor method. Return a value of `property.type` for each property.
22
public func construct<T>(_ type: T.Type = T.self, constructor: (Property.Description) throws -> Any) throws -> T {
3+
return try constructGenericType(constructor: constructor)
4+
}
5+
6+
func constructGenericType<T>(_ type: T.Type = T.self, constructor: (Property.Description) throws -> Any) throws -> T {
37
if Metadata(type: T.self)?.kind == .struct {
48
return try constructValueType(constructor)
59
} else {
@@ -22,22 +26,29 @@ private func constructValueType<T>(_ constructor: (Property.Description) throws
2226
}
2327

2428
private func constructType(storage: UnsafeMutableRawPointer, values: inout [Any], properties: [Property.Description], constructor: (Property.Description) throws -> Any) throws {
29+
var errors = [Error]()
2530
for property in properties {
26-
let value = try constructor(property)
27-
guard GraphQL.value(value, is: property.type) else { throw ReflectionError.valueIsNotType(value: value, type: property.type) }
28-
values.append(value)
29-
extensions(of: value).write(to: storage.advanced(by: property.offset))
31+
do {
32+
let value = try constructor(property)
33+
values.append(value)
34+
try property.write(value, to: storage)
35+
} catch {
36+
errors.append(error)
37+
}
38+
}
39+
if errors.count > 0 {
40+
throw ConstructionErrors(errors: errors)
3041
}
3142
}
3243

3344
/// Create a struct from a dictionary.
3445
public func construct<T>(_ type: T.Type = T.self, dictionary: [String: Any]) throws -> T {
35-
return try construct(constructor: constructorForDictionary(dictionary))
46+
return try constructGenericType(constructor: constructorForDictionary(dictionary))
3647
}
3748

3849
/// Create a struct from a dictionary.
3950
public func construct(_ type: Any.Type, dictionary: [String: Any]) throws -> Any {
40-
return try extensions(of: type).construct(dictionary: dictionary)
51+
return try construct(type, constructor: constructorForDictionary(dictionary))
4152
}
4253

4354
private func constructorForDictionary(_ dictionary: [String: Any]) -> (Property.Description) throws -> Any {

0 commit comments

Comments
 (0)