Skip to content

Commit

Permalink
Move enableGraphiQL functions to RoutesBuilder extension. Fixes #9
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsteinerde committed Mar 7, 2023
1 parent 28ec96c commit a9c44f9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![Vapor Version](https://img.shields.io/badge/Vapor-4-F6CBCA.svg)](http://vapor.codes)
[![build](https://github.com/alexsteinerde/graphiql-vapor/workflows/build/badge.svg)](https://github.com/alexsteinerde/graphiql-vapor/actions)

This package ships functionality to add the [GraphiQL](https://github.com/graphql/graphiql) GraphQL web editor and request-tester page to an `Application` instance in Vapor.
This package ships functionality to add the [GraphiQL](https://github.com/graphql/graphiql) GraphQL web editor and request-tester page to an `RoutesBuilder` instance in Vapor.

## Installation
```swift
Expand All @@ -30,7 +30,7 @@ let package = Package(
app.enableGraphiQL()

```
This will register the web page on `GET /`. If you want to have GraphiQL available on another route, call `app.enableGraphiQL(on: "/graphiQL)` instead.
This will register the web page on `GET /`. If you want to have GraphiQL available on another route, call `app.enableGraphiQL(on: "/graphiQL)` or `app.grouped("graphiQL").enableGraphiQL()` instead.

## License
This project is available under the MIT license. See the LICENSE file for more info.
Expand Down
2 changes: 1 addition & 1 deletion Sources/GraphiQLVapor/GraphiQLVapor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extension Request {
}
}

public extension Application {
public extension RoutesBuilder {
func enableGraphiQL(on pathComponents: PathComponent..., method: HTTPMethod = .GET, credentials: GraphiQLCredentialMode = .sameOrigin, serverPath: PathComponent = "/graphql") {
self.on(method, pathComponents) { (request) -> Response in
request.serve(html: grahphiQLHTML(path: serverPath, credentialMode: credentials))
Expand Down
11 changes: 11 additions & 0 deletions Tests/GraphiQLVaporTests/GraphiQLVaporTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,15 @@ final class GraphiQLVaporTests: XCTestCase {
XCTAssertEqual(res.status, HTTPResponseStatus.ok)
}
}

func testRegisterOnRoutesBuilder() throws {
let app = Application(.testing)
defer { app.shutdown() }

app.grouped("test").enableGraphiQL()

try app.testable().test(.GET, "/test") { res in
XCTAssertEqual(res.status, HTTPResponseStatus.ok)
}
}
}

0 comments on commit a9c44f9

Please sign in to comment.