All Projects → lgaches → Kitura-GraphQL

lgaches / Kitura-GraphQL

Licence: MIT license
Swift GraphQL HTTP Middleware for Kitura

Programming Languages

swift
15916 projects
HTML
75241 projects
shell
77523 projects

Projects that are alternatives of or similar to Kitura-GraphQL

Kitura-CouchDB
CouchDB adapter for Kitura
Stars: ✭ 50 (+78.57%)
Mutual labels:  kitura
swift-server-app
Server app with Swift and Docker
Stars: ✭ 18 (-35.71%)
Mutual labels:  kitura
Kitura-HelloWorld-iOS
A Hello World example of running Kitura on iOS
Stars: ✭ 55 (+96.43%)
Mutual labels:  kitura
kitura-cli
⌨️ Kitura command-line interface
Stars: ✭ 13 (-53.57%)
Mutual labels:  kitura
KituraKit
Swift client library for using Codable routes with Kitura
Stars: ✭ 58 (+107.14%)
Mutual labels:  kitura
now-swift-example
Example for use Kitura framework and swift lang with https://zeit.co/now.
Stars: ✭ 18 (-35.71%)
Mutual labels:  kitura
Kitura-NIO
A networking library for Kitura, based on SwiftNIO
Stars: ✭ 35 (+25%)
Mutual labels:  kitura
Kitura
A Swift web framework and HTTP server.
Stars: ✭ 7,533 (+26803.57%)
Mutual labels:  kitura

Kitura GraphQL

Swift macOS Linux License Build Status Codebeat

Create a GraphQL HTTP server with Kitura web framework.

Installation

import PackageDescription

let package = Package(
    dependencies: [
        .Package(url: "https://github.com/lgaches/Kitura-GraphQL.git", majorVersion: 0, minor: 0),
    ]
)

Usage

Configuration

GraphQLMiddleware has the following parameters:

  • schema: A Schema instance from Graphiti. A Schema must be provided.
  • showGraphiQL: If true, presentss GraphiQL when the GraphQL endpoint is loaded in a browser. We recommend that you set showGraphiQL to true when your app is in development because it's quite useful. You may or may not want it in production.
  • rootValue: A value to pass as the rootValue to the schema's execute function from Graphiti.
  • context: A value to pass as the context to the schema's execute function from Graphiti. If context is not provided, the RouterRequest struct is passed as the context.

HTTP Usage

Once installed as a middleware at a path, GraphQLMiddleware will accept requests with the parameters:

  • query: A string GraphQL document to be executed.
  • operationName: If the provided query contains multiple named operations, this specifies which operation should be executed. If not provided, a 400 error will be returned if the query contains multiple named operations.
  • variables: The runtime values to use for any GraphQL query variables as a JSON object.
  • raw: If the showGraphiQL option is enabled and the raw parameter is provided raw JSON will always be returned instead of GraphiQL even when loaded from a browser.

Example

import Graphiti
import Kitura
import GraphQLMiddleware

let schema = try Schema<NoRoot, NoContext> { schema in
    try schema.query { query in
        try query.field(name: "hello",
                        type: String.self,
                        description: "Totally Awesome",
                        deprecationReason: nil,
                        resolve: {
                            (type, arguments, context, resolveInfo) -> String in
                            return "world"
        })
    }
}

let router = Router()

let graphQL = GraphQLMiddleware(schema: schema,
                                showGraphiQL: true,
                                rootValue: noRootValue)

router.all("/graphql", middleware: graphQL)

Kitura.addHTTPServer(onPort: 8090, with: router)
Kitura.run()

License

This project is released under the MIT license. See LICENSE for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].