Skip to content

Commit 2133893

Browse files
committed
add ExecutionContext
1 parent 19d8869 commit 2133893

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

Sources/Example/configure.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import StarWars
44

55
/// Called before your application initializes.
66
public func configure(_ config: inout Config, _ env: inout Vapor.Environment, _ services: inout Services) throws {
7-
let httpGraphQL = HTTPGraphQL() { req -> ExecutionContext in
8-
return (
7+
let httpGraphQL = HTTPGraphQL() { req in
8+
return ExecutionContext(
99
schema: starWarsSchema,
10-
rootValue: [:],
11-
context: req
10+
rootValue: (),
11+
context: (),
12+
eventLoopGroup: req
1213
)
1314
}
1415
services.register(httpGraphQL, as: GraphQLService.self)

Sources/VaporGraphQL/HTTPGraphQL.swift

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,19 @@ import Vapor
22
import GraphQL
33
import Graphiti
44

5-
public typealias ExecutionContext = (
6-
schema: GraphQLSchema,
7-
rootValue: Any,
8-
context: Any
9-
)
5+
public struct ExecutionContext {
6+
public let schema: GraphQLSchema
7+
public let rootValue: Any
8+
public let context: Any
9+
public let eventLoopGroup: EventLoopGroup
10+
11+
public init(schema: GraphQLSchema, rootValue: Any, context: Any, eventLoopGroup: EventLoopGroup) {
12+
self.schema = schema
13+
self.rootValue = rootValue
14+
self.context = context
15+
self.eventLoopGroup = eventLoopGroup
16+
}
17+
}
1018

1119
/// Provides HTTPGraphQL an execution context to perform per request.
1220
public typealias ExecutionContextProvider = (Request) throws -> ExecutionContext
@@ -33,15 +41,15 @@ public struct HTTPGraphQL: GraphQLService {
3341
return self.executeIntrospectionQuery(for: req)
3442
}
3543
do {
36-
let (schema, rootValue, context) = try self.executionContextProvider(req)
44+
let executionContext = try self.executionContextProvider(req)
3745
let result = try graphql(
38-
schema: schema,
39-
request: executionRequest.query,
40-
rootValue: rootValue,
41-
context: context,
42-
eventLoopGroup: req,
43-
variableValues: executionRequest.variables,
44-
operationName: executionRequest.operationName)
46+
schema: executionContext.schema,
47+
request: executionRequest.query,
48+
rootValue: executionContext.rootValue,
49+
context: executionContext.context,
50+
eventLoopGroup: executionContext.eventLoopGroup,
51+
variableValues: executionRequest.variables,
52+
operationName: executionRequest.operationName)
4553
return result
4654
} catch let e as GraphQLError {
4755
let graphQLError: [String: Map] = [

0 commit comments

Comments
 (0)