Code Monkey home page Code Monkey logo

kitura-graphql's Introduction

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.

kitura-graphql's People

Contributors

jacobvanorder avatar lgaches avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

kitura-graphql's Issues

Update `README.md`

The information in your README.md is out of date.

I was able to get a response using

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()

Additionally, if I were to try to create the Schema using <NoRoot, RouterRequest>, I get "The operation couldn’t be completed. (GraphQL.GraphQLError error 1.)" as a response.

Schema file

It would be great to have the ability to provide a schema file to the server and start it with the file content.
Or is this already possible just not listed in the readme?
Thanks
Alex

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.