All Projects β†’ rse β†’ hapi-plugin-graphiql

rse / hapi-plugin-graphiql

Licence: other
HAPI plugin for GraphiQL integration

Programming Languages

CSS
56736 projects
javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to hapi-plugin-graphiql

Appy
πŸš€ A full stack boilerplate web app
Stars: ✭ 225 (+1025%)
Mutual labels:  hapi
hapi-plugin-mysql
Hapi plugin for MySQL
Stars: ✭ 17 (-15%)
Mutual labels:  hapi
apollo-studio-community
🎑 Β GraphQL developer portal featuring an IDE (Apollo Explorer), auto-documentation, metrics reporting, and more. This repo is for issues, feature requests, and preview docs. πŸ“¬
Stars: ✭ 212 (+960%)
Mutual labels:  graphiql
Inert
Static file and directory handlers for hapi.js
Stars: ✭ 236 (+1080%)
Mutual labels:  hapi
sapper-authentication-demo
A demonstration of Auth with Sapper + JWT + Server Side Rendering + RBAC
Stars: ✭ 102 (+410%)
Mutual labels:  hapi
hapi-statsd
A hapi plugin for sending request round trip metrics to statsd
Stars: ✭ 29 (+45%)
Mutual labels:  hapi
Hapi Universal Redux
DEPRECATED: Create an universal React and Redux app in less than 5 minutes!
Stars: ✭ 215 (+975%)
Mutual labels:  hapi
noire-server
Hapi Boilerplate
Stars: ✭ 20 (+0%)
Mutual labels:  hapi
nodejs-tutorials-hapi
Examples for the hapi tutorial series within the Future Studio University
Stars: ✭ 70 (+250%)
Mutual labels:  hapi
hapi-doorkeeper
User authentication for web servers
Stars: ✭ 14 (-30%)
Mutual labels:  hapi
hapi-docs
Beautiful API documentation generator for Hapi using Vue
Stars: ✭ 64 (+220%)
Mutual labels:  hapi
good-sentry
Sentry broadcasting for good process monitor
Stars: ✭ 15 (-25%)
Mutual labels:  hapi
hapi-good-winston
A good reporter to send and log events with winston
Stars: ✭ 21 (+5%)
Mutual labels:  hapi
Hapi React Views
πŸ“¦ A hapi view engine for React components
Stars: ✭ 234 (+1070%)
Mutual labels:  hapi
protoc-gen-twirpql
Generate A GraphQL Layer from A Twirp Server: https://twirpql.dev
Stars: ✭ 49 (+145%)
Mutual labels:  graphiql
Openapi Backend
Build, Validate, Route, Authenticate and Mock using OpenAPI
Stars: ✭ 216 (+980%)
Mutual labels:  hapi
trailpack-hapi
πŸ“¦ Hapi.js Trailpack
Stars: ✭ 19 (-5%)
Mutual labels:  hapi
minimal-hapi-react-webpack
Minimal Hapi + React + Webpack + HMR (hot module reloading) Sandbox
Stars: ✭ 55 (+175%)
Mutual labels:  hapi
hapi-mongo-models
πŸ“¦ A hapi plugin for `mongo-models`
Stars: ✭ 101 (+405%)
Mutual labels:  hapi
hapi-now-auth
Hapi token auth for bearer and jwt
Stars: ✭ 43 (+115%)
Mutual labels:  hapi

hapi-plugin-graphiql

HAPI plugin for GraphiQL integration

Installation

$ npm install hapi hapi-plugin-graphiql

About

This is a small plugin for the HAPI server framework for seamless integration of GraphiQL, an interactive GraphQL user interface. This variant of GraphiQL especially integrates a username/password based login dialog and reports network responses in the GraphiQL status bar. In case of its downstream/local copy of GraphiQL, it also applies some additional changes to GraphiQL's internals.

Usage

The following example shows the plugin in action. The shown options are actually the default ones:

server.register({
    register: require("hapi-plugin-graphiql"),
    options: {
        graphiqlSource: "downstream",
        graphiqlGlobals: "",
        graphiqlURL: "/api",
        graphqlFetchURL: "/api/data/graph",
        graphqlFetchOpts: `{
            method: "POST",
            headers: {
                "Content-Type": "application/json",
                "Accept":       "application/json"
            },
            body: JSON.stringify(params),
            credentials: "same-origin"
        }`,
        loginFetchURL: "/api/auth/login",
        loginFetchOpts: `{
            method: "POST",
            headers: {
                "Content-Type": "application/json"
            },
            body: JSON.stringify({
                username: username,
                password: password
            }),
            credentials: "same-origin"
        }`,
        loginFetchSuccess: "",
        loginFetchError: "",
        graphqlExample:
            "query Example {\n" +
            "    Session {\n" +
            "        __typename # schema introspection\n" +
            "    }\n" +
            "}\n",
        documentationURL:  "",
        documentationFile: ""
    }
})

This assumes you have a REST-based authentication endpoint /api/auth/login and a GraphQL endpoint /api/data/graphql. The GraphiQL UI then can be accessed under /api. The authentication endpoint is assumed to accept { username: "...", password: "..." } and sets the authentication token as a HTTP cookie for /api. If you your authentication endpoint returns { token: "..." } and the token has to be passed in an Authorization header as a Bearer token, use the following configuration instead:

server.register({
    register: require("hapi-plugin-graphiql"),
    options: {
        graphiqlSource: "downstream",
        graphiqlGlobals: `var token = null;`,
        graphiqlURL: "/api",
        graphqlFetchURL: "/api/data/graph",
        graphqlFetchOpts: `{
            method: "POST",
            headers: Object.assign({
                "Content-Type":  "application/json",
                "Accept":        "application/json"
            }, token ? {
                "Authorization": "Bearer " + token
            } : {}),
            body: JSON.stringify(params),
            credentials: "same-origin"
        }`,
        loginFetchURL: "/api/auth/login",
        loginFetchOpts: `{
            method: "POST",
            headers: {
                "Content-Type": "application/json"
            },
            body: JSON.stringify({
                username: username,
                password: password
            }),
            credentials: "same-origin"
        }`,
        loginFetchSuccess: `token = JSON.parse(response.text()).token;`,
        loginFetchError:   `token = null;`,
        graphqlExample:
            "query Example {\n" +
            "    Session {\n" +
            "        __typename # schema introspection\n" +
            "    }\n" +
            "}\n"
    }
})

Options

The supported configuration options are:

  • graphiqlSource:
    The source for GraphiQL, either upstream (original vendor version) or downstream (patched local version). Default: "downstream"

  • graphiqlGlobals:
    JavaScript code snippet injected into the global scope of the GraphiQL integration. Usually used for injecting a global variable for use in the other code snippets. Default: ""

  • graphiqlURL:
    The URL under which the GraphiQL UI is registered for GET requests. This can be even the same as the GraphQL URL, as it is usually registered for POST requests. Default: "/api"

  • graphqlFetchURL:
    The URL under which the GraphQL API can be reached via POST requests. Default: "/api/data/graph"

  • graphqlFetchOpts:
    JavaScript code snippet injected into the W3C-Fetch API call as options for fetching a GraphQL query. Default:

    `{
        method: "POST",
        headers: {
            "Content-Type": "application/json",
            "Accept":       "application/json"
        },
        body: JSON.stringify(params),
        credentials: "same-origin"
    }`
    
  • loginFetchURL:
    JavaScript code snippet injected into the W3C-Fetch API call as options for logging in. Default: "/api/auth/login"

  • loginFetchOpts:
    JavaScript code snippet injected into the W3C-Fetch API call as options for logging in. Default:

    `{
        method: "POST",
        headers: {
            "Content-Type": "application/json"
        },
        body: JSON.stringify({
            username: username,
            password: password
        }),
        credentials: "same-origin"
    }`
    
  • loginFetchSuccess:
    JavaScript code snippet injected into the success handler of the W3C-Fetch API call for loggin in. Default: ""

  • loginFetchError:
    JavaScript code snippet injected into the error handler of the W3C-Fetch API call for loggin in. Default: ""

  • graphqlExample:
    A GraphQL query string used as the initial query source in the UI. Default:

    "query Example {\n" +
    "    Session {\n" +
    "        __typename # schema introspection\n" +
    "    }\n" +
    "}\n"
    
  • documentationURL:
    URL (usually under graphiqlURL) under which you want to reference a single documentation file with the markdown directive [name](url) from within your GraphQL schema comments.

  • documentationFile:
    The local path to the file to serve if documentationURL is requested.

License

Copyright (c) 2016-2019 Dr. Ralf S. Engelschall (http://engelschall.com/)

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.

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].