Skip to content

Commit

Permalink
First public package version
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsteinerde committed Jan 25, 2020
0 parents commit 7c03ecb
Show file tree
Hide file tree
Showing 15 changed files with 641 additions and 0 deletions.
57 changes: 57 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
version: 2

jobs:
linux:
docker:
- image: swift:latest
steps:
- checkout
- run: apt-get -qq update && apt-get -q -y install libpq-dev libssl-dev zlib1g-dev
- run:
name: Compile code
command: swift build
- run:
name: Run unit tests
command: swift test

linux-release:
docker:
- image: swift:latest
steps:
- checkout
- run: apt-get -qq update && apt-get -q -y install libpq-dev libssl-dev zlib1g-dev
- run:
name: Compile code with optimizations
command: swift build -c release

linux-nightly-5.2:
docker:
- image: swiftlang/swift:nightly-5.2
steps:
- checkout
- run: apt-get -qq update && apt-get -q -y install libpq-dev libssl-dev zlib1g-dev
- run:
name: Compile code
command: swift build
- run:
name: Run unit tests
command: swift test

linux-nightly-5.2-release:
docker:
- image: swiftlang/swift:nightly-5.2
steps:
- checkout
- run: apt-get -qq update && apt-get -q -y install libpq-dev libssl-dev zlib1g-dev
- run:
name: Compile code with optimizations
command: swift build -c release

workflows:
version: 2
tests:
jobs:
- linux
- linux-release
- linux-nightly-5.2
- linux-nightly-5.2-release
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.DS_Store
/.build
/Packages
/*.xcodeproj
xcuserdata/i
.swiftpm/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2020 Alexander Steiner

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
196 changes: 196 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
{
"object": {
"pins": [
{
"package": "Console",
"repositoryURL": "https://github.com/vapor/console.git",
"state": {
"branch": null,
"revision": "74cfbea629d4aac34a97cead2447a6870af1950b",
"version": "3.1.1"
}
},
{
"package": "Core",
"repositoryURL": "https://github.com/vapor/core.git",
"state": {
"branch": null,
"revision": "10d33362a47fab03a067e78fb0791341d9c634fa",
"version": "3.9.3"
}
},
{
"package": "CRuntime",
"repositoryURL": "https://github.com/wickwirew/CRuntime.git",
"state": {
"branch": null,
"revision": "95f911318d8c885f6fc05e971471f94adfd39405",
"version": "2.1.2"
}
},
{
"package": "Crypto",
"repositoryURL": "https://github.com/vapor/crypto.git",
"state": {
"branch": null,
"revision": "df8eb7d8ae51787b3a0628aa3975e67666da936c",
"version": "3.3.3"
}
},
{
"package": "DatabaseKit",
"repositoryURL": "https://github.com/vapor/database-kit.git",
"state": {
"branch": null,
"revision": "8f352c8e66dab301ab9bfef912a01ce1361ba1e4",
"version": "1.3.3"
}
},
{
"package": "Graphiti",
"repositoryURL": "https://github.com/alexsteinerde/Graphiti.git",
"state": {
"branch": null,
"revision": "a44c615d9f1632fe403d7c9721d33cc7ce684b4c",
"version": "0.12.1"
}
},
{
"package": "GraphQL",
"repositoryURL": "https://github.com/alexsteinerde/GraphQL.git",
"state": {
"branch": null,
"revision": "be0d2940c1a91e8b6f4de091a27c12d0f513d83f",
"version": "0.12.1"
}
},
{
"package": "HTTP",
"repositoryURL": "https://github.com/vapor/http.git",
"state": {
"branch": null,
"revision": "3808ed0401379b6e9f4a053f03090ea9d658caa9",
"version": "3.2.1"
}
},
{
"package": "Multipart",
"repositoryURL": "https://github.com/vapor/multipart.git",
"state": {
"branch": null,
"revision": "f063180d0b84832accd33194e06ed3c41f8609ac",
"version": "3.1.1"
}
},
{
"package": "Routing",
"repositoryURL": "https://github.com/vapor/routing.git",
"state": {
"branch": null,
"revision": "d76f339c9716785e5079af9d7075d28ff7da3d92",
"version": "3.1.0"
}
},
{
"package": "Runtime",
"repositoryURL": "https://github.com/wickwirew/Runtime.git",
"state": {
"branch": null,
"revision": "61c9776f47d2951bdc562486ad348e5e1ca2e180",
"version": "2.1.1"
}
},
{
"package": "Service",
"repositoryURL": "https://github.com/vapor/service.git",
"state": {
"branch": null,
"revision": "fa5b5de62bd68bcde9a69933f31319e46c7275fb",
"version": "1.0.2"
}
},
{
"package": "swift-nio",
"repositoryURL": "https://github.com/apple/swift-nio.git",
"state": {
"branch": null,
"revision": "ba7970fe396e8198b84c6c1b44b38a1d4e2eb6bd",
"version": "1.14.1"
}
},
{
"package": "swift-nio-ssl",
"repositoryURL": "https://github.com/apple/swift-nio-ssl.git",
"state": {
"branch": null,
"revision": "0f3999f3e3c359cc74480c292644c3419e44a12f",
"version": "1.4.0"
}
},
{
"package": "swift-nio-ssl-support",
"repositoryURL": "https://github.com/apple/swift-nio-ssl-support.git",
"state": {
"branch": null,
"revision": "c02eec4e0e6d351cd092938cf44195a8e669f555",
"version": "1.0.0"
}
},
{
"package": "swift-nio-zlib-support",
"repositoryURL": "https://github.com/apple/swift-nio-zlib-support.git",
"state": {
"branch": null,
"revision": "37760e9a52030bb9011972c5213c3350fa9d41fd",
"version": "1.0.0"
}
},
{
"package": "TemplateKit",
"repositoryURL": "https://github.com/vapor/template-kit.git",
"state": {
"branch": null,
"revision": "51405c83e95e8adb09565278a5e9b959c605e56c",
"version": "1.4.0"
}
},
{
"package": "URLEncodedForm",
"repositoryURL": "https://github.com/vapor/url-encoded-form.git",
"state": {
"branch": null,
"revision": "82d8d63bdb76b6dd8febe916c639ab8608dbbaed",
"version": "1.0.6"
}
},
{
"package": "Validation",
"repositoryURL": "https://github.com/vapor/validation.git",
"state": {
"branch": null,
"revision": "4de213cf319b694e4ce19e5339592601d4dd3ff6",
"version": "2.1.1"
}
},
{
"package": "Vapor",
"repositoryURL": "https://github.com/vapor/vapor.git",
"state": {
"branch": null,
"revision": "92a58a9a84e4330500b99fe355a94d29f67abe58",
"version": "3.3.1"
}
},
{
"package": "WebSocket",
"repositoryURL": "https://github.com/vapor/websocket.git",
"state": {
"branch": null,
"revision": "d85e5b6dce4d04065865f77385fc3324f98178f6",
"version": "1.1.2"
}
}
]
},
"version": 1
}
20 changes: 20 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// swift-tools-version:5.1

import PackageDescription

let package = Package(
name: "GraphQLKit",
products: [
.library(
name: "GraphQLKit",
targets: ["GraphQLKit"]),
],
dependencies: [
.package(url: "https://github.com/alexsteinerde/Graphiti.git", from: "0.12.1"),
.package(url: "https://github.com/vapor/vapor.git", from: "3.0.0"),
],
targets: [
.target(name: "GraphQLKit", dependencies: ["Vapor", "Graphiti"]),
.testTarget(name: "GraphQLKitTests",dependencies: ["GraphQLKit"]),
]
)
70 changes: 70 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# GraphQLKit
[![Language](https://img.shields.io/badge/Swift-5.1-brightgreen.svg)](http://swift.org)
[![Vapor Version](https://img.shields.io/badge/Vapor-3-F6CBCA.svg)](http://vapor.codes)
[![CircleCI](https://circleci.com/gh/alexsteinerde/graphql-kit.svg?style=shield)](https://circleci.com/gh/alexsteinerde/graphql-kit)


Easy setup of a GraphQL server with Vapor. It uses the GraphQL implementation of [Graphiti](https://github.com/alexsteinerde/Graphiti).

## Features
- [x] Arguments, operation name and query support
- [x] Normal access to the `Request` object as in normal Vapor request handlers
- [x] Accept JSON in the body of a POST request as the GraphQL query
- [x] POST and GET support
- [ ] Accept `application/graphql` content type requests
- [ ] Downloadable schema file
- [ ] Multi-Resolver support

## Installation
```Swift
import PackageDescription

let package = Package(
dependencies: [
.package(url: "https://github.com/alexsteinerde/graphql-kit.git", from: "1.0.0"),
],
targets: [
.target(name: "App", dependencies: [<#T##Other Dependencies#>, "GraphQLKit"]),
...
]
)
```

## Getting Started
### Define your schema
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.
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.
But by including this package some other helper functions are exposed:

#### Async Resolver
An `EventLoopGroup` parameter is no longer required for async resolvers as the `Request` context object already provides access to it's `EventLoopGroup` attribute `eventLoop`.

```Swift
// Instead of adding an unnecessary parameter
func getAllTodos(store: Request, arguments: NoArguments, _: EventLoopGroup) throws -> EventLoopFuture<[Todo]> {
Todo.query(on: store).all()
}

// You don't need to provide the eventLoopGroup parameter even when resolving a future.
func getAllTodos(store: Request, arguments: NoArguments) throws -> EventLoopFuture<[Todo]> {
Todo.query(on: store).all()
}
```

### Register the schema on the router
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.

```Swift
let router = EngineRouter.default()

// Register the schema and it's resolver.
router.register(graphQLSchema: todoSchema, withResolver: TodoAPI())

services.register(router, as: Router.self)
```

## License
This project is released under the MIT license. See [LICENSE](LICENSE) for details.

## Contribution
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 :)
12 changes: 12 additions & 0 deletions Sources/GraphQLKit/GraphQLError+Debuggabe.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import GraphQL
import Vapor

extension GraphQLError: Debuggable {
public var identifier: String {
"GraphQLError"
}

public var reason: String {
message
}
}
7 changes: 7 additions & 0 deletions Sources/GraphQLKit/GraphQLRequest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import GraphQL

struct QueryRequest: Codable {
var query: String
var operationName: String?
var variables: [String: Map]?
}
Loading

0 comments on commit 7c03ecb

Please sign in to comment.