Skip to content

Commit 56b4da1

Browse files
authored
Merge pull request #35 from jseibert/swift-4.1
Swift 4.1 Support
2 parents ffffcd6 + e7f0e5f commit 56b4da1

35 files changed

+76
-685
lines changed

.swift-version

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

.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: xcode9
8+
osx_image: xcode9.3beta
99
- os: linux
1010
env: JOB=SwiftPM_linux
1111
dist: trusty

Package.resolved

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
1+
// swift-tools-version:4.0
12
import PackageDescription
23

34
let package = Package(
4-
name: "GraphQL"
5+
name: "GraphQL",
6+
7+
products: [
8+
.library(name: "GraphQL", targets: ["GraphQL"]),
9+
],
10+
11+
dependencies: [
12+
.package(url: "https://github.com/wickwirew/Runtime.git", from: "0.4.0"),
13+
],
14+
15+
targets: [
16+
.target(name: "GraphQL", dependencies: ["Runtime"]),
17+
18+
.testTarget(name: "GraphQLTests", dependencies: ["GraphQL"]),
19+
]
520
)

Sources/GraphQL/Error/SyntaxError.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func highlightSourceAtLocation(source: Source, location: SourceLocation) -> Stri
2828
let prevLineNum = (line - 1).description
2929
let lineNum = line.description
3030
let nextLineNum = (line + 1).description
31-
let padLength = nextLineNum.characters.count
31+
let padLength = nextLineNum.count
3232

3333
let lines = splitLines(string: source.body)
3434

@@ -73,5 +73,5 @@ func splitLines(string: String) -> [String] {
7373
}
7474

7575
func leftpad(_ length: Int, _ string: String) -> String {
76-
return String(repeating: " ", count: max(length - string.characters.count + 1, 0)) + string
76+
return String(repeating: " ", count: max(length - string.count + 1, 0)) + string
7777
}

Sources/GraphQL/Execution/Execute.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Dispatch
2+
import Runtime
23

34
/**
45
* Terminology
@@ -1128,7 +1129,12 @@ func defaultResolve(source: Any, args: Map, context: Any, info: GraphQLResolveIn
11281129
}
11291130

11301131
// TODO: check why Reflection fails
1131-
guard let value = try? get(info.fieldName, from: s) else {
1132+
guard let typeInfo = try? typeInfo(of: type(of: s)),
1133+
let property = try? typeInfo.property(named: info.fieldName) else {
1134+
return nil
1135+
}
1136+
1137+
guard let value = try? property.get(from: s) else {
11321138
return nil
11331139
}
11341140

Sources/GraphQL/Map/MapCustomStringConvertible.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ extension Map {
3939
func escape(_ source: String) -> String {
4040
var string = "\""
4141

42-
for character in source.characters {
42+
for character in source {
4343
if let escapedSymbol = escapeMapping[character] {
4444
string.append(escapedSymbol)
4545
} else {

Sources/GraphQL/Map/MapInitializable.swift

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
1+
import Runtime
2+
3+
enum RuntimeReflectionError: Error {
4+
case requiredValueMissing(key: String)
5+
}
6+
17
extension MapInitializable {
28
public init(map: Map) throws {
39
guard case .dictionary(let dictionary) = map else {
410
throw MapError.cannotInitialize(type: Self.self, from: try type(of: map.get()))
511
}
6-
self = try construct { property in
12+
13+
self = try createInstance()
14+
let info = try typeInfo(of: Self.self)
15+
16+
for property in info.properties {
717
guard let initializable = property.type as? MapInitializable.Type else {
818
throw MapError.notMapInitializable(property.type)
919
}
10-
switch dictionary[property.key] ?? .null {
20+
switch dictionary[property.name] ?? .null {
1121
case .null:
1222
guard let expressibleByNilLiteral = property.type as? ExpressibleByNilLiteral.Type else {
13-
throw ReflectionError.requiredValueMissing(key: property.key)
23+
throw RuntimeReflectionError.requiredValueMissing(key: property.name)
1424
}
15-
return expressibleByNilLiteral.init(nilLiteral: ())
25+
try property.set(value: expressibleByNilLiteral.init(nilLiteral: ()), on: &self)
1626
case let x:
17-
return try initializable.init(map: x)
27+
try property.set(value: initializable.init(map: x), on: &self)
1828
}
1929
}
2030
}

Sources/GraphQL/Map/MapRepresentable.swift

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import Runtime
2+
13
public func map(from value: Any?) throws -> Map {
24
guard let value = value else {
35
return .null
@@ -10,13 +12,14 @@ public func map(from value: Any?) throws -> Map {
1012
if let mapFallibleRepresentable = value as? MapFallibleRepresentable {
1113
return try mapFallibleRepresentable.asMap()
1214
}
13-
14-
let props = try properties(value)
15+
16+
let info = try typeInfo(of: type(of: value))
17+
let props = info.properties
1518

1619
var dictionary = [String: Map](minimumCapacity: props.count)
1720

1821
for property in props {
19-
dictionary[property.key] = try map(from: property.value)
22+
dictionary[property.name] = try map(from: property.get(from: value))
2023
}
2124

2225
return .dictionary(dictionary)
@@ -31,20 +34,22 @@ public func assertMappable(_ type: Any.Type) throws {
3134
return
3235
}
3336

34-
for property in try properties(type) {
37+
let info = try typeInfo(of: type)
38+
for property in info.properties {
3539
try assertMappable(property.type)
3640
}
3741
}
3842

3943
extension MapFallibleRepresentable {
4044
public func asMap() throws -> Map {
41-
let props = try properties(self)
45+
let info = try typeInfo(of: type(of: self))
46+
let props = info.properties
4247
var dictionary = [String: Map](minimumCapacity: props.count)
4348
for property in props {
44-
guard let representable = property.value as? MapFallibleRepresentable else {
45-
throw MapError.notMapRepresentable(type(of: property.value))
49+
guard let representable = try property.get(from: self) as? MapFallibleRepresentable else {
50+
throw MapError.notMapRepresentable(property.type)
4651
}
47-
dictionary[property.key] = try representable.asMap()
52+
dictionary[property.name] = try representable.asMap()
4853
}
4954
return .dictionary(dictionary)
5055
}

Sources/GraphQL/Reflection/Advance.swift

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

0 commit comments

Comments
 (0)