diff --git a/README.md b/README.md index 4db10de..bb03df2 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # GraphQLVapor +***WARNING***: This package is in v0.x beta. It's API is still evolving and is subject to breaking changes in minor version bumps. + A Swift library for integrating [GraphQL](https://github.com/GraphQLSwift/GraphQL) with [Vapor](https://github.com/vapor/vapor), enabling you to easily expose GraphQL APIs in your Vapor applications. ## Features diff --git a/Sources/GraphQLVapor/GraphQLHandler.swift b/Sources/GraphQLVapor/GraphQLHandler.swift index 48e63a9..ac7477b 100644 --- a/Sources/GraphQLVapor/GraphQLHandler.swift +++ b/Sources/GraphQLVapor/GraphQLHandler.swift @@ -6,15 +6,18 @@ struct GraphQLHandler< WebSocketInit: Equatable & Codable & Sendable >: Sendable { let schema: GraphQLSchema + let rootValue: any Sendable let config: GraphQLConfig let computeContext: @Sendable (Request) async throws -> Context init( schema: GraphQLSchema, + rootValue: any Sendable, config: GraphQLConfig, computeContext: @Sendable @escaping (Request) async throws -> Context ) { self.schema = schema + self.rootValue = rootValue self.config = config self.computeContext = computeContext } diff --git a/Sources/GraphQLVapor/HTTP/GraphQLHandler+HTTP.swift b/Sources/GraphQLVapor/HTTP/GraphQLHandler+HTTP.swift index 13efe20..a03b4b5 100644 --- a/Sources/GraphQLVapor/HTTP/GraphQLHandler+HTTP.swift +++ b/Sources/GraphQLVapor/HTTP/GraphQLHandler+HTTP.swift @@ -53,6 +53,7 @@ extension GraphQLHandler { result = try await graphql( schema: schema, request: graphQLRequest.query, + rootValue: rootValue, context: context, variableValues: graphQLRequest.variables, operationName: graphQLRequest.operationName, diff --git a/Sources/GraphQLVapor/RoutesBuilder+graphql.swift b/Sources/GraphQLVapor/RoutesBuilder+graphql.swift index cb0e037..3033a48 100644 --- a/Sources/GraphQLVapor/RoutesBuilder+graphql.swift +++ b/Sources/GraphQLVapor/RoutesBuilder+graphql.swift @@ -15,6 +15,7 @@ public extension RoutesBuilder { /// - Parameters: /// - path: The route that should respond to GraphQL requests. Both `GET` and `POST` routes are registered. /// - schema: The GraphQL schema that should be used to respond to requests. + /// - rootValue: The `rootValue` GraphQL execution arg. This is the object passed to the root resolvers. /// - config: GraphQL Handler configuration options. See type documentation for details. /// - computeContext: A closure used to compute the GraphQL context from incoming requests. This must be provided. func graphql< @@ -23,6 +24,7 @@ public extension RoutesBuilder { >( _ path: [PathComponent] = ["graphql"], schema: GraphQLSchema, + rootValue: any Sendable = (), config: GraphQLConfig = GraphQLConfig(), computeContext: @Sendable @escaping (Request) async throws -> Context ) { @@ -30,7 +32,7 @@ public extension RoutesBuilder { ContentConfiguration.global.use(decoder: JSONDecoder(), for: .jsonGraphQL) // https://github.com/graphql/graphql-over-http/blob/main/spec/GraphQLOverHTTP.md#request - let handler = GraphQLHandler(schema: schema, config: config, computeContext: computeContext) + let handler = GraphQLHandler(schema: schema, rootValue: rootValue, config: config, computeContext: computeContext) get(path) { request in // WebSocket handling if diff --git a/Sources/GraphQLVapor/WebSocket/GraphQLHandler+handleWebSocket.swift b/Sources/GraphQLVapor/WebSocket/GraphQLHandler+handleWebSocket.swift index 5107ad7..e0d6f2a 100644 --- a/Sources/GraphQLVapor/WebSocket/GraphQLHandler+handleWebSocket.swift +++ b/Sources/GraphQLVapor/WebSocket/GraphQLHandler+handleWebSocket.swift @@ -47,6 +47,7 @@ extension GraphQLHandler { try await graphql( schema: schema, request: graphQLRequest.query, + rootValue: rootValue, context: context, variableValues: graphQLRequest.variables, operationName: graphQLRequest.operationName @@ -56,6 +57,7 @@ extension GraphQLHandler { try await graphqlSubscribe( schema: schema, request: graphQLRequest.query, + rootValue: rootValue, context: context, variableValues: graphQLRequest.variables, operationName: graphQLRequest.operationName @@ -71,6 +73,7 @@ extension GraphQLHandler { try await graphql( schema: schema, request: graphQLRequest.query, + rootValue: rootValue, context: context, variableValues: graphQLRequest.variables, operationName: graphQLRequest.operationName @@ -80,6 +83,7 @@ extension GraphQLHandler { try await graphqlSubscribe( schema: schema, request: graphQLRequest.query, + rootValue: rootValue, context: context, variableValues: graphQLRequest.variables, operationName: graphQLRequest.operationName