Skip to content

Express middleware for creating GraphQL query shortlinks to GraphiQL.

License

Notifications You must be signed in to change notification settings

kettanaito/graphql-query-shortlink

Repository files navigation

graphql-query-shortlink

A middleware that creates shortlinks for received GraphQL queries that link to the GraphiQL.

Getting started

Install

npm install graphql-query-shortlink

Use middleware

import express from 'express'
import bodyParser from 'body-parser'
import { buildSchema } from 'graphql'
import graphqlHTTP from 'express-graphql'
import graphqlQueryShortlink from 'graphql-query-shortlink'

const app = express()

app.use(bodyParser.json())

graphqlQueryShortlink(app, {
  graphqlUrl: '/graphql',
})

app.use('/graphql', graphqlHTTP({
  schema: buildSchema(`
    type Query {
      hello: string
    }
  `),
  rootValue: {
    hello: () => 'Hello, world!'
  }
  graphiql: true
}))

app.listen(3001)

API

graphqlUrl: string

Default: /graphql

A relaive URL to the GraphQL endpoint.


inspectorUrl: string

Default: /goto

A relative URL of the generated query shortlink.


reportQuery: (shortlink: string) => void

Default:

graphqlQueryShortlink(app, {
  reportQuery(shortlink) {
    console.log(`Inspect the query: ${shortlink}`)
  },
})

A custom reporter function used for logging the shortlinks into the console.

Materials

Special thanks

About

Express middleware for creating GraphQL query shortlinks to GraphiQL.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages