Skip to content

Commit 7c03ecb

Browse files
committed
First public package version
0 parents  commit 7c03ecb

15 files changed

+641
-0
lines changed

.circleci/config.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
version: 2
2+
3+
jobs:
4+
linux:
5+
docker:
6+
- image: swift:latest
7+
steps:
8+
- checkout
9+
- run: apt-get -qq update && apt-get -q -y install libpq-dev libssl-dev zlib1g-dev
10+
- run:
11+
name: Compile code
12+
command: swift build
13+
- run:
14+
name: Run unit tests
15+
command: swift test
16+
17+
linux-release:
18+
docker:
19+
- image: swift:latest
20+
steps:
21+
- checkout
22+
- run: apt-get -qq update && apt-get -q -y install libpq-dev libssl-dev zlib1g-dev
23+
- run:
24+
name: Compile code with optimizations
25+
command: swift build -c release
26+
27+
linux-nightly-5.2:
28+
docker:
29+
- image: swiftlang/swift:nightly-5.2
30+
steps:
31+
- checkout
32+
- run: apt-get -qq update && apt-get -q -y install libpq-dev libssl-dev zlib1g-dev
33+
- run:
34+
name: Compile code
35+
command: swift build
36+
- run:
37+
name: Run unit tests
38+
command: swift test
39+
40+
linux-nightly-5.2-release:
41+
docker:
42+
- image: swiftlang/swift:nightly-5.2
43+
steps:
44+
- checkout
45+
- run: apt-get -qq update && apt-get -q -y install libpq-dev libssl-dev zlib1g-dev
46+
- run:
47+
name: Compile code with optimizations
48+
command: swift build -c release
49+
50+
workflows:
51+
version: 2
52+
tests:
53+
jobs:
54+
- linux
55+
- linux-release
56+
- linux-nightly-5.2
57+
- linux-nightly-5.2-release

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.DS_Store
2+
/.build
3+
/Packages
4+
/*.xcodeproj
5+
xcuserdata/i
6+
.swiftpm/

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2020 Alexander Steiner
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Package.resolved

Lines changed: 196 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// swift-tools-version:5.1
2+
3+
import PackageDescription
4+
5+
let package = Package(
6+
name: "GraphQLKit",
7+
products: [
8+
.library(
9+
name: "GraphQLKit",
10+
targets: ["GraphQLKit"]),
11+
],
12+
dependencies: [
13+
.package(url: "https://github.com/alexsteinerde/Graphiti.git", from: "0.12.1"),
14+
.package(url: "https://github.com/vapor/vapor.git", from: "3.0.0"),
15+
],
16+
targets: [
17+
.target(name: "GraphQLKit", dependencies: ["Vapor", "Graphiti"]),
18+
.testTarget(name: "GraphQLKitTests",dependencies: ["GraphQLKit"]),
19+
]
20+
)

README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# GraphQLKit
2+
[![Language](https://img.shields.io/badge/Swift-5.1-brightgreen.svg)](http://swift.org)
3+
[![Vapor Version](https://img.shields.io/badge/Vapor-3-F6CBCA.svg)](http://vapor.codes)
4+
[![CircleCI](https://circleci.com/gh/alexsteinerde/graphql-kit.svg?style=shield)](https://circleci.com/gh/alexsteinerde/graphql-kit)
5+
6+
7+
Easy setup of a GraphQL server with Vapor. It uses the GraphQL implementation of [Graphiti](https://github.com/alexsteinerde/Graphiti).
8+
9+
## Features
10+
- [x] Arguments, operation name and query support
11+
- [x] Normal access to the `Request` object as in normal Vapor request handlers
12+
- [x] Accept JSON in the body of a POST request as the GraphQL query
13+
- [x] POST and GET support
14+
- [ ] Accept `application/graphql` content type requests
15+
- [ ] Downloadable schema file
16+
- [ ] Multi-Resolver support
17+
18+
## Installation
19+
```Swift
20+
import PackageDescription
21+
22+
let package = Package(
23+
dependencies: [
24+
.package(url: "https://github.com/alexsteinerde/graphql-kit.git", from: "1.0.0"),
25+
],
26+
targets: [
27+
.target(name: "App", dependencies: [<#T##Other Dependencies#>, "GraphQLKit"]),
28+
...
29+
]
30+
)
31+
```
32+
33+
## Getting Started
34+
### Define your schema
35+
This package is setup to accept only `Request` objects as the context object for the schema. This gives the opportunity to access all functionality that Vapor provides, for example authentication, service management and database access. To see an example implementation please have a look at the [`vapor-graphql-template`](https://github.com/alexsteinerde/vapor-graphql-template) repository.
36+
This package only provides the needed functions to register an existing GraphQL schema on a Vapor application. To define your schema please refer to the [Graphiti](https://github.com/alexsteinerde/Graphiti) documentations.
37+
But by including this package some other helper functions are exposed:
38+
39+
#### Async Resolver
40+
An `EventLoopGroup` parameter is no longer required for async resolvers as the `Request` context object already provides access to it's `EventLoopGroup` attribute `eventLoop`.
41+
42+
```Swift
43+
// Instead of adding an unnecessary parameter
44+
func getAllTodos(store: Request, arguments: NoArguments, _: EventLoopGroup) throws -> EventLoopFuture<[Todo]> {
45+
Todo.query(on: store).all()
46+
}
47+
48+
// You don't need to provide the eventLoopGroup parameter even when resolving a future.
49+
func getAllTodos(store: Request, arguments: NoArguments) throws -> EventLoopFuture<[Todo]> {
50+
Todo.query(on: store).all()
51+
}
52+
```
53+
54+
### Register the schema on the router
55+
In your configure.swift file call the `register(graphQLSchema: <#T##Schema<FieldKeyProvider, Request>#>, withResolver: <#T##FieldKeyProvider#>)`. By default this registers the GET and POST endpoints at `/graphql`. But you can also pass the optional parameter `at:` and override the default value.
56+
57+
```Swift
58+
let router = EngineRouter.default()
59+
60+
// Register the schema and it's resolver.
61+
router.register(graphQLSchema: todoSchema, withResolver: TodoAPI())
62+
63+
services.register(router, as: Router.self)
64+
```
65+
66+
## License
67+
This project is released under the MIT license. See [LICENSE](LICENSE) for details.
68+
69+
## Contribution
70+
You can contribute to this project by submitting a detailed issue or by forking this project and sending a pull request. Contributions of any kind are very welcome :)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import GraphQL
2+
import Vapor
3+
4+
extension GraphQLError: Debuggable {
5+
public var identifier: String {
6+
"GraphQLError"
7+
}
8+
9+
public var reason: String {
10+
message
11+
}
12+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import GraphQL
2+
3+
struct QueryRequest: Codable {
4+
var query: String
5+
var operationName: String?
6+
var variables: [String: Map]?
7+
}

0 commit comments

Comments
 (0)