Swiftpack.co - nerdsupremacist/graphzahl-vapor-support as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by nerdsupremacist.
nerdsupremacist/graphzahl-vapor-support 0.1.0-alpha.8
A set of extensions that allow to use GraphZahl with Vapor
⭐️ 6
🕓 3 years ago
macOS
.package(url: "https://github.com/nerdsupremacist/graphzahl-vapor-support.git", from: "0.1.0-alpha.8")

GraphZahl Vapor Support

A set of extensions that allow to use GraphZahl with Vapor.

Warning: For the best results please use. graphzahl-vapor-support with Xcode 11.4 Beta

About GraphZahl

GraphZahl is a Framework to implement Declarative, Type-Safe GraphQL Server APIs with Magic 🎩.

Learn more about GraphZahl: here

Installation

Swift Package Manager

You can install graphzahl-vapor-support via Swift Package Manager by adding the following line to your Package.swift:

import PackageDescription

let package = Package(
    [...]
    dependencies: [
        .package(url: "https://github.com/nerdsupremacist/graphzahl-vapor-support.git", from: "0.1.0-alpha.")
    ]
)

Usage

You can now add a Schema direetly to your APPs Routes:

enum HelloWorld: GraphQLSchema {
    class Query: QueryType {
        func greeting(name: String) -> String {
            return "Hello, \(name)"
        }
    }

    typealias Mutation = None
}

// Add the API to the Routes of your Vapor App
app.routes.graphql(path: "api", "graphql", use: HelloWorld.self)

And you can even add GraphiQL:

app.routes.graphql(path: "api", "graphql", use: HelloWorld.self, includeGraphiQL: true)

And in case you need to provide a ViewerContext, just pass a closure, that describes how to get the ViewerContext from the Request:

enum TodoApp: GraphQLSchema {
    typealias ViewerContext = LoggedInUser?

    class Query: QueryType {
        let user: LoggedInUser?
        
        func myTodos() -> [Todo]? {
            return user?.todosFromDB()
        }

        required init(viewerContext user: LoggedInUser?) {
            self.user = user
        }
    }

    typealias Mutation = None
}

app.routes.graphql(path: "api", "graphql", use: TodoApp.self, includeGraphiQL: true) { $0.db }

Contributions

Contributions are welcome and encouraged!

License

graphzahl-vapor-support is available under the MIT license. See the LICENSE file for more info.

This project is being done under the supervision of the Chair for Applied Software Enginnering at the Technical University of Munich. The chair has everlasting rights to use and maintain this tool.

GitHub

link
Stars: 6
Last commit: 3 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

3 years ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics