Skip to content
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: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0
4.1
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ matrix:
include:
- os: osx
env: JOB=SwiftPM_OSX
osx_image: xcode9
osx_image: xcode9.3beta
- os: linux
env: JOB=SwiftPM_linux
dist: trusty
Expand All @@ -16,4 +16,6 @@ script:
- swift build -c release
- swift build
- swift test
- eval "$(curl -sL https://raw.githubusercontent.com/lgaches/swifttravisci/master/codecov)"
- 'if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
eval "$(curl -sL https://raw.githubusercontent.com/lgaches/swifttravisci/master/codecov)";
fi'
25 changes: 25 additions & 0 deletions Package.resolved

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

14 changes: 13 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
// swift-tools-version:4.0
import PackageDescription

let package = Package(
name: "Graphiti",

products: [
.library(name: "Graphiti", targets: ["Graphiti"]),
],

dependencies: [
.Package(url: "https://github.com/GraphQLSwift/GraphQL.git", majorVersion: 0, minor: 3),
.package(url: "https://github.com/GraphQLSwift/GraphQL.git", from: "0.5.0"),
],

targets: [
.target(name: "Graphiti", dependencies: ["GraphQL"]),

.testTarget(name: "GraphitiTests", dependencies: ["Graphiti"]),
]
)
6 changes: 3 additions & 3 deletions Sources/Graphiti/Graphiti.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final class AnyType : Hashable {
}

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

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

if name.hasPrefix("(") {
workingString = String(name.characters.dropFirst())
workingString = String(name.dropFirst())
}

var newName: [Character] = []
for character in workingString.characters {
for character in workingString {
if character != " " {
newName.append(character)
} else {
Expand Down
14 changes: 8 additions & 6 deletions Sources/Graphiti/Schema/Schema.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import GraphQL
import Runtime

public final class SchemaBuilder<Root, Context> {
var graphQLTypeMap: [AnyType: GraphQLType] = [
Expand Down Expand Up @@ -261,7 +262,7 @@ public final class SchemaBuilder<Root, Context> {
}
}

extension SchemaBuilder {
public extension SchemaBuilder {
func map(_ type: Any.Type, to graphQLType: GraphQLType) {
guard !(type is Void.Type) else {
return
Expand Down Expand Up @@ -339,7 +340,7 @@ extension SchemaBuilder {
return outputType
}

func getInputType(from type: Any.Type, field: String) throws -> GraphQLInputType {
public func getInputType(from type: Any.Type, field: String) throws -> GraphQLInputType {
guard let graphQLType = getGraphQLType(from: type) else {
throw GraphQLError(
message:
Expand Down Expand Up @@ -462,15 +463,16 @@ extension SchemaBuilder {
return [:]
}

for property in try properties(type) {
let info = try typeInfo(of: type)
for property in info.properties {
if case let propertyType as MapInitializable.Type = property.type {
let argument = GraphQLArgument(
type: try getInputType(from: propertyType, field: field),
description: argumentsType.descriptions[property.key],
defaultValue: try argumentsType.defaultValues[property.key]?.asMap()
description: argumentsType.descriptions[property.name],
defaultValue: try argumentsType.defaultValues[property.name]?.asMap()
)

arguments[property.key] = argument
arguments[property.name] = argument
}
}

Expand Down
35 changes: 19 additions & 16 deletions Sources/Graphiti/Types/Field.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import GraphQL
import Runtime

public protocol InputType : MapInitializable {}
public protocol OutputType : MapFallibleRepresentable {}
Expand Down Expand Up @@ -45,10 +46,12 @@ public class FieldBuilder<Root, Context, Type> {
/// - Parameter excluding: properties excluded from the export
/// - Throws: Reflection Errors
public func exportFields(excluding: String...) throws {
for property in try properties(Type.self) {
if !excluding.contains(property.key) {
let field = GraphQLField(type: try schema.getOutputType(from: property.type, field: property.key))
fields[property.key] = field
let info = try typeInfo(of: Type.self)

for property in info.properties {
if !excluding.contains(property.name) {
let field = GraphQLField(type: try schema.getOutputType(from: property.type, field: property.name))
fields[property.name] = field
}
}
}
Expand All @@ -65,11 +68,11 @@ public class FieldBuilder<Root, Context, Type> {
if let resolve = resolve {
r = { source, _, context, info in
guard let s = source as? Type else {
throw GraphQLError(message: "Expected source type \(Type.self) but got \(type(of: source))")
throw GraphQLError(message: "Expected source type \(Type.self) but got \(Swift.type(of: source))")
}

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

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

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

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

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

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

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

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

let a = try A(map: args)

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

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

let a = try A(map: args)

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

return try resolve(s, a, c, info)
Expand Down
18 changes: 14 additions & 4 deletions Sources/Graphiti/Types/InputObjectType.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import GraphQL
import Runtime

public final class InputObjectTypeBuilder<Root, Context, Type> {
var schema: SchemaBuilder<Root, Context>
Expand All @@ -14,11 +15,20 @@ public final class InputObjectTypeBuilder<Root, Context, Type> {
/// Export all properties using reflection
///
/// - Throws: Reflection Errors
public func exportFields() throws {
for property in try properties(Type.self) {
let field = InputObjectField(type: try schema.getInputType(from: property.type, field: property.key))
fields[property.key] = field
public func exportFields(excluding: String...) throws {

let info = try typeInfo(of: Type.self)

for property in info.properties {
if !excluding.contains(property.name) {
let field = InputObjectField(type: try schema.getInputType(from: property.type, field: property.name))
fields[property.name] = field
}
}
}

public func addFieldMap(key: String, fieldMap: InputObjectField) {
fields[key] = fieldMap
}
}

4 changes: 2 additions & 2 deletions Sources/Graphiti/Types/InterfaceType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ public final class InterfaceTypeBuilder<Root, Context, Type> : FieldBuilder<Root
public func resolveType(_ resolve: @escaping ResolveType<Type, Context>) {
self.resolveType = { value, context, info in
guard let v = value as? Type else {
throw GraphQLError(message: "Expected value type \(Type.self) but got \(type(of: value))")
throw GraphQLError(message: "Expected value type \(Type.self) but got \(Swift.type(of: value))")
}

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

let type = try resolve(v, c, info)
Expand Down
2 changes: 1 addition & 1 deletion Tests/GraphitiTests/HelloWorldTests/HelloWorldTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extension Float : InputType, OutputType {
class HelloWorldTests : XCTestCase {
let schema = try! Schema<NoRoot, NoContext> { schema in
try schema.query { query in
try query.field(name: "hello", type: String.self) { _ in
try query.field(name: "hello", type: String.self) { (_, _, _, _) -> String in
"world"
}
}
Expand Down
16 changes: 12 additions & 4 deletions Tests/GraphitiTests/StarWarsTests/StarWarsQueryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,15 @@ class StarWarsQueryTests : XCTestCase {
struct A : OutputType {}

try schema.object(type: A.self) { a in
try a.field(name: "nullableA", type: (TypeReference<A>?).self) { _ in A() }
try a.field(name: "nonNullA", type: TypeReference<A>.self) { _ in A() }
try a.field(name: "throws", type: String.self) { _ in
try a.field(name: "nullableA", type: (TypeReference<A>?).self) { (_, _, _, _) -> A?
in A()
}

try a.field(name: "nonNullA", type: TypeReference<A>.self) { (_, _, _, _) -> A
in A()
}

try a.field(name: "throws", type: String.self) { (_, _, _, _) -> String in
struct 🏃 : Error, CustomStringConvertible {
let description: String
}
Expand All @@ -455,7 +461,9 @@ class StarWarsQueryTests : XCTestCase {
}

try schema.query { query in
try query.field(name: "nullableA", type: (A?).self) { _ in A() }
try query.field(name: "nullableA", type: (A?).self) { (_, _, _, _) -> A? in
A()
}
}
}

Expand Down