From 77f7259737e4ffb478c87419e5fd781cd4a5ad69 Mon Sep 17 00:00:00 2001 From: Kim de Vos Date: Wed, 30 May 2018 10:41:48 +0200 Subject: [PATCH 1/7] Introducing Swift NIO with a little help from Vapor/Core --- Sources/Graphiti/Schema/Schema.swift | 126 +++++++------------ Sources/Graphiti/Types/Field.swift | 57 ++++----- Sources/Graphiti/Types/InputObjectType.swift | 3 +- Sources/Graphiti/Types/InterfaceType.swift | 3 +- Sources/Graphiti/Types/ObjectType.swift | 3 +- 5 files changed, 75 insertions(+), 117 deletions(-) diff --git a/Sources/Graphiti/Schema/Schema.swift b/Sources/Graphiti/Schema/Schema.swift index 69c1aef6..f684fb43 100644 --- a/Sources/Graphiti/Schema/Schema.swift +++ b/Sources/Graphiti/Schema/Schema.swift @@ -1,13 +1,14 @@ import GraphQL import Runtime +import NIO -public final class SchemaBuilder { +public final class SchemaBuilder { var graphQLTypeMap: [AnyType: GraphQLType] = [ AnyType(Int.self): GraphQLInt, AnyType(Double.self): GraphQLFloat, AnyType(String.self): GraphQLString, AnyType(Bool.self): GraphQLBoolean, - ] + ] var query: GraphQLObjectType? = nil var mutation: GraphQLObjectType? = nil @@ -58,7 +59,7 @@ public final class SchemaBuilder { type: Type.Type, interfaces: Any.Type..., build: (ObjectTypeBuilder) throws -> Void - ) throws { + ) throws { let name = fixName(String(describing: Type.self)) try `object`(name: name, type: type, interfaces: interfaces, build: build) } @@ -68,7 +69,7 @@ public final class SchemaBuilder { name: String, interfaces: Any.Type..., build: (ObjectTypeBuilder) throws -> Void - ) throws { + ) throws { try `object`(name: name, type: type, interfaces: interfaces, build: build) } @@ -77,8 +78,8 @@ public final class SchemaBuilder { type: Type.Type, interfaces: [Any.Type], build: (ObjectTypeBuilder) throws -> Void - ) throws { - let builder = ObjectTypeBuilder(schema: self) + ) throws { + let builder = ObjectTypeBuilder(schema: self) try build(builder) let objectType = try GraphQLObjectType( @@ -89,7 +90,7 @@ public final class SchemaBuilder { isTypeOf: builder.isTypeOf ) - map(Type.self, to: objectType) + try map(Type.self, to: objectType) } public func inputObject( @@ -99,7 +100,7 @@ public final class SchemaBuilder { let name = fixName(String(describing: Type.self)) try inputObject(name: name, type: type, build: build) } - + public func inputObject( name: String, type: Type.Type, @@ -107,20 +108,20 @@ public final class SchemaBuilder { ) throws { let builder = InputObjectTypeBuilder(schema: self) try build(builder) - + let inputObjectType = try GraphQLInputObjectType( name: name, description: builder.description, fields: builder.fields ) - - map(Type.self, to: inputObjectType) + + try map(Type.self, to: inputObjectType) } - + public func interface( type: Type.Type, build: (InterfaceTypeBuilder) throws -> Void - ) throws { + ) throws { let name = fixName(String(describing: Type.self)) try interface(name: name, type: type, build: build) } @@ -129,7 +130,7 @@ public final class SchemaBuilder { name: String, type: Type.Type, build: (InterfaceTypeBuilder) throws -> Void - ) throws { + ) throws { let builder = InterfaceTypeBuilder(schema: self) try build(builder) @@ -140,7 +141,7 @@ public final class SchemaBuilder { resolveType: builder.resolveType ) - map(Type.self, to: interfaceType) + try map(Type.self, to: interfaceType) } public func union( @@ -155,7 +156,7 @@ public final class SchemaBuilder { name: String, type: Type.Type, members: [Any.Type] - ) throws { + ) throws { try union(name: name, type: type) { builder in builder.types = members } @@ -184,13 +185,13 @@ public final class SchemaBuilder { types: builder.types.map { try getObjectType(from: $0) } ) - map(Type.self, to: interfaceType) + try map(Type.self, to: interfaceType) } public func `enum`( type: Type.Type, build: (EnumTypeBuilder) throws -> Void - ) throws { + ) throws { let name = fixName(String(describing: Type.self)) try `enum`(name: name, type: type, build: build) } @@ -199,7 +200,7 @@ public final class SchemaBuilder { name: String, type: Type.Type, build: (EnumTypeBuilder) throws -> Void - ) throws { + ) throws { let builder = EnumTypeBuilder() try build(builder) @@ -209,13 +210,13 @@ public final class SchemaBuilder { values: builder.values ) - map(Type.self, to: enumType) + try map(Type.self, to: enumType) } public func scalar( type: Type.Type, build: (ScalarTypeBuilder) throws -> Void - ) throws { + ) throws { let name = fixName(String(describing: Type.self)) try scalar(name: name, type: type, build: build) } @@ -224,7 +225,7 @@ public final class SchemaBuilder { name: String, type: Type.Type, build: (ScalarTypeBuilder) throws -> Void - ) throws { + ) throws { let builder = ScalarTypeBuilder() try build(builder) @@ -258,17 +259,24 @@ public final class SchemaBuilder { ) } - map(Type.self, to: scalarType) + try map(Type.self, to: scalarType) } } public extension SchemaBuilder { - func map(_ type: Any.Type, to graphQLType: GraphQLType) { + func map(_ type: Any.Type, to graphQLType: GraphQLType) throws { guard !(type is Void.Type) else { return } - graphQLTypeMap[AnyType(type)] = graphQLType + let key = AnyType(type) + guard graphQLTypeMap[key] == nil else { + throw GraphQLError( + message: "Duplicate type registration: \(graphQLType.debugDescription)" + ) + } + + graphQLTypeMap[key] = graphQLType } func getTypes() throws -> [GraphQLNamedType] { @@ -441,7 +449,7 @@ public extension SchemaBuilder { "Mapped GraphQL type is nullable." ) } - + guard let objectType = nonNull.ofType as? GraphQLObjectType else { throw GraphQLError( message: @@ -450,7 +458,7 @@ public extension SchemaBuilder { "Mapped GraphQL type is not an object type." ) } - + return objectType } } @@ -475,7 +483,7 @@ extension SchemaBuilder { arguments[property.name] = argument } } - + return arguments } } @@ -483,7 +491,7 @@ extension SchemaBuilder { public typealias NoRoot = Void public typealias NoContext = Void -public struct Schema { +public struct Schema { let schema: GraphQLSchema public init(_ build: (SchemaBuilder) throws -> Void) throws { @@ -504,68 +512,23 @@ public struct Schema { directives: builder.directives ) } - public func execute( - request: String, - variables: [String: Map] = [:], - operationName: String? = nil - ) throws -> Map { - guard Root.self is Void.Type else { - throw GraphQLError( - message: "Root value is required." - ) - } - - guard Context.self is Void.Type else { - throw GraphQLError( - message: "Context value is required." - ) - } - - return try graphql( - schema: schema, - request: request, - variableValues: variables, - operationName: operationName - ) - } public func execute( request: String, - rootValue: Root, + eventLoopGroup: EventLoopGroup, variables: [String: Map] = [:], operationName: String? = nil - ) throws -> Map { - guard Context.self is Void.Type else { - throw GraphQLError( - message: "Context value is required." - ) - } - - return try graphql( - schema: schema, - request: request, - rootValue: rootValue, - variableValues: variables, - operationName: operationName - ) - } - - public func execute( - request: String, - context: Context, - variables: [String: Map] = [:], - operationName: String? = nil - ) throws -> Map { + ) throws -> EventLoopFuture { guard Root.self is Void.Type else { throw GraphQLError( message: "Root value is required." ) } - + return try graphql( schema: schema, request: request, - contextValue: context, + eventLoopGroup: eventLoopGroup, variableValues: variables, operationName: operationName ) @@ -574,18 +537,17 @@ public struct Schema { public func execute( request: String, rootValue: Root, - context: Context, + worker: EventLoopGroup, variables: [String: Map] = [:], operationName: String? = nil - ) throws -> Map { + ) throws -> EventLoopFuture { return try graphql( schema: schema, request: request, rootValue: rootValue, - contextValue: context, + eventLoopGroup: worker, variableValues: variables, operationName: operationName ) } } - diff --git a/Sources/Graphiti/Types/Field.swift b/Sources/Graphiti/Types/Field.swift index 00be722d..da0a3394 100644 --- a/Sources/Graphiti/Types/Field.swift +++ b/Sources/Graphiti/Types/Field.swift @@ -1,5 +1,6 @@ import GraphQL import Runtime +import NIO public protocol InputType : MapInitializable {} public protocol OutputType : MapFallibleRepresentable {} @@ -29,9 +30,9 @@ public typealias ResolveField = ( _ args: A, _ context: C, _ info: GraphQLResolveInfo -) throws -> R + ) throws -> R -public class FieldBuilder { +public class FieldBuilder { var schema: SchemaBuilder init(schema: SchemaBuilder) { @@ -47,7 +48,7 @@ public class FieldBuilder { /// - Throws: Reflection Errors 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 = GraphQLField(type: try schema.getOutputType(from: property.type, field: property.name)) @@ -61,8 +62,8 @@ public class FieldBuilder { type: (TypeReference?).Type = (TypeReference?).self, description: String? = nil, deprecationReason: String? = nil, - resolve: ResolveField? = nil - ) throws { + resolve: ResolveField>? = nil + ) throws { var r: GraphQLFieldResolve? = nil if let resolve = resolve { @@ -75,11 +76,7 @@ public class FieldBuilder { throw GraphQLError(message: "Expected context type \(Context.self) but got \(Swift.type(of: context))") } - guard let output = try resolve(s, NoArguments(), c, info) else { - return nil - } - - return output + return try resolve(s, NoArguments(), c, info).flatMap{ return c.next().newSucceededFuture(result: $0) } } } @@ -99,8 +96,8 @@ public class FieldBuilder { type: TypeReference.Type = TypeReference.self, description: String? = nil, deprecationReason: String? = nil, - resolve: ResolveField? = nil - ) throws { + resolve: ResolveField>? = nil + ) throws { var r: GraphQLFieldResolve? = nil if let resolve = resolve { @@ -113,7 +110,7 @@ public class FieldBuilder { throw GraphQLError(message: "Expected context type \(Context.self) but got \(Swift.type(of: context))") } - return try resolve(s, NoArguments(), c, info) + return try resolve(s, NoArguments(), c, info).flatMap{ return c.next().newSucceededFuture(result: $0) } } } @@ -133,8 +130,8 @@ public class FieldBuilder { type: [TypeReference].Type = [TypeReference].self, description: String? = nil, deprecationReason: String? = nil, - resolve: ResolveField? = nil - ) throws { + resolve: ResolveField>? = nil + ) throws { var r: GraphQLFieldResolve? = nil if let resolve = resolve { @@ -147,7 +144,7 @@ public class FieldBuilder { throw GraphQLError(message: "Expected context type \(Context.self) but got \(Swift.type(of: context))") } - return try resolve(s, NoArguments(), c, info) + return try resolve(s, NoArguments(), c, info).flatMap{ return c.next().newSucceededFuture(result: $0) } } } @@ -167,13 +164,13 @@ public class FieldBuilder { type: [TypeReference].Type = [TypeReference].self, description: String? = nil, deprecationReason: String? = nil - ) throws { + ) throws { let field = GraphQLField( type: try schema.getOutputType(from: [TypeReference].self, field: name), description: description, deprecationReason: deprecationReason ) - + fields[name] = field } @@ -182,8 +179,8 @@ public class FieldBuilder { type: O.Type = O.self, description: String? = nil, deprecationReason: String? = nil, - resolve: ResolveField? = nil - ) throws { + resolve: ResolveField>? = nil + ) throws { var r: GraphQLFieldResolve? = nil if let resolve = resolve { @@ -196,7 +193,7 @@ public class FieldBuilder { throw GraphQLError(message: "Expected context type \(Context.self) but got \(Swift.type(of: context))") } - return try resolve(s, NoArguments(), c, info) + return try resolve(s, NoArguments(), c, info).flatMap{ return c.next().newSucceededFuture(result: $0) } } } @@ -216,8 +213,8 @@ public class FieldBuilder { type: (O?).Type = (O?).self, description: String? = nil, deprecationReason: String? = nil, - resolve: ResolveField? = nil - ) throws { + resolve: ResolveField>? = nil + ) throws { let arguments = try schema.arguments(type: A.self, field: name) let field = GraphQLField( @@ -237,11 +234,7 @@ public class FieldBuilder { throw GraphQLError(message: "Expected context type \(Context.self) but got \(Swift.type(of: context))") } - guard let output = try resolve(s, a, c, info) else { - return nil - } - - return output + return try resolve(s, a, c, info).flatMap{ return c.next().newSucceededFuture(result: $0) } } } ) @@ -254,8 +247,8 @@ public class FieldBuilder { type: O.Type = O.self, description: String? = nil, deprecationReason: String? = nil, - resolve: ResolveField? = nil - ) throws { + resolve: ResolveField>? = nil + ) throws { let arguments = try schema.arguments(type: A.self, field: name) let field = GraphQLField( @@ -275,11 +268,11 @@ public class FieldBuilder { throw GraphQLError(message: "Expected context type \(Context.self) but got \(Swift.type(of: context))") } - return try resolve(s, a, c, info) + return try resolve(s, a, c, info).flatMap{ return c.next().newSucceededFuture(result: $0) } } } ) - + fields[name] = field } } diff --git a/Sources/Graphiti/Types/InputObjectType.swift b/Sources/Graphiti/Types/InputObjectType.swift index cf423bf1..e5bbe94d 100644 --- a/Sources/Graphiti/Types/InputObjectType.swift +++ b/Sources/Graphiti/Types/InputObjectType.swift @@ -1,7 +1,8 @@ import GraphQL import Runtime +import NIO -public final class InputObjectTypeBuilder { +public final class InputObjectTypeBuilder { var schema: SchemaBuilder init(schema: SchemaBuilder) { diff --git a/Sources/Graphiti/Types/InterfaceType.swift b/Sources/Graphiti/Types/InterfaceType.swift index 82ac25c8..e1ceb84c 100644 --- a/Sources/Graphiti/Types/InterfaceType.swift +++ b/Sources/Graphiti/Types/InterfaceType.swift @@ -1,4 +1,5 @@ import GraphQL +import NIO public typealias ResolveType = ( _ value: Value, @@ -6,7 +7,7 @@ public typealias ResolveType = ( _ info: GraphQLResolveInfo ) throws -> Any.Type -public final class InterfaceTypeBuilder : FieldBuilder { +public final class InterfaceTypeBuilder : FieldBuilder { public var description: String? = nil var resolveType: GraphQLTypeResolve? = nil diff --git a/Sources/Graphiti/Types/ObjectType.swift b/Sources/Graphiti/Types/ObjectType.swift index 0ac6206b..ef9b8d64 100644 --- a/Sources/Graphiti/Types/ObjectType.swift +++ b/Sources/Graphiti/Types/ObjectType.swift @@ -1,4 +1,5 @@ import GraphQL +import NIO public typealias IsTypeOf = ( _ source: S, @@ -6,7 +7,7 @@ public typealias IsTypeOf = ( _ info: GraphQLResolveInfo ) throws -> Bool -public final class ObjectTypeBuilder : FieldBuilder { +public final class ObjectTypeBuilder : FieldBuilder { public var description: String? = nil var isTypeOf: GraphQLIsTypeOf = { source, _, _ in From ec4faae8ccbe62cbd29294b2e5d2e4d42523ab77 Mon Sep 17 00:00:00 2001 From: Kim de Vos Date: Wed, 30 May 2018 10:42:21 +0200 Subject: [PATCH 2/7] Updated tests to support EventLoopFuture --- .../HelloWorldTests/HelloWorldTests.swift | 92 +++++++----- .../StarWarsIntrospectionTests.swift | 65 +++++++-- .../StarWarsTests/StarWarsQueryTests.swift | 133 ++++++++++++++---- .../StarWarsTests/StarWarsSchema.swift | 40 +++--- 4 files changed, 242 insertions(+), 88 deletions(-) diff --git a/Tests/GraphitiTests/HelloWorldTests/HelloWorldTests.swift b/Tests/GraphitiTests/HelloWorldTests/HelloWorldTests.swift index aff31c83..7452e135 100644 --- a/Tests/GraphitiTests/HelloWorldTests/HelloWorldTests.swift +++ b/Tests/GraphitiTests/HelloWorldTests/HelloWorldTests.swift @@ -1,6 +1,7 @@ import XCTest @testable import Graphiti import GraphQL +import NIO extension Float : InputType, OutputType { public init(map: Map) throws { @@ -13,26 +14,37 @@ extension Float : InputType, OutputType { } class HelloWorldTests : XCTestCase { - let schema = try! Schema { schema in + let schema = try! Schema { schema in try schema.query { query in - try query.field(name: "hello", type: String.self) { (_, _, _, _) -> String in - "world" + + try query.field(name: "hello", type: String.self) { (_, _, eventLoopGroup, _) in + return eventLoopGroup.next().newSucceededFuture(result: "world") } } } func testHello() throws { + let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + defer { + XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) + } + let query = "{ hello }" let expected: Map = [ "data": [ "hello": "world" ] ] - let result = try schema.execute(request: query) + let result = try schema.execute(request: query, eventLoopGroup: eventLoopGroup).wait() XCTAssertEqual(result, expected) } func testBoyhowdy() throws { + let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + defer { + XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) + } + let query = "{ boyhowdy }" let expectedErrors: Map = [ @@ -44,12 +56,17 @@ class HelloWorldTests : XCTestCase { ] ] - let result = try schema.execute(request: query) + let result = try schema.execute(request: query, eventLoopGroup: eventLoopGroup).wait() XCTAssertEqual(result, expectedErrors) } func testScalar() throws { - let schema = try Schema { schema in + let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + defer { + XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) + } + + let schema = try Schema { schema in try schema.scalar(type: Float.self) { scalar in scalar.description = "The `Float` scalar type represents signed double-precision fractional values as specified by [IEEE 754](http://en.wikipedia.org/wiki/IEEE_floating_point)." @@ -83,8 +100,8 @@ class HelloWorldTests : XCTestCase { let float: Float } - try query.field(name: "float", type: Float.self) { (_, arguments: FloatArguments, _, _) in - return arguments.float + try query.field(name: "float", type: Float.self) { (_, arguments: FloatArguments, eventLoopGroup, _) in + return eventLoopGroup.next().newSucceededFuture(result: arguments.float) } } } @@ -94,78 +111,81 @@ class HelloWorldTests : XCTestCase { var result: Map query = "query Query($float: Float!) { float(float: $float) }" - result = try schema.execute(request: query, variables: ["float": 4]) + result = try schema.execute(request: query, eventLoopGroup: eventLoopGroup, variables: ["float": 4]).wait() XCTAssertEqual(result, expected) query = "query Query { float(float: 4) }" - result = try schema.execute(request: query) + result = try schema.execute(request: query, eventLoopGroup: eventLoopGroup).wait() XCTAssertEqual(result, expected) } - + func testInput() throws { - + let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + defer { + XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) + } + struct Foo : OutputType { let id: String let name : String? - + static func fromInput(_ input: FooInput) -> Foo { return Foo(id: input.id, name: input.name) } } - + struct FooInput : InputType { let id: String let name : String? } - - let schema = try Schema { schema in - + + let schema = try Schema { schema in + try schema.object(type: Foo.self) { builder in - + try builder.exportFields() } - + try schema.query { query in - - try query.field(name: "foo", type: (Foo?).self) { (_,_,_,_) in - - return Foo(id: "123", name: "bar") + + try query.field(name: "foo", type: (Foo?).self) { (_,_,eventLoopGroup,_) in + return eventLoopGroup.next().newSucceededFuture(result: Foo(id: "123", name: "bar")) } } - + try schema.inputObject(type: FooInput.self) { builder in - + try builder.exportFields() } - + struct AddFooArguments : Arguments { - + let input: FooInput } - + try schema.mutation { mutation in - - try mutation.field(name: "addFoo", type: Foo.self) { (_, arguments: AddFooArguments, _, _) in - + + try mutation.field(name: "addFoo", type: Foo.self) { (_, arguments: AddFooArguments, eventLoopgroup, _) in + debugPrint(arguments) - return Foo.fromInput(arguments.input) + return eventLoopGroup.next().newSucceededFuture(result: Foo.fromInput(arguments.input)) } } - + } - + let mutation = "mutation addFoo($input: FooInput!) { addFoo(input:$input) { id, name } }" let variables: [String:Map] = ["input" : [ "id" : "123", "name" : "bob" ]] let expected: Map = ["data": ["addFoo" : [ "id" : "123", "name" : "bob" ]]] do { - let result = try schema.execute(request: mutation, variables: variables) + let result = try schema.execute(request: mutation, eventLoopGroup: eventLoopGroup, variables: variables).wait() XCTAssertEqual(result, expected) debugPrint(result) } catch { debugPrint(error) } - + } } diff --git a/Tests/GraphitiTests/StarWarsTests/StarWarsIntrospectionTests.swift b/Tests/GraphitiTests/StarWarsTests/StarWarsIntrospectionTests.swift index 9a630490..7e599034 100644 --- a/Tests/GraphitiTests/StarWarsTests/StarWarsIntrospectionTests.swift +++ b/Tests/GraphitiTests/StarWarsTests/StarWarsIntrospectionTests.swift @@ -1,8 +1,15 @@ import XCTest +import NIO + @testable import Graphiti class StarWarsIntrospectionTests : XCTestCase { func testIntrospectionTypeQuery() throws { + let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + defer { + XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) + } + let query = "query IntrospectionTypeQuery {" + " __schema {" + " types {" + @@ -139,11 +146,16 @@ class StarWarsIntrospectionTests : XCTestCase { ] #endif - let result = try starWarsSchema.execute(request: query) + let result = try starWarsSchema.execute(request: query, eventLoopGroup: eventLoopGroup).wait() XCTAssertEqual(result, expected) } func testIntrospectionQueryTypeQuery() throws { + let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + defer { + XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) + } + let query = "query IntrospectionQueryTypeQuery {" + " __schema {" + " queryType {" + @@ -162,11 +174,16 @@ class StarWarsIntrospectionTests : XCTestCase { ], ] - let result = try starWarsSchema.execute(request: query) + let result = try starWarsSchema.execute(request: query, eventLoopGroup: eventLoopGroup).wait() XCTAssertEqual(result, expected) } func testIntrospectionDroidTypeQuery() throws { + let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + defer { + XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) + } + let query = "query IntrospectionDroidTypeQuery {" + " __type(name: \"Droid\") {" + " name" + @@ -181,11 +198,16 @@ class StarWarsIntrospectionTests : XCTestCase { ], ] - let result = try starWarsSchema.execute(request: query) + let result = try starWarsSchema.execute(request: query, eventLoopGroup: eventLoopGroup).wait() XCTAssertEqual(result, expected) } func testIntrospectionDroidKindQuery() throws { + let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + defer { + XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) + } + let query = "query IntrospectionDroidKindQuery {" + " __type(name: \"Droid\") {" + " name" + @@ -202,11 +224,16 @@ class StarWarsIntrospectionTests : XCTestCase { ], ] - let result = try starWarsSchema.execute(request: query) + let result = try starWarsSchema.execute(request: query, eventLoopGroup: eventLoopGroup).wait() XCTAssertEqual(result, expected) } func testIntrospectionCharacterKindQuery() throws { + let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + defer { + XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) + } + let query = "query IntrospectionCharacterKindQuery {" + " __type(name: \"Character\") {" + " name" + @@ -223,11 +250,16 @@ class StarWarsIntrospectionTests : XCTestCase { ], ] - let result = try starWarsSchema.execute(request: query) + let result = try starWarsSchema.execute(request: query, eventLoopGroup: eventLoopGroup).wait() XCTAssertEqual(result, expected) } func testIntrospectionDroidFieldsQuery() throws { + let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + defer { + XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) + } + let query = "query IntrospectionDroidFieldsQuery {" + " __type(name: \"Droid\") {" + " name" + @@ -293,11 +325,16 @@ class StarWarsIntrospectionTests : XCTestCase { ], ] - let result = try starWarsSchema.execute(request: query) + let result = try starWarsSchema.execute(request: query, eventLoopGroup: eventLoopGroup).wait() XCTAssertEqual(result, expected) } func testIntrospectionDroidNestedFieldsQuery() throws { + let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + defer { + XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) + } + let query = "query IntrospectionDroidNestedFieldsQuery {" + " __type(name: \"Droid\") {" + " name" + @@ -388,11 +425,16 @@ class StarWarsIntrospectionTests : XCTestCase { ], ] - let result = try starWarsSchema.execute(request: query) + let result = try starWarsSchema.execute(request: query, eventLoopGroup: eventLoopGroup).wait() XCTAssertEqual(result, expected) } func testIntrospectionFieldArgsQuery() throws { + let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + defer { + XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) + } + let query = "query IntrospectionFieldArgsQuery {" + " __schema {" + " queryType {" + @@ -496,11 +538,16 @@ class StarWarsIntrospectionTests : XCTestCase { ], ] - let result = try starWarsSchema.execute(request: query) + let result = try starWarsSchema.execute(request: query, eventLoopGroup: eventLoopGroup).wait() XCTAssertEqual(result, expected) } func testIntrospectionDroidDescriptionQuery() throws { + let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + defer { + XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) + } + let query = "query IntrospectionDroidDescriptionQuery {" + " __type(name: \"Droid\") {" + " name" + @@ -517,7 +564,7 @@ class StarWarsIntrospectionTests : XCTestCase { ], ] - let result = try starWarsSchema.execute(request: query) + let result = try starWarsSchema.execute(request: query, eventLoopGroup: eventLoopGroup).wait() XCTAssertEqual(result, expected) } } diff --git a/Tests/GraphitiTests/StarWarsTests/StarWarsQueryTests.swift b/Tests/GraphitiTests/StarWarsTests/StarWarsQueryTests.swift index a72c665f..b3b16ad3 100644 --- a/Tests/GraphitiTests/StarWarsTests/StarWarsQueryTests.swift +++ b/Tests/GraphitiTests/StarWarsTests/StarWarsQueryTests.swift @@ -1,8 +1,14 @@ import XCTest +import NIO @testable import Graphiti class StarWarsQueryTests : XCTestCase { func testHeroNameQuery() throws { + let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + defer { + XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) + } + let query = "query HeroNameQuery {" + " hero {" + " name" + @@ -17,11 +23,16 @@ class StarWarsQueryTests : XCTestCase { ], ] - let result = try starWarsSchema.execute(request: query) + let result = try starWarsSchema.execute(request: query, eventLoopGroup: eventLoopGroup).wait() XCTAssertEqual(result, expected) } func testHeroNameAndFriendsQuery() throws { + let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + defer { + XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) + } + let query = "query HeroNameAndFriendsQuery {" + " hero {" + " id" + @@ -46,11 +57,16 @@ class StarWarsQueryTests : XCTestCase { ], ] - let result = try starWarsSchema.execute(request: query) + let result = try starWarsSchema.execute(request: query, eventLoopGroup: eventLoopGroup).wait() XCTAssertEqual(result, expected) } func testNestedQuery() throws { + let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + defer { + XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) + } + let query = "query NestedQuery {" + " hero {" + " name" + @@ -103,11 +119,16 @@ class StarWarsQueryTests : XCTestCase { ], ] - let result = try starWarsSchema.execute(request: query) + let result = try starWarsSchema.execute(request: query, eventLoopGroup: eventLoopGroup).wait() XCTAssertEqual(result, expected) } func testFetchLukeQuery() throws { + let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + defer { + XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) + } + let query = "query FetchLukeQuery {" + " human(id: \"1000\") {" + " name" + @@ -122,11 +143,16 @@ class StarWarsQueryTests : XCTestCase { ], ] - let result = try starWarsSchema.execute(request: query) + let result = try starWarsSchema.execute(request: query, eventLoopGroup: eventLoopGroup).wait() XCTAssertEqual(result, expected) } func testFetchSomeIDQuery() throws { + let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + defer { + XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) + } + let query = "query FetchSomeIDQuery($someId: String!) {" + " human(id: $someId) {" + " name" + @@ -149,7 +175,7 @@ class StarWarsQueryTests : XCTestCase { ], ] - result = try starWarsSchema.execute(request: query, variables: params) + result = try starWarsSchema.execute(request: query, eventLoopGroup: eventLoopGroup, variables: params).wait() XCTAssertEqual(result, expected) params = [ @@ -164,7 +190,7 @@ class StarWarsQueryTests : XCTestCase { ], ] - result = try starWarsSchema.execute(request: query, variables: params) + result = try starWarsSchema.execute(request: query, eventLoopGroup: eventLoopGroup, variables: params).wait() XCTAssertEqual(result, expected) @@ -178,11 +204,16 @@ class StarWarsQueryTests : XCTestCase { ], ] - result = try starWarsSchema.execute(request: query, variables: params) + result = try starWarsSchema.execute(request: query, eventLoopGroup: eventLoopGroup, variables: params).wait() XCTAssertEqual(result, expected) } func testFetchLukeAliasedQuery() throws { + let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + defer { + XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) + } + let query = "query FetchLukeAliasedQuery {" + " luke: human(id: \"1000\") {" + " name" + @@ -197,11 +228,16 @@ class StarWarsQueryTests : XCTestCase { ], ] - let result = try starWarsSchema.execute(request: query) + let result = try starWarsSchema.execute(request: query, eventLoopGroup: eventLoopGroup).wait() XCTAssertEqual(result, expected) } func testFetchLukeAndLeiaAliasedQuery() throws { + let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + defer { + XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) + } + let query = "query FetchLukeAndLeiaAliasedQuery {" + " luke: human(id: \"1000\") {" + " name" + @@ -222,11 +258,16 @@ class StarWarsQueryTests : XCTestCase { ], ] - let result = try starWarsSchema.execute(request: query) + let result = try starWarsSchema.execute(request: query, eventLoopGroup: eventLoopGroup).wait() XCTAssertEqual(result, expected) } func testDuplicateFieldsQuery() throws { + let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + defer { + XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) + } + let query = "query DuplicateFieldsQuery {" + " luke: human(id: \"1000\") {" + " name" + @@ -251,11 +292,16 @@ class StarWarsQueryTests : XCTestCase { ], ] - let result = try starWarsSchema.execute(request: query) + let result = try starWarsSchema.execute(request: query, eventLoopGroup: eventLoopGroup).wait() XCTAssertEqual(result, expected) } func testUseFragmentQuery() throws { + let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + defer { + XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) + } + let query = "query UseFragmentQuery {" + " luke: human(id: \"1000\") {" + " ...HumanFragment" + @@ -282,11 +328,16 @@ class StarWarsQueryTests : XCTestCase { ] ] - let result = try starWarsSchema.execute(request: query) + let result = try starWarsSchema.execute(request: query, eventLoopGroup: eventLoopGroup).wait() XCTAssertEqual(result, expected) } func testCheckTypeOfR2Query() throws { + let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + defer { + XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) + } + let query = "query CheckTypeOfR2Query {" + " hero {" + " __typename" + @@ -303,11 +354,16 @@ class StarWarsQueryTests : XCTestCase { ], ] - let result = try starWarsSchema.execute(request: query) + let result = try starWarsSchema.execute(request: query, eventLoopGroup: eventLoopGroup).wait() XCTAssertEqual(result, expected) } func testCheckTypeOfLukeQuery() throws { + let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + defer { + XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) + } + let query = "query CheckTypeOfLukeQuery {" + " hero(episode: EMPIRE) {" + " __typename" + @@ -324,11 +380,16 @@ class StarWarsQueryTests : XCTestCase { ], ] - let result = try starWarsSchema.execute(request: query) + let result = try starWarsSchema.execute(request: query, eventLoopGroup: eventLoopGroup).wait() XCTAssertEqual(result, expected) } func testSecretBackstoryQuery() throws { + let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + defer { + XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) + } + let query = "query SecretBackstoryQuery {\n" + " hero {\n" + " name\n" + @@ -352,11 +413,16 @@ class StarWarsQueryTests : XCTestCase { ], ] - let result = try starWarsSchema.execute(request: query) + let result = try starWarsSchema.execute(request: query, eventLoopGroup: eventLoopGroup).wait() XCTAssertEqual(result, expected) } func testSecretBackstoryListQuery() throws { + let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + defer { + XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) + } + let query = "query SecretBackstoryListQuery {\n" + " hero {\n" + " name\n" + @@ -406,11 +472,16 @@ class StarWarsQueryTests : XCTestCase { ], ] - let result = try starWarsSchema.execute(request: query) + let result = try starWarsSchema.execute(request: query, eventLoopGroup: eventLoopGroup).wait() XCTAssertEqual(result, expected) } func testSecretBackstoryAliasQuery() throws { + let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + defer { + XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) + } + let query = "query SecretBackstoryAliasQuery {\n" + " mainHero: hero {\n" + " name\n" + @@ -434,24 +505,29 @@ class StarWarsQueryTests : XCTestCase { ] ] - let result = try starWarsSchema.execute(request: query) + let result = try starWarsSchema.execute(request: query, eventLoopGroup: eventLoopGroup).wait() XCTAssertEqual(result, expected) } func testNonNullableFieldsQuery() throws { - let schema = try Schema { schema in + let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + defer { + XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) + } + + let schema = try Schema { schema in struct A : OutputType {} try schema.object(type: A.self) { a in - try a.field(name: "nullableA", type: (TypeReference?).self) { (_, _, _, _) -> A? - in A() + try a.field(name: "nullableA", type: (TypeReference?).self) { (_, _, eventLoopGroup, _) in + eventLoopGroup.next().newSucceededFuture(result: A()) } - try a.field(name: "nonNullA", type: TypeReference.self) { (_, _, _, _) -> A - in A() + try a.field(name: "nonNullA", type: TypeReference.self) { (_, _, eventLoopGroup, _) in + eventLoopGroup.next().newSucceededFuture(result: A()) } - try a.field(name: "throws", type: String.self) { (_, _, _, _) -> String in + try a.field(name: "throws", type: String.self) { (_, _, _, _) in struct 🏃 : Error, CustomStringConvertible { let description: String } @@ -461,8 +537,8 @@ class StarWarsQueryTests : XCTestCase { } try schema.query { query in - try query.field(name: "nullableA", type: (A?).self) { (_, _, _, _) -> A? in - A() + try query.field(name: "nullableA", type: (A?).self) { (_, _, eventLoopGroup, _) in + eventLoopGroup.next().newSucceededFuture(result: A()) } } } @@ -495,11 +571,16 @@ class StarWarsQueryTests : XCTestCase { ], ] - let result = try schema.execute(request: query) + let result = try schema.execute(request: query, eventLoopGroup: eventLoopGroup).wait() XCTAssertEqual(result, expected) } func testSearchQuery() throws { + let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + defer { + XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) + } + let query = "query {" + " search(query: \"o\") {" + " ... on Planet {" + @@ -527,7 +608,7 @@ class StarWarsQueryTests : XCTestCase { ], ] - let result = try starWarsSchema.execute(request: query) + let result = try starWarsSchema.execute(request: query, eventLoopGroup: eventLoopGroup).wait() XCTAssertEqual(result, expected) } } diff --git a/Tests/GraphitiTests/StarWarsTests/StarWarsSchema.swift b/Tests/GraphitiTests/StarWarsTests/StarWarsSchema.swift index 3785845c..84ea1781 100644 --- a/Tests/GraphitiTests/StarWarsTests/StarWarsSchema.swift +++ b/Tests/GraphitiTests/StarWarsTests/StarWarsSchema.swift @@ -1,4 +1,5 @@ import Graphiti +import NIO /** * This is designed to be an end-to-end test, demonstrating @@ -73,7 +74,7 @@ extension Planet: OutputType {} import GraphQL -let starWarsSchema = try! Schema { schema in +let starWarsSchema = try! Schema { schema in /** * The original trilogy consists of three movies. * @@ -199,8 +200,8 @@ let starWarsSchema = try! Schema { schema in name: "friends", type: [Character].self, description: "The friends of the human, or an empty list if they have none.", - resolve: { human, _, _, _ in - getFriends(character: human) + resolve: { human, _, eventLoopGroup, _ in + return eventLoopGroup.next().newSucceededFuture(result: getFriends(character: human)) } ) @@ -208,8 +209,8 @@ let starWarsSchema = try! Schema { schema in name: "secretBackstory", type: (String?).self, description: "Where are they from and how they came to be who they are.", - resolve: { _, _, _, _ in - try getSecretBackStory() + resolve: { _, _, eventLoopGroup, _ in + return eventLoopGroup.next().newSucceededFuture(result: try getSecretBackStory()) } ) } @@ -237,8 +238,9 @@ let starWarsSchema = try! Schema { schema in name: "friends", type: [Character].self, description: "The friends of the droid, or an empty list if they have none.", - resolve: { droid, _, _, _ in - getFriends(character: droid) + resolve: { droid, _, eventLoopGroup, _ in + return eventLoopGroup.next().newSucceededFuture(result: getFriends(character: droid)) + } ) @@ -246,8 +248,8 @@ let starWarsSchema = try! Schema { schema in name: "secretBackstory", type: (String?).self, description: "Where are they from and how they came to be who they are.", - resolve: { _, _, _, _ in - try getSecretBackStory() + resolve: { _, _, eventLoopGroup, _ in + return eventLoopGroup.next().newSucceededFuture(result: try getSecretBackStory()) } ) } @@ -287,8 +289,9 @@ let starWarsSchema = try! Schema { schema in ] } - try query.field(name: "hero") { (_, arguments: HeroArguments, _, _) in - getHero(episode: arguments.episode) + try query.field(name: "hero") { (_, arguments: HeroArguments, eventLoopGroup, _) in + return eventLoopGroup.next().newSucceededFuture(result: getHero(episode: arguments.episode)) + } struct HumanArguments : Arguments { @@ -296,8 +299,9 @@ let starWarsSchema = try! Schema { schema in static let descriptions = ["id": "id of the human"] } - try query.field(name: "human") { (_, arguments: HumanArguments, _, _) in - getHuman(id: arguments.id) + try query.field(name: "human") { (_, arguments: HumanArguments, eventLoopGroup, _) in + return eventLoopGroup.next().newSucceededFuture(result: getHuman(id: arguments.id)) + } struct DroidArguments : Arguments { @@ -305,8 +309,9 @@ let starWarsSchema = try! Schema { schema in static let descriptions = ["id": "id of the droid"] } - try query.field(name: "droid") { (_, arguments: DroidArguments, _, _) in - getDroid(id: arguments.id) + try query.field(name: "droid") { (_, arguments: DroidArguments, eventLoopGroup, _) in + return eventLoopGroup.next().newSucceededFuture(result: getDroid(id: arguments.id)) + } struct SearchArguments : Arguments { @@ -314,8 +319,9 @@ let starWarsSchema = try! Schema { schema in static let descriptions = ["query": "text to find"] } - try query.field(name: "search") { (_, arguments: SearchArguments, _, _) in - search(for: arguments.query) + try query.field(name: "search") { (_, arguments: SearchArguments, eventLoopGroup, _) in + return eventLoopGroup.next().newSucceededFuture(result: search(for: arguments.query)) + } } From a1947219faea596ee6c47a5e8281e4ff30132c91 Mon Sep 17 00:00:00 2001 From: Kim de Vos Date: Wed, 30 May 2018 18:12:50 +0200 Subject: [PATCH 3/7] Updated swift package --- Package.resolved | 39 +++++++++++++++++++++++++++++++++------ Package.swift | 4 ++-- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/Package.resolved b/Package.resolved index d4394b94..fba0f829 100644 --- a/Package.resolved +++ b/Package.resolved @@ -2,12 +2,21 @@ "object": { "pins": [ { - "package": "GraphQL", - "repositoryURL": "https://github.com/GraphQLSwift/GraphQL.git", + "package": "Core", + "repositoryURL": "https://github.com/vapor/core.git", "state": { "branch": null, - "revision": "faa869cdf0214cf25aa8df1081891b5e8647d6df", - "version": "0.5.0" + "revision": "3b72f2cc3fb21d505fbe97215418951a8e4a2871", + "version": "3.2.1" + } + }, + { + "package": "GraphQL", + "repositoryURL": "https://github.com/kimdv/GraphQL.git", + "state": { + "branch": "master", + "revision": "9f4456e2b8f04e9cbfd0fe0250fc4bcd6ffad729", + "version": null } }, { @@ -15,8 +24,26 @@ "repositoryURL": "https://github.com/wickwirew/Runtime.git", "state": { "branch": null, - "revision": "9f9e3078fff093adbd8f43df1052ee5d68b05c2a", - "version": "0.6.0" + "revision": "23357609f0df427d870bb4bd22ac14e0a4ea1346", + "version": "0.7.1" + } + }, + { + "package": "swift-nio", + "repositoryURL": "https://github.com/apple/swift-nio.git", + "state": { + "branch": null, + "revision": "77dc77b9b5cdddfb3c385c5ee6cb74153d284967", + "version": "1.7.2" + } + }, + { + "package": "swift-nio-zlib-support", + "repositoryURL": "https://github.com/apple/swift-nio-zlib-support.git", + "state": { + "branch": null, + "revision": "37760e9a52030bb9011972c5213c3350fa9d41fd", + "version": "1.0.0" } } ] diff --git a/Package.swift b/Package.swift index 96abb64b..468b13fc 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:4.0 +// swift-tools-version:4.1 import PackageDescription let package = Package( @@ -9,7 +9,7 @@ let package = Package( ], dependencies: [ - .package(url: "https://github.com/GraphQLSwift/GraphQL.git", from: "0.5.0"), + .package(url: "https://github.com/kimdv/GraphQL.git", .branch("master")), ], targets: [ From 76dc287d7863f2b50440bc7746cd33d33dd4da3f Mon Sep 17 00:00:00 2001 From: Kim de Vos Date: Fri, 1 Jun 2018 23:13:42 +0200 Subject: [PATCH 4/7] Readded context again --- Package.resolved | 2 +- Sources/Graphiti/Schema/Schema.swift | 40 +++++------ Sources/Graphiti/Types/Field.swift | 69 +++++++++++++------ Sources/Graphiti/Types/InputObjectType.swift | 6 +- Sources/Graphiti/Types/InterfaceType.swift | 2 +- Sources/Graphiti/Types/ObjectType.swift | 2 +- .../HelloWorldTests/HelloWorldTests.swift | 14 ++-- .../StarWarsTests/StarWarsQueryTests.swift | 10 +-- .../StarWarsTests/StarWarsSchema.swift | 18 ++--- 9 files changed, 94 insertions(+), 69 deletions(-) diff --git a/Package.resolved b/Package.resolved index fba0f829..fb3ce63e 100644 --- a/Package.resolved +++ b/Package.resolved @@ -15,7 +15,7 @@ "repositoryURL": "https://github.com/kimdv/GraphQL.git", "state": { "branch": "master", - "revision": "9f4456e2b8f04e9cbfd0fe0250fc4bcd6ffad729", + "revision": "3bbca7112389496e116772f29cd9022ff13480c0", "version": null } }, diff --git a/Sources/Graphiti/Schema/Schema.swift b/Sources/Graphiti/Schema/Schema.swift index f684fb43..09800a12 100644 --- a/Sources/Graphiti/Schema/Schema.swift +++ b/Sources/Graphiti/Schema/Schema.swift @@ -2,7 +2,7 @@ import GraphQL import Runtime import NIO -public final class SchemaBuilder { +public final class SchemaBuilder { var graphQLTypeMap: [AnyType: GraphQLType] = [ AnyType(Int.self): GraphQLInt, AnyType(Double.self): GraphQLFloat, @@ -19,8 +19,8 @@ public final class SchemaBuilder { init() {} - public func query(name: String = "Query", build: (ObjectTypeBuilder) throws -> Void) throws { - let builder = ObjectTypeBuilder(schema: self) + public func query(name: String = "Query", build: (ObjectTypeBuilder) throws -> Void) throws { + let builder = ObjectTypeBuilder(schema: self) try build(builder) query = try GraphQLObjectType( @@ -31,8 +31,8 @@ public final class SchemaBuilder { ) } - public func mutation(name: String = "Mutation", build: (ObjectTypeBuilder) throws -> Void) throws { - let builder = ObjectTypeBuilder(schema: self) + public func mutation(name: String = "Mutation", build: (ObjectTypeBuilder) throws -> Void) throws { + let builder = ObjectTypeBuilder(schema: self) try build(builder) mutation = try GraphQLObjectType( @@ -43,8 +43,8 @@ public final class SchemaBuilder { ) } - public func subscription(name: String = "Subscription", build: (ObjectTypeBuilder) throws -> Void) throws { - let builder = ObjectTypeBuilder(schema: self) + public func subscription(name: String = "Subscription", build: (ObjectTypeBuilder) throws -> Void) throws { + let builder = ObjectTypeBuilder(schema: self) try build(builder) subscription = try GraphQLObjectType( @@ -58,7 +58,7 @@ public final class SchemaBuilder { public func object( type: Type.Type, interfaces: Any.Type..., - build: (ObjectTypeBuilder) throws -> Void + build: (ObjectTypeBuilder) throws -> Void ) throws { let name = fixName(String(describing: Type.self)) try `object`(name: name, type: type, interfaces: interfaces, build: build) @@ -68,7 +68,7 @@ public final class SchemaBuilder { type: Type.Type, name: String, interfaces: Any.Type..., - build: (ObjectTypeBuilder) throws -> Void + build: (ObjectTypeBuilder) throws -> Void ) throws { try `object`(name: name, type: type, interfaces: interfaces, build: build) } @@ -77,9 +77,9 @@ public final class SchemaBuilder { name: String, type: Type.Type, interfaces: [Any.Type], - build: (ObjectTypeBuilder) throws -> Void + build: (ObjectTypeBuilder) throws -> Void ) throws { - let builder = ObjectTypeBuilder(schema: self) + let builder = ObjectTypeBuilder(schema: self) try build(builder) let objectType = try GraphQLObjectType( @@ -95,7 +95,7 @@ public final class SchemaBuilder { public func inputObject( type: Type.Type, - build: (InputObjectTypeBuilder) throws -> Void + build: (InputObjectTypeBuilder) throws -> Void ) throws { let name = fixName(String(describing: Type.self)) try inputObject(name: name, type: type, build: build) @@ -104,9 +104,9 @@ public final class SchemaBuilder { public func inputObject( name: String, type: Type.Type, - build: (InputObjectTypeBuilder) throws -> Void + build: (InputObjectTypeBuilder) throws -> Void ) throws { - let builder = InputObjectTypeBuilder(schema: self) + let builder = InputObjectTypeBuilder(schema: self) try build(builder) let inputObjectType = try GraphQLInputObjectType( @@ -120,7 +120,7 @@ public final class SchemaBuilder { public func interface( type: Type.Type, - build: (InterfaceTypeBuilder) throws -> Void + build: (InterfaceTypeBuilder) throws -> Void ) throws { let name = fixName(String(describing: Type.self)) try interface(name: name, type: type, build: build) @@ -129,9 +129,9 @@ public final class SchemaBuilder { public func interface( name: String, type: Type.Type, - build: (InterfaceTypeBuilder) throws -> Void + build: (InterfaceTypeBuilder) throws -> Void ) throws { - let builder = InterfaceTypeBuilder(schema: self) + let builder = InterfaceTypeBuilder(schema: self) try build(builder) let interfaceType = try GraphQLInterfaceType( @@ -491,11 +491,11 @@ extension SchemaBuilder { public typealias NoRoot = Void public typealias NoContext = Void -public struct Schema { +public struct Schema { let schema: GraphQLSchema - public init(_ build: (SchemaBuilder) throws -> Void) throws { - let builder = SchemaBuilder() + public init(_ build: (SchemaBuilder) throws -> Void) throws { + let builder = SchemaBuilder() try build(builder) guard let query = builder.query else { diff --git a/Sources/Graphiti/Types/Field.swift b/Sources/Graphiti/Types/Field.swift index da0a3394..f8731f5f 100644 --- a/Sources/Graphiti/Types/Field.swift +++ b/Sources/Graphiti/Types/Field.swift @@ -25,17 +25,18 @@ public struct NoArguments : Arguments { public init(map: Map) throws {} } -public typealias ResolveField = ( +public typealias ResolveField = ( _ source: S, _ args: A, _ context: C, + _ eventLoopGroup: E, _ info: GraphQLResolveInfo ) throws -> R -public class FieldBuilder { - var schema: SchemaBuilder +public class FieldBuilder { + var schema: SchemaBuilder - init(schema: SchemaBuilder) { + init(schema: SchemaBuilder) { self.schema = schema } @@ -62,12 +63,12 @@ public class FieldBuilder { type: (TypeReference?).Type = (TypeReference?).self, description: String? = nil, deprecationReason: String? = nil, - resolve: ResolveField>? = nil + resolve: ResolveField>? = nil ) throws { var r: GraphQLFieldResolve? = nil if let resolve = resolve { - r = { source, _, context, info in + r = { source, _, context, eventLoopGroup, info in guard let s = source as? Type else { throw GraphQLError(message: "Expected source type \(Type.self) but got \(Swift.type(of: source))") } @@ -76,7 +77,11 @@ public class FieldBuilder { throw GraphQLError(message: "Expected context type \(Context.self) but got \(Swift.type(of: context))") } - return try resolve(s, NoArguments(), c, info).flatMap{ return c.next().newSucceededFuture(result: $0) } + guard let e = eventLoopGroup as? EventLoop else { + throw GraphQLError(message: "Expected eventloop type \(EventLoop.self) but got \(Swift.type(of: eventLoopGroup))") + } + + return try resolve(s, NoArguments(), c, e, info).flatMap{ return e.next().newSucceededFuture(result: $0) } } } @@ -96,12 +101,12 @@ public class FieldBuilder { type: TypeReference.Type = TypeReference.self, description: String? = nil, deprecationReason: String? = nil, - resolve: ResolveField>? = nil + resolve: ResolveField>? = nil ) throws { var r: GraphQLFieldResolve? = nil if let resolve = resolve { - r = { source, _, context, info in + r = { source, _, context, eventLoopGroup, info in guard let s = source as? Type else { throw GraphQLError(message: "Expected source type \(Type.self) but got \(Swift.type(of: source))") } @@ -110,7 +115,11 @@ public class FieldBuilder { throw GraphQLError(message: "Expected context type \(Context.self) but got \(Swift.type(of: context))") } - return try resolve(s, NoArguments(), c, info).flatMap{ return c.next().newSucceededFuture(result: $0) } + guard let e = eventLoopGroup as? EventLoop else { + throw GraphQLError(message: "Expected eventloop type \(EventLoop.self) but got \(Swift.type(of: eventLoopGroup))") + } + + return try resolve(s, NoArguments(), c, e, info).flatMap{ return e.next().newSucceededFuture(result: $0) } } } @@ -130,12 +139,12 @@ public class FieldBuilder { type: [TypeReference].Type = [TypeReference].self, description: String? = nil, deprecationReason: String? = nil, - resolve: ResolveField>? = nil + resolve: ResolveField>? = nil ) throws { var r: GraphQLFieldResolve? = nil if let resolve = resolve { - r = { source, _, context, info in + r = { source, _, context, eventLoopGroup, info in guard let s = source as? Type else { throw GraphQLError(message: "Expected source type \(Type.self) but got \(Swift.type(of: source))") } @@ -144,7 +153,11 @@ public class FieldBuilder { throw GraphQLError(message: "Expected context type \(Context.self) but got \(Swift.type(of: context))") } - return try resolve(s, NoArguments(), c, info).flatMap{ return c.next().newSucceededFuture(result: $0) } + guard let e = eventLoopGroup as? EventLoop else { + throw GraphQLError(message: "Expected eventloop type \(EventLoop.self) but got \(Swift.type(of: eventLoopGroup))") + } + + return try resolve(s, NoArguments(), c, e, info).flatMap{ return e.next().newSucceededFuture(result: $0) } } } @@ -179,12 +192,12 @@ public class FieldBuilder { type: O.Type = O.self, description: String? = nil, deprecationReason: String? = nil, - resolve: ResolveField>? = nil + resolve: ResolveField>? = nil ) throws { var r: GraphQLFieldResolve? = nil if let resolve = resolve { - r = { source, _, context, info in + r = { source, _, context, eventLoopGroup, info in guard let s = source as? Type else { throw GraphQLError(message: "Expected source type \(Type.self) but got \(Swift.type(of: source))") } @@ -193,7 +206,11 @@ public class FieldBuilder { throw GraphQLError(message: "Expected context type \(Context.self) but got \(Swift.type(of: context))") } - return try resolve(s, NoArguments(), c, info).flatMap{ return c.next().newSucceededFuture(result: $0) } + guard let e = eventLoopGroup as? EventLoop else { + throw GraphQLError(message: "Expected eventloop type \(EventLoop.self) but got \(Swift.type(of: eventLoopGroup))") + } + + return try resolve(s, NoArguments(), c, e, info).flatMap{ return e.next().newSucceededFuture(result: $0) } } } @@ -213,7 +230,7 @@ public class FieldBuilder { type: (O?).Type = (O?).self, description: String? = nil, deprecationReason: String? = nil, - resolve: ResolveField>? = nil + resolve: ResolveField>? = nil ) throws { let arguments = try schema.arguments(type: A.self, field: name) @@ -223,7 +240,7 @@ public class FieldBuilder { deprecationReason: deprecationReason, args: arguments, resolve: resolve.map { resolve in - return { source, args, context, info in + return { source, args, context, eventLoopGroup, info in guard let s = source as? Type else { throw GraphQLError(message: "Expected source type \(Type.self) but got \(Swift.type(of: source))") } @@ -234,7 +251,11 @@ public class FieldBuilder { throw GraphQLError(message: "Expected context type \(Context.self) but got \(Swift.type(of: context))") } - return try resolve(s, a, c, info).flatMap{ return c.next().newSucceededFuture(result: $0) } + guard let e = eventLoopGroup as? EventLoop else { + throw GraphQLError(message: "Expected eventloop type \(EventLoop.self) but got \(Swift.type(of: eventLoopGroup))") + } + + return try resolve(s, a, c, e, info).flatMap{ return e.next().newSucceededFuture(result: $0) } } } ) @@ -247,7 +268,7 @@ public class FieldBuilder { type: O.Type = O.self, description: String? = nil, deprecationReason: String? = nil, - resolve: ResolveField>? = nil + resolve: ResolveField>? = nil ) throws { let arguments = try schema.arguments(type: A.self, field: name) @@ -257,7 +278,7 @@ public class FieldBuilder { deprecationReason: deprecationReason, args: arguments, resolve: resolve.map { resolve in - return { source, args, context, info in + return { source, args, context, eventLoopGroup, info in guard let s = source as? Type else { throw GraphQLError(message: "Expected type \(Type.self) but got \(Swift.type(of: source))") } @@ -268,7 +289,11 @@ public class FieldBuilder { throw GraphQLError(message: "Expected context type \(Context.self) but got \(Swift.type(of: context))") } - return try resolve(s, a, c, info).flatMap{ return c.next().newSucceededFuture(result: $0) } + guard let e = eventLoopGroup as? EventLoop else { + throw GraphQLError(message: "Expected eventloop type \(EventLoop.self) but got \(Swift.type(of: eventLoopGroup))") + } + + return try resolve(s, a, c, e, info).flatMap{ return e.next().newSucceededFuture(result: $0) } } } ) diff --git a/Sources/Graphiti/Types/InputObjectType.swift b/Sources/Graphiti/Types/InputObjectType.swift index e5bbe94d..65b856b2 100644 --- a/Sources/Graphiti/Types/InputObjectType.swift +++ b/Sources/Graphiti/Types/InputObjectType.swift @@ -2,10 +2,10 @@ import GraphQL import Runtime import NIO -public final class InputObjectTypeBuilder { - var schema: SchemaBuilder +public final class InputObjectTypeBuilder { + var schema: SchemaBuilder - init(schema: SchemaBuilder) { + init(schema: SchemaBuilder) { self.schema = schema } diff --git a/Sources/Graphiti/Types/InterfaceType.swift b/Sources/Graphiti/Types/InterfaceType.swift index e1ceb84c..a1f85a79 100644 --- a/Sources/Graphiti/Types/InterfaceType.swift +++ b/Sources/Graphiti/Types/InterfaceType.swift @@ -7,7 +7,7 @@ public typealias ResolveType = ( _ info: GraphQLResolveInfo ) throws -> Any.Type -public final class InterfaceTypeBuilder : FieldBuilder { +public final class InterfaceTypeBuilder : FieldBuilder { public var description: String? = nil var resolveType: GraphQLTypeResolve? = nil diff --git a/Sources/Graphiti/Types/ObjectType.swift b/Sources/Graphiti/Types/ObjectType.swift index ef9b8d64..24e713ad 100644 --- a/Sources/Graphiti/Types/ObjectType.swift +++ b/Sources/Graphiti/Types/ObjectType.swift @@ -7,7 +7,7 @@ public typealias IsTypeOf = ( _ info: GraphQLResolveInfo ) throws -> Bool -public final class ObjectTypeBuilder : FieldBuilder { +public final class ObjectTypeBuilder : FieldBuilder { public var description: String? = nil var isTypeOf: GraphQLIsTypeOf = { source, _, _ in diff --git a/Tests/GraphitiTests/HelloWorldTests/HelloWorldTests.swift b/Tests/GraphitiTests/HelloWorldTests/HelloWorldTests.swift index 7452e135..eefe1d18 100644 --- a/Tests/GraphitiTests/HelloWorldTests/HelloWorldTests.swift +++ b/Tests/GraphitiTests/HelloWorldTests/HelloWorldTests.swift @@ -14,10 +14,10 @@ extension Float : InputType, OutputType { } class HelloWorldTests : XCTestCase { - let schema = try! Schema { schema in + let schema = try! Schema { schema in try schema.query { query in - try query.field(name: "hello", type: String.self) { (_, _, eventLoopGroup, _) in + try query.field(name: "hello", type: String.self) { (_, _, _, eventLoopGroup, _) in return eventLoopGroup.next().newSucceededFuture(result: "world") } } @@ -66,7 +66,7 @@ class HelloWorldTests : XCTestCase { XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) } - let schema = try Schema { schema in + let schema = try Schema { schema in try schema.scalar(type: Float.self) { scalar in scalar.description = "The `Float` scalar type represents signed double-precision fractional values as specified by [IEEE 754](http://en.wikipedia.org/wiki/IEEE_floating_point)." @@ -100,7 +100,7 @@ class HelloWorldTests : XCTestCase { let float: Float } - try query.field(name: "float", type: Float.self) { (_, arguments: FloatArguments, eventLoopGroup, _) in + try query.field(name: "float", type: Float.self) { (_, arguments: FloatArguments, _, eventLoopGroup, _) in return eventLoopGroup.next().newSucceededFuture(result: arguments.float) } } @@ -139,7 +139,7 @@ class HelloWorldTests : XCTestCase { let name : String? } - let schema = try Schema { schema in + let schema = try Schema { schema in try schema.object(type: Foo.self) { builder in @@ -148,7 +148,7 @@ class HelloWorldTests : XCTestCase { try schema.query { query in - try query.field(name: "foo", type: (Foo?).self) { (_,_,eventLoopGroup,_) in + try query.field(name: "foo", type: (Foo?).self) { (_, _, _, eventLoopGroup, _) in return eventLoopGroup.next().newSucceededFuture(result: Foo(id: "123", name: "bar")) } } @@ -165,7 +165,7 @@ class HelloWorldTests : XCTestCase { try schema.mutation { mutation in - try mutation.field(name: "addFoo", type: Foo.self) { (_, arguments: AddFooArguments, eventLoopgroup, _) in + try mutation.field(name: "addFoo", type: Foo.self) { (_, arguments: AddFooArguments, _, eventLoopgroup, _) in debugPrint(arguments) return eventLoopGroup.next().newSucceededFuture(result: Foo.fromInput(arguments.input)) diff --git a/Tests/GraphitiTests/StarWarsTests/StarWarsQueryTests.swift b/Tests/GraphitiTests/StarWarsTests/StarWarsQueryTests.swift index b3b16ad3..14368b86 100644 --- a/Tests/GraphitiTests/StarWarsTests/StarWarsQueryTests.swift +++ b/Tests/GraphitiTests/StarWarsTests/StarWarsQueryTests.swift @@ -515,19 +515,19 @@ class StarWarsQueryTests : XCTestCase { XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) } - let schema = try Schema { schema in + let schema = try Schema { schema in struct A : OutputType {} try schema.object(type: A.self) { a in - try a.field(name: "nullableA", type: (TypeReference?).self) { (_, _, eventLoopGroup, _) in + try a.field(name: "nullableA", type: (TypeReference?).self) { (_, _, _, eventLoopGroup, _) in eventLoopGroup.next().newSucceededFuture(result: A()) } - try a.field(name: "nonNullA", type: TypeReference.self) { (_, _, eventLoopGroup, _) in + try a.field(name: "nonNullA", type: TypeReference.self) { (_, _, _, eventLoopGroup, _) in eventLoopGroup.next().newSucceededFuture(result: A()) } - try a.field(name: "throws", type: String.self) { (_, _, _, _) in + try a.field(name: "throws", type: String.self) { (_, _, _, _, _) in struct 🏃 : Error, CustomStringConvertible { let description: String } @@ -537,7 +537,7 @@ class StarWarsQueryTests : XCTestCase { } try schema.query { query in - try query.field(name: "nullableA", type: (A?).self) { (_, _, eventLoopGroup, _) in + try query.field(name: "nullableA", type: (A?).self) { (_, _, _, eventLoopGroup, _) in eventLoopGroup.next().newSucceededFuture(result: A()) } } diff --git a/Tests/GraphitiTests/StarWarsTests/StarWarsSchema.swift b/Tests/GraphitiTests/StarWarsTests/StarWarsSchema.swift index 84ea1781..e704f077 100644 --- a/Tests/GraphitiTests/StarWarsTests/StarWarsSchema.swift +++ b/Tests/GraphitiTests/StarWarsTests/StarWarsSchema.swift @@ -74,7 +74,7 @@ extension Planet: OutputType {} import GraphQL -let starWarsSchema = try! Schema { schema in +let starWarsSchema = try! Schema { schema in /** * The original trilogy consists of three movies. * @@ -200,7 +200,7 @@ let starWarsSchema = try! Schema { schema i name: "friends", type: [Character].self, description: "The friends of the human, or an empty list if they have none.", - resolve: { human, _, eventLoopGroup, _ in + resolve: { human, _, _, eventLoopGroup, _ in return eventLoopGroup.next().newSucceededFuture(result: getFriends(character: human)) } ) @@ -209,7 +209,7 @@ let starWarsSchema = try! Schema { schema i name: "secretBackstory", type: (String?).self, description: "Where are they from and how they came to be who they are.", - resolve: { _, _, eventLoopGroup, _ in + resolve: { _, _, _, eventLoopGroup, _ in return eventLoopGroup.next().newSucceededFuture(result: try getSecretBackStory()) } ) @@ -238,7 +238,7 @@ let starWarsSchema = try! Schema { schema i name: "friends", type: [Character].self, description: "The friends of the droid, or an empty list if they have none.", - resolve: { droid, _, eventLoopGroup, _ in + resolve: { droid, _, _, eventLoopGroup, _ in return eventLoopGroup.next().newSucceededFuture(result: getFriends(character: droid)) } @@ -248,7 +248,7 @@ let starWarsSchema = try! Schema { schema i name: "secretBackstory", type: (String?).self, description: "Where are they from and how they came to be who they are.", - resolve: { _, _, eventLoopGroup, _ in + resolve: { _, _, _, eventLoopGroup, _ in return eventLoopGroup.next().newSucceededFuture(result: try getSecretBackStory()) } ) @@ -289,7 +289,7 @@ let starWarsSchema = try! Schema { schema i ] } - try query.field(name: "hero") { (_, arguments: HeroArguments, eventLoopGroup, _) in + try query.field(name: "hero") { (_, arguments: HeroArguments, _, eventLoopGroup, _) in return eventLoopGroup.next().newSucceededFuture(result: getHero(episode: arguments.episode)) } @@ -299,7 +299,7 @@ let starWarsSchema = try! Schema { schema i static let descriptions = ["id": "id of the human"] } - try query.field(name: "human") { (_, arguments: HumanArguments, eventLoopGroup, _) in + try query.field(name: "human") { (_, arguments: HumanArguments, _, eventLoopGroup, _) in return eventLoopGroup.next().newSucceededFuture(result: getHuman(id: arguments.id)) } @@ -309,7 +309,7 @@ let starWarsSchema = try! Schema { schema i static let descriptions = ["id": "id of the droid"] } - try query.field(name: "droid") { (_, arguments: DroidArguments, eventLoopGroup, _) in + try query.field(name: "droid") { (_, arguments: DroidArguments, _, eventLoopGroup, _) in return eventLoopGroup.next().newSucceededFuture(result: getDroid(id: arguments.id)) } @@ -319,7 +319,7 @@ let starWarsSchema = try! Schema { schema i static let descriptions = ["query": "text to find"] } - try query.field(name: "search") { (_, arguments: SearchArguments, eventLoopGroup, _) in + try query.field(name: "search") { (_, arguments: SearchArguments, _, eventLoopGroup, _) in return eventLoopGroup.next().newSucceededFuture(result: search(for: arguments.query)) } From 05a477f4c94c1f80428bd595f123b7e7f72936e5 Mon Sep 17 00:00:00 2001 From: Kim de Vos Date: Tue, 12 Jun 2018 15:19:54 +0200 Subject: [PATCH 5/7] Updated to correct GraphQLSwift --- Package.resolved | 16 ++++++++-------- Package.swift | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Package.resolved b/Package.resolved index fb3ce63e..b4030d7c 100644 --- a/Package.resolved +++ b/Package.resolved @@ -6,17 +6,17 @@ "repositoryURL": "https://github.com/vapor/core.git", "state": { "branch": null, - "revision": "3b72f2cc3fb21d505fbe97215418951a8e4a2871", - "version": "3.2.1" + "revision": "174f909bc048a6aff27d6cb4c31810971f912cca", + "version": "3.2.2" } }, { "package": "GraphQL", - "repositoryURL": "https://github.com/kimdv/GraphQL.git", + "repositoryURL": "https://github.com/GraphQLSwift/GraphQL.git", "state": { - "branch": "master", - "revision": "3bbca7112389496e116772f29cd9022ff13480c0", - "version": null + "branch": null, + "revision": "1ab3c9050cb0aea4350dbc343454bb8c83adff34", + "version": "0.6.0" } }, { @@ -33,8 +33,8 @@ "repositoryURL": "https://github.com/apple/swift-nio.git", "state": { "branch": null, - "revision": "77dc77b9b5cdddfb3c385c5ee6cb74153d284967", - "version": "1.7.2" + "revision": "695afc5205aaa49fca092b94b479ff71c43d9d3c", + "version": "1.8.0" } }, { diff --git a/Package.swift b/Package.swift index 468b13fc..ac8c1afe 100644 --- a/Package.swift +++ b/Package.swift @@ -9,7 +9,7 @@ let package = Package( ], dependencies: [ - .package(url: "https://github.com/kimdv/GraphQL.git", .branch("master")), + .package(url: "https://github.com/GraphQLSwift/GraphQL.git", from: "0.6.0"), ], targets: [ From c2071446610404d7f95a92c14bfcc1a36925352b Mon Sep 17 00:00:00 2001 From: Kim de Vos Date: Tue, 12 Jun 2018 15:20:48 +0200 Subject: [PATCH 6/7] Removed warnings --- .../HelloWorldTests/HelloWorldTests.swift | 8 ++--- .../StarWarsIntrospectionTests.swift | 18 +++++------ .../StarWarsTests/StarWarsQueryTests.swift | 32 +++++++++---------- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/Tests/GraphitiTests/HelloWorldTests/HelloWorldTests.swift b/Tests/GraphitiTests/HelloWorldTests/HelloWorldTests.swift index eefe1d18..2edf866d 100644 --- a/Tests/GraphitiTests/HelloWorldTests/HelloWorldTests.swift +++ b/Tests/GraphitiTests/HelloWorldTests/HelloWorldTests.swift @@ -24,7 +24,7 @@ class HelloWorldTests : XCTestCase { } func testHello() throws { - let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) defer { XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) } @@ -40,7 +40,7 @@ class HelloWorldTests : XCTestCase { } func testBoyhowdy() throws { - let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) defer { XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) } @@ -61,7 +61,7 @@ class HelloWorldTests : XCTestCase { } func testScalar() throws { - let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) defer { XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) } @@ -120,7 +120,7 @@ class HelloWorldTests : XCTestCase { } func testInput() throws { - let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) defer { XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) } diff --git a/Tests/GraphitiTests/StarWarsTests/StarWarsIntrospectionTests.swift b/Tests/GraphitiTests/StarWarsTests/StarWarsIntrospectionTests.swift index 7e599034..fc9d769f 100644 --- a/Tests/GraphitiTests/StarWarsTests/StarWarsIntrospectionTests.swift +++ b/Tests/GraphitiTests/StarWarsTests/StarWarsIntrospectionTests.swift @@ -5,7 +5,7 @@ import NIO class StarWarsIntrospectionTests : XCTestCase { func testIntrospectionTypeQuery() throws { - let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) defer { XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) } @@ -151,7 +151,7 @@ class StarWarsIntrospectionTests : XCTestCase { } func testIntrospectionQueryTypeQuery() throws { - let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) defer { XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) } @@ -179,7 +179,7 @@ class StarWarsIntrospectionTests : XCTestCase { } func testIntrospectionDroidTypeQuery() throws { - let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) defer { XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) } @@ -203,7 +203,7 @@ class StarWarsIntrospectionTests : XCTestCase { } func testIntrospectionDroidKindQuery() throws { - let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) defer { XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) } @@ -229,7 +229,7 @@ class StarWarsIntrospectionTests : XCTestCase { } func testIntrospectionCharacterKindQuery() throws { - let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) defer { XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) } @@ -255,7 +255,7 @@ class StarWarsIntrospectionTests : XCTestCase { } func testIntrospectionDroidFieldsQuery() throws { - let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) defer { XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) } @@ -330,7 +330,7 @@ class StarWarsIntrospectionTests : XCTestCase { } func testIntrospectionDroidNestedFieldsQuery() throws { - let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) defer { XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) } @@ -430,7 +430,7 @@ class StarWarsIntrospectionTests : XCTestCase { } func testIntrospectionFieldArgsQuery() throws { - let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) defer { XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) } @@ -543,7 +543,7 @@ class StarWarsIntrospectionTests : XCTestCase { } func testIntrospectionDroidDescriptionQuery() throws { - let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) defer { XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) } diff --git a/Tests/GraphitiTests/StarWarsTests/StarWarsQueryTests.swift b/Tests/GraphitiTests/StarWarsTests/StarWarsQueryTests.swift index 14368b86..00a46c5b 100644 --- a/Tests/GraphitiTests/StarWarsTests/StarWarsQueryTests.swift +++ b/Tests/GraphitiTests/StarWarsTests/StarWarsQueryTests.swift @@ -4,7 +4,7 @@ import NIO class StarWarsQueryTests : XCTestCase { func testHeroNameQuery() throws { - let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) defer { XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) } @@ -28,7 +28,7 @@ class StarWarsQueryTests : XCTestCase { } func testHeroNameAndFriendsQuery() throws { - let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) defer { XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) } @@ -62,7 +62,7 @@ class StarWarsQueryTests : XCTestCase { } func testNestedQuery() throws { - let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) defer { XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) } @@ -124,7 +124,7 @@ class StarWarsQueryTests : XCTestCase { } func testFetchLukeQuery() throws { - let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) defer { XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) } @@ -148,7 +148,7 @@ class StarWarsQueryTests : XCTestCase { } func testFetchSomeIDQuery() throws { - let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) defer { XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) } @@ -209,7 +209,7 @@ class StarWarsQueryTests : XCTestCase { } func testFetchLukeAliasedQuery() throws { - let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) defer { XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) } @@ -233,7 +233,7 @@ class StarWarsQueryTests : XCTestCase { } func testFetchLukeAndLeiaAliasedQuery() throws { - let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) defer { XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) } @@ -263,7 +263,7 @@ class StarWarsQueryTests : XCTestCase { } func testDuplicateFieldsQuery() throws { - let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) defer { XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) } @@ -297,7 +297,7 @@ class StarWarsQueryTests : XCTestCase { } func testUseFragmentQuery() throws { - let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) defer { XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) } @@ -333,7 +333,7 @@ class StarWarsQueryTests : XCTestCase { } func testCheckTypeOfR2Query() throws { - let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) defer { XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) } @@ -359,7 +359,7 @@ class StarWarsQueryTests : XCTestCase { } func testCheckTypeOfLukeQuery() throws { - let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) defer { XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) } @@ -385,7 +385,7 @@ class StarWarsQueryTests : XCTestCase { } func testSecretBackstoryQuery() throws { - let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) defer { XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) } @@ -418,7 +418,7 @@ class StarWarsQueryTests : XCTestCase { } func testSecretBackstoryListQuery() throws { - let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) defer { XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) } @@ -477,7 +477,7 @@ class StarWarsQueryTests : XCTestCase { } func testSecretBackstoryAliasQuery() throws { - let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) defer { XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) } @@ -510,7 +510,7 @@ class StarWarsQueryTests : XCTestCase { } func testNonNullableFieldsQuery() throws { - let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) defer { XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) } @@ -576,7 +576,7 @@ class StarWarsQueryTests : XCTestCase { } func testSearchQuery() throws { - let eventLoopGroup = MultiThreadedEventLoopGroup(numThreads: 1) + let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) defer { XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) } From 962cf8e0553b77e56f75472478d1affcc0b6b1c6 Mon Sep 17 00:00:00 2001 From: Kim de Vos Date: Tue, 12 Jun 2018 15:22:26 +0200 Subject: [PATCH 7/7] Now require swift4.0 instead of swift 4.1 --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index ac8c1afe..14d54ccb 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:4.1 +// swift-tools-version:4.0 import PackageDescription let package = Package(