Skip to content

Commit 881e8f9

Browse files
Igor-Palagutapaulofaria
authored andcommitted
swift-4 support
1 parent 9f498fa commit 881e8f9

File tree

9 files changed

+36
-13
lines changed

9 files changed

+36
-13
lines changed

Sources/GraphQL/Reflection/Identity.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/// Tests if `value` is `type` or a subclass of `type`
22
public func value(_ value: Any, is type: Any.Type) -> Bool {
3-
if type(of: value) == type {
3+
if Swift.type(of: value) == type {
44
return true
55
}
6-
guard var subclass = Metadata.Class(type: type(of: value)), let superclass = Metadata.Class(type: type) else {
6+
guard var subclass = Metadata.Class(type: Swift.type(of: value)), let superclass = Metadata.Class(type: type) else {
77
return false
88
}
99
while let parentClass = subclass.superclass {

Sources/GraphQL/Reflection/MetadataType.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ extension MetadataType {
1414

1515
init?(type: Any.Type) {
1616
self.init(pointer: unsafeBitCast(type, to: UnsafePointer<Int>.self))
17-
if let kind = type(of: self).kind, kind != self.kind {
17+
if let kind = Swift.type(of: self).kind, kind != self.kind {
1818
return nil
1919
}
2020
}

Sources/GraphQL/Reflection/ReflectionError.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public enum ReflectionError : Error, CustomStringConvertible {
1212
var caseDescription: String {
1313
switch self {
1414
case .notStruct(type: let type): return "\(type) is not a struct"
15-
case .valueIsNotType(value: let value, type: let type): return "Cannot set value of type \(type(of: value)) as \(type)"
15+
case .valueIsNotType(value: let value, type: let type): return "Cannot set value of type \(Swift.type(of: value)) as \(type)"
1616
case .instanceHasNoKey(type: let type, key: let key): return "Instance of type \(type) has no key \(key)"
1717
case .requiredValueMissing(key: let key): return "No value found for required key \"\(key)\" in dictionary"
1818
case .unexpected: return "An unexpected error hass occured"

Sources/GraphQL/Reflection/RelativePointer.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
2+
#if swift(>=4)
3+
func relativePointer<T, U, V>(base: UnsafePointer<T>, offset: U) -> UnsafePointer<V> where U : BinaryInteger {
4+
let p = UnsafeRawPointer(base).assumingMemoryBound(to: Int8.self)
5+
return UnsafeRawPointer(p.advanced(by: Int(integer: offset))).assumingMemoryBound(to: V.self)
6+
}
7+
8+
extension Int {
9+
fileprivate init<T : BinaryInteger>(integer: T) {
10+
switch integer {
11+
case let value as Int: self = value
12+
case let value as Int32: self = Int(value)
13+
case let value as Int16: self = Int(value)
14+
case let value as Int8: self = Int(value)
15+
default: self = 0
16+
}
17+
}
18+
}
19+
20+
#else
21+
122
func relativePointer<T, U, V>(base: UnsafePointer<T>, offset: U) -> UnsafePointer<V> where U : Integer {
223
let p = UnsafeRawPointer(base).assumingMemoryBound(to: Int8.self)
324
return UnsafeRawPointer(p.advanced(by: Int(integer: offset))).assumingMemoryBound(to: V.self)
@@ -14,3 +35,5 @@ extension Int {
1435
}
1536
}
1637
}
38+
39+
#endif

Tests/GraphQLTests/FieldExecutionStrategyTests/FieldExecutionStrategyTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class FieldExecutionStrategyTests: XCTestCase {
1414
fields: [
1515
"sleep": GraphQLField(
1616
type: GraphQLString,
17-
resolve: { _ in
17+
resolve: { _, _, _, _ in
1818
let g = DispatchGroup()
1919
g.enter()
2020
DispatchQueue.global().asyncAfter(wallDeadline: .now() + 0.1) {

Tests/GraphQLTests/HelloWorldTests/HelloWorldTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class HelloWorldTests : XCTestCase {
88
fields: [
99
"hello": GraphQLField(
1010
type: GraphQLString,
11-
resolve: { _ in "world" }
11+
resolve: { _, _, _, _ in "world" }
1212
)
1313
]
1414
)

Tests/GraphQLTests/PersistedQueriesTests/PersistedQueriesTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class PersistedQueriesTests: XCTestCase {
99
fields: [
1010
"hello": GraphQLField(
1111
type: GraphQLString,
12-
resolve: { _ in "world" }
12+
resolve: { _, _, _, _ in "world" }
1313
)
1414
]
1515
)

Tests/GraphQLTests/StarWarsTests/StarWarsQueryTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -487,15 +487,15 @@ class StarWarsQueryTests : XCTestCase {
487487
fields: [
488488
"nullableA": GraphQLField(
489489
type: GraphQLTypeReference("A"),
490-
resolve: { _ in [:] }
490+
resolve: { _, _, _, _ in [:] }
491491
),
492492
"nonNullA": GraphQLField(
493493
type: GraphQLNonNull(GraphQLTypeReference("A")),
494-
resolve: { _ in [:] }
494+
resolve: { _, _, _, _ in [:] }
495495
),
496496
"throws": GraphQLField(
497497
type: GraphQLNonNull(GraphQLString),
498-
resolve: { _ in
498+
resolve: { _, _, _, _ in
499499
struct 🏃 : Error, CustomStringConvertible {
500500
let description: String
501501
}
@@ -511,7 +511,7 @@ class StarWarsQueryTests : XCTestCase {
511511
fields: [
512512
"nullableA": GraphQLField(
513513
type: A,
514-
resolve: { _ in [:] }
514+
resolve: { _, _, _, _ in [:] }
515515
)
516516
]
517517
)

Tests/GraphQLTests/StarWarsTests/StarWarsSchema.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ let HumanType = try! GraphQLObjectType(
175175
"secretBackstory": GraphQLField(
176176
type: GraphQLString,
177177
description: "Where are they from and how they came to be who they are.",
178-
resolve: { _ in
178+
resolve: { _, _, _, _ in
179179
struct Secret : Error, CustomStringConvertible {
180180
let description: String
181181
}
@@ -230,7 +230,7 @@ let DroidType = try! GraphQLObjectType(
230230
"secretBackstory": GraphQLField(
231231
type: GraphQLString,
232232
description: "Construction date and the name of the designer.",
233-
resolve: { _ in
233+
resolve: { _, _, _, _ in
234234
struct Secret : Error, CustomStringConvertible {
235235
let description: String
236236
}

0 commit comments

Comments
 (0)