Skip to content

nerdsupremacist/graphzahl-vapor-support

Repository files navigation

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.

About

A set of extensions that allow to use GraphZahl with Vapor

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages