Skip to content

Commit 85d7117

Browse files
authored
Merge pull request #15 from SportlabsTechnology/master
Swift4.1 updates and switch to Runtime library
2 parents 864e263 + b42b3ac commit 85d7117

File tree

11 files changed

+102
-40
lines changed

11 files changed

+102
-40
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: 4 additions & 2 deletions
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
@@ -16,4 +16,6 @@ script:
1616
- swift build -c release
1717
- swift build
1818
- swift test
19-
- eval "$(curl -sL https://raw.githubusercontent.com/lgaches/swifttravisci/master/codecov)"
19+
- 'if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
20+
eval "$(curl -sL https://raw.githubusercontent.com/lgaches/swifttravisci/master/codecov)";
21+
fi'

Package.resolved

Lines changed: 25 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: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
1+
// swift-tools-version:4.0
12
import PackageDescription
23

34
let package = Package(
45
name: "Graphiti",
6+
7+
products: [
8+
.library(name: "Graphiti", targets: ["Graphiti"]),
9+
],
10+
511
dependencies: [
6-
.Package(url: "https://github.com/GraphQLSwift/GraphQL.git", majorVersion: 0, minor: 3),
12+
.package(url: "https://github.com/GraphQLSwift/GraphQL.git", from: "0.5.0"),
13+
],
14+
15+
targets: [
16+
.target(name: "Graphiti", dependencies: ["GraphQL"]),
17+
18+
.testTarget(name: "GraphitiTests", dependencies: ["Graphiti"]),
719
]
820
)

Sources/Graphiti/Graphiti.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ final class AnyType : Hashable {
1919
}
2020

2121
func isProtocol(type: Any.Type) -> Bool {
22-
let description = String(describing: type(of: type))
22+
let description = String(describing: Swift.type(of: type))
2323
return description.hasSuffix("Protocol")
2424
}
2525

@@ -29,11 +29,11 @@ func fixName(_ name: String) -> String {
2929
var workingString = name
3030

3131
if name.hasPrefix("(") {
32-
workingString = String(name.characters.dropFirst())
32+
workingString = String(name.dropFirst())
3333
}
3434

3535
var newName: [Character] = []
36-
for character in workingString.characters {
36+
for character in workingString {
3737
if character != " " {
3838
newName.append(character)
3939
} else {

Sources/Graphiti/Schema/Schema.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import GraphQL
2+
import Runtime
23

34
public final class SchemaBuilder<Root, Context> {
45
var graphQLTypeMap: [AnyType: GraphQLType] = [
@@ -261,7 +262,7 @@ public final class SchemaBuilder<Root, Context> {
261262
}
262263
}
263264

264-
extension SchemaBuilder {
265+
public extension SchemaBuilder {
265266
func map(_ type: Any.Type, to graphQLType: GraphQLType) {
266267
guard !(type is Void.Type) else {
267268
return
@@ -339,7 +340,7 @@ extension SchemaBuilder {
339340
return outputType
340341
}
341342

342-
func getInputType(from type: Any.Type, field: String) throws -> GraphQLInputType {
343+
public func getInputType(from type: Any.Type, field: String) throws -> GraphQLInputType {
343344
guard let graphQLType = getGraphQLType(from: type) else {
344345
throw GraphQLError(
345346
message:
@@ -462,15 +463,16 @@ extension SchemaBuilder {
462463
return [:]
463464
}
464465

465-
for property in try properties(type) {
466+
let info = try typeInfo(of: type)
467+
for property in info.properties {
466468
if case let propertyType as MapInitializable.Type = property.type {
467469
let argument = GraphQLArgument(
468470
type: try getInputType(from: propertyType, field: field),
469-
description: argumentsType.descriptions[property.key],
470-
defaultValue: try argumentsType.defaultValues[property.key]?.asMap()
471+
description: argumentsType.descriptions[property.name],
472+
defaultValue: try argumentsType.defaultValues[property.name]?.asMap()
471473
)
472474

473-
arguments[property.key] = argument
475+
arguments[property.name] = argument
474476
}
475477
}
476478

Sources/Graphiti/Types/Field.swift

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import GraphQL
2+
import Runtime
23

34
public protocol InputType : MapInitializable {}
45
public protocol OutputType : MapFallibleRepresentable {}
@@ -45,10 +46,12 @@ public class FieldBuilder<Root, Context, Type> {
4546
/// - Parameter excluding: properties excluded from the export
4647
/// - Throws: Reflection Errors
4748
public func exportFields(excluding: String...) throws {
48-
for property in try properties(Type.self) {
49-
if !excluding.contains(property.key) {
50-
let field = GraphQLField(type: try schema.getOutputType(from: property.type, field: property.key))
51-
fields[property.key] = field
49+
let info = try typeInfo(of: Type.self)
50+
51+
for property in info.properties {
52+
if !excluding.contains(property.name) {
53+
let field = GraphQLField(type: try schema.getOutputType(from: property.type, field: property.name))
54+
fields[property.name] = field
5255
}
5356
}
5457
}
@@ -65,11 +68,11 @@ public class FieldBuilder<Root, Context, Type> {
6568
if let resolve = resolve {
6669
r = { source, _, context, info in
6770
guard let s = source as? Type else {
68-
throw GraphQLError(message: "Expected source type \(Type.self) but got \(type(of: source))")
71+
throw GraphQLError(message: "Expected source type \(Type.self) but got \(Swift.type(of: source))")
6972
}
7073

7174
guard let c = context as? Context else {
72-
throw GraphQLError(message: "Expected context type \(Context.self) but got \(type(of: context))")
75+
throw GraphQLError(message: "Expected context type \(Context.self) but got \(Swift.type(of: context))")
7376
}
7477

7578
guard let output = try resolve(s, NoArguments(), c, info) else {
@@ -103,11 +106,11 @@ public class FieldBuilder<Root, Context, Type> {
103106
if let resolve = resolve {
104107
r = { source, _, context, info in
105108
guard let s = source as? Type else {
106-
throw GraphQLError(message: "Expected source type \(Type.self) but got \(type(of: source))")
109+
throw GraphQLError(message: "Expected source type \(Type.self) but got \(Swift.type(of: source))")
107110
}
108111

109112
guard let c = context as? Context else {
110-
throw GraphQLError(message: "Expected context type \(Context.self) but got \(type(of: context))")
113+
throw GraphQLError(message: "Expected context type \(Context.self) but got \(Swift.type(of: context))")
111114
}
112115

113116
return try resolve(s, NoArguments(), c, info)
@@ -137,11 +140,11 @@ public class FieldBuilder<Root, Context, Type> {
137140
if let resolve = resolve {
138141
r = { source, _, context, info in
139142
guard let s = source as? Type else {
140-
throw GraphQLError(message: "Expected source type \(Type.self) but got \(type(of: source))")
143+
throw GraphQLError(message: "Expected source type \(Type.self) but got \(Swift.type(of: source))")
141144
}
142145

143146
guard let c = context as? Context else {
144-
throw GraphQLError(message: "Expected context type \(Context.self) but got \(type(of: context))")
147+
throw GraphQLError(message: "Expected context type \(Context.self) but got \(Swift.type(of: context))")
145148
}
146149

147150
return try resolve(s, NoArguments(), c, info)
@@ -186,11 +189,11 @@ public class FieldBuilder<Root, Context, Type> {
186189
if let resolve = resolve {
187190
r = { source, _, context, info in
188191
guard let s = source as? Type else {
189-
throw GraphQLError(message: "Expected source type \(Type.self) but got \(type(of: source))")
192+
throw GraphQLError(message: "Expected source type \(Type.self) but got \(Swift.type(of: source))")
190193
}
191194

192195
guard let c = context as? Context else {
193-
throw GraphQLError(message: "Expected context type \(Context.self) but got \(type(of: context))")
196+
throw GraphQLError(message: "Expected context type \(Context.self) but got \(Swift.type(of: context))")
194197
}
195198

196199
return try resolve(s, NoArguments(), c, info)
@@ -225,13 +228,13 @@ public class FieldBuilder<Root, Context, Type> {
225228
resolve: resolve.map { resolve in
226229
return { source, args, context, info in
227230
guard let s = source as? Type else {
228-
throw GraphQLError(message: "Expected source type \(Type.self) but got \(type(of: source))")
231+
throw GraphQLError(message: "Expected source type \(Type.self) but got \(Swift.type(of: source))")
229232
}
230233

231234
let a = try A(map: args)
232235

233236
guard let c = context as? Context else {
234-
throw GraphQLError(message: "Expected context type \(Context.self) but got \(type(of: context))")
237+
throw GraphQLError(message: "Expected context type \(Context.self) but got \(Swift.type(of: context))")
235238
}
236239

237240
guard let output = try resolve(s, a, c, info) else {
@@ -263,13 +266,13 @@ public class FieldBuilder<Root, Context, Type> {
263266
resolve: resolve.map { resolve in
264267
return { source, args, context, info in
265268
guard let s = source as? Type else {
266-
throw GraphQLError(message: "Expected type \(Type.self) but got \(type(of: source))")
269+
throw GraphQLError(message: "Expected type \(Type.self) but got \(Swift.type(of: source))")
267270
}
268271

269272
let a = try A(map: args)
270273

271274
guard let c = context as? Context else {
272-
throw GraphQLError(message: "Expected context type \(Context.self) but got \(type(of: context))")
275+
throw GraphQLError(message: "Expected context type \(Context.self) but got \(Swift.type(of: context))")
273276
}
274277

275278
return try resolve(s, a, c, info)

Sources/Graphiti/Types/InputObjectType.swift

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import GraphQL
2+
import Runtime
23

34
public final class InputObjectTypeBuilder<Root, Context, Type> {
45
var schema: SchemaBuilder<Root, Context>
@@ -14,11 +15,20 @@ public final class InputObjectTypeBuilder<Root, Context, Type> {
1415
/// Export all properties using reflection
1516
///
1617
/// - Throws: Reflection Errors
17-
public func exportFields() throws {
18-
for property in try properties(Type.self) {
19-
let field = InputObjectField(type: try schema.getInputType(from: property.type, field: property.key))
20-
fields[property.key] = field
18+
public func exportFields(excluding: String...) throws {
19+
20+
let info = try typeInfo(of: Type.self)
21+
22+
for property in info.properties {
23+
if !excluding.contains(property.name) {
24+
let field = InputObjectField(type: try schema.getInputType(from: property.type, field: property.name))
25+
fields[property.name] = field
26+
}
2127
}
2228
}
29+
30+
public func addFieldMap(key: String, fieldMap: InputObjectField) {
31+
fields[key] = fieldMap
32+
}
2333
}
2434

Sources/Graphiti/Types/InterfaceType.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ public final class InterfaceTypeBuilder<Root, Context, Type> : FieldBuilder<Root
1313
public func resolveType(_ resolve: @escaping ResolveType<Type, Context>) {
1414
self.resolveType = { value, context, info in
1515
guard let v = value as? Type else {
16-
throw GraphQLError(message: "Expected value type \(Type.self) but got \(type(of: value))")
16+
throw GraphQLError(message: "Expected value type \(Type.self) but got \(Swift.type(of: value))")
1717
}
1818

1919
guard let c = context as? Context else {
20-
throw GraphQLError(message: "Expected context type \(Context.self) but got \(type(of: context))")
20+
throw GraphQLError(message: "Expected context type \(Context.self) but got \(Swift.type(of: context))")
2121
}
2222

2323
let type = try resolve(v, c, info)

Tests/GraphitiTests/HelloWorldTests/HelloWorldTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ extension Float : InputType, OutputType {
1515
class HelloWorldTests : XCTestCase {
1616
let schema = try! Schema<NoRoot, NoContext> { schema in
1717
try schema.query { query in
18-
try query.field(name: "hello", type: String.self) { _ in
18+
try query.field(name: "hello", type: String.self) { (_, _, _, _) -> String in
1919
"world"
2020
}
2121
}

0 commit comments

Comments
 (0)