Skip to content

Commit

Permalink
Merge pull request #5 from doofyus/master
Browse files Browse the repository at this point in the history
Add GraphQL server path customization
  • Loading branch information
alexsteinerde authored Jun 4, 2021
2 parents c88ceec + 33a7fac commit c0003d3
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Sources/GraphiQLVapor/GraphiQLVapor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,21 @@ extension Request {
}

public extension Application {
func enableGraphiQL(on pathComponents: PathComponent..., method: HTTPMethod = .GET) {
func enableGraphiQL(on pathComponents: PathComponent..., method: HTTPMethod = .GET, serverPath: PathComponent = "/graphql") {
graphQLServerPath = serverPath

self.on(method, pathComponents) { (request) -> Response in
request.serve(html: grahphiQLHTML)
}
}

func enableGraphiQL(method: HTTPMethod = .GET) {
self.enableGraphiQL(on: "", method: .GET)
self.enableGraphiQL(on: "", method: .GET, serverPath: "/graphql")
}
}

var graphQLServerPath: PathComponent = "/graphql"

let grahphiQLHTML = """
<!--
* Copyright (c) Facebook, Inc.
Expand Down Expand Up @@ -134,7 +138,7 @@ let grahphiQLHTML = """
function graphQLFetcher(graphQLParams) {
// This example expects a GraphQL server at the path /graphql.
// Change this to point wherever you host your GraphQL server.
return fetch('/graphql', {
return fetch('\(graphQLServerPath)', {
method: 'post',
headers: {
'Accept': 'application/json',
Expand Down

0 comments on commit c0003d3

Please sign in to comment.