Provides a simple route collection to integrate GraphQLSwift into a Vapor application.
Add GraphQLRouteCollection to your Package.swift
import PackageDescription
let package = Package(
dependencies: [
...
.package(url: "https://github.com/stevenlambion/GraphQLRouteCollection.git", .upToNextMajor(from: "0.0.1")),
],
.target(
name: "App",
dependencies: [..., "GraphQLRouteCollection"],
),
)
Add the GraphQLRouteCollection to your droplet. Your schema, rootValue, and context are provided through a closure to allow per request dynamic execution. A common use case is setting up dataloaders for each request.
import Vapor
import GraphQLRouteCollection
extension Droplet {
func setupRoutes() throws {
// By default, the collection uses "graphql" as its path.
// Pass a custom path as the first argument to change it.
try collection(
GraphQLRouteCollection() { req in (
schema: schema,
rootValue: [:],
context: [:]
)}
)
}
}
Enables the GraphiQL IDE when a user accesses the graphql path in a web browser.
GraphQLRouteCollection(enableGraphiQL: true) { req in (
schema: schema,
rootValue: [:],
context: [:]
)}
The route collection enables a quick way to introspect your entire graphql schema. This is useful in development when you need to auto-generate a schema for graphql clients such as Apollo. Here's an example of how to enable for development use.
GraphQLRouteCollection(enableIntrospectionQuery: true) { req in (
schema: schema,
rootValue: [:],
context: [:]
)}
To retrieve the introspected schema simply hit the graphql endpoint without a provided query. It will instead use an internal introspection query.
fetch("localhost:8080/graphql") { resp in
let schema = parseSchema(resp.json)
}
GraphQLRouteCollection("graphql", enableGraphiQL: true, enableIntrospectionQuery: true) { req in (
schema: schema,
rootValue: [:],
context: ["dataLoaders": createDataLoaders(req)]
)}
This project is released under the MIT license. See LICENSE for details.