gqlplay

package module
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 31, 2019 License: MIT Imports: 3 Imported by: 0

README

GraphQL Playground Handler Function with Playground Settings in Golang

CircleCI Maintainability Test Coverage Go Report Card

What this?

This is a go binding of Prisma's GraphQL PlayGround with setting configuration support.

Why I made this?

I like using GraphQL, especially, GQLGen is awesome. However, the playground provided by GQLGen has some small-issues. i.e. I cam't set configuration to handle CSRF. So, I decided to re-invent the wheel that can set the configuration.

How to use?

package main

import "log"

import (
  "github.com/hiroaki-yamamoto/gqlplay"
  "github.com/go-chi/chi"
)

func main() {
  player := gqlplay.Ground(gqlplay.Option{
    Settings: goplay.Settings{
      PollingEnabled: false,
      Credentials: SameOriginCredentials,
      HideTraceResponse: true,
    },
    Headers: map[string]string{
      "X-CSRF-TOKEN": "blablablabla...",
    }
  })
  r := chi.NewRouter()
  //...Other code...
  r.Get("/playground", player)
  svr := http.Server{
		Addr:    fmt.Sprintf("%s:%d", setting.Host, setting.Port),
		Handler: chi.ServerBaseContext(ctx, r),
  }
  log.Fatal(svr.ListenAndServe())
}

It must be easy.

Contribution

Sending Issues / PR is welcome. PR is more appreciated. However, if you changed the behavior, the corresponding changes, additions, and/or deletions of the test code is mandatory, if you changed only the doc, the test code is not needed.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ground

func Ground(option Option) http.HandlerFunc

Ground generates http handler function for Go Playground (with CDN)

Types

type Credentials

type Credentials string

Credentials enumerates strings to specify credentials options.

const (
	// OmitCredentials omits the credentials.
	OmitCredentials Credentials = "omit"
	// IncludeCredentials accepts the credentials from anywhere.
	IncludeCredentials Credentials = "include"
	// SameOriginCredentials accepts the credentials from same-origin.
	SameOriginCredentials Credentials = "same-origin"
)

type CursorShape

type CursorShape string

CursorShape enumerate strings to specify the sahpe of the cursor.

const (
	// CursorShapeLine set the cursor shape to line.
	CursorShapeLine CursorShape = "line"
	// CursorShapeBlock set the cursor shape to block.
	CursorShapeBlock CursorShape = "block"
	// CursorShapeUnderline set the cursor shape to underline.
	CursorShapeUnderline CursorShape = "underline"
)

type Option

type Option struct {
	Settings             Settings          `json:"settings,omitempty"`
	Endpoint             string            `json:"endpoint,omitempty"`
	SubscriptionEndpoint string            `json:"subscriptionEndpoint,omitempty"`
	WorkspaceName        string            `json:"workspaceName,omitempty"`
	Config               string            `json:"config,omitempty"`
	Headers              map[string]string `json:"headers,omitempty"`
}

Option represents the configuration of playground that depends on: https://github.com/prisma/graphql-playground

type Settings

type Settings struct {
	CursorShape           CursorShape `json:"editor.cursorShape,omitempty"`
	FontFamily            string      `json:"editor.fontFamily,omitempty"`
	FontSize              float32     `json:"editor.fontSize,omitempty"`
	ReuseHeaders          bool        `json:"editor.reuseHeaders"`
	Theme                 Theme       `json:"editor.theme,omitempty"`
	BetaUpdates           bool        `json:"general.betaUpdates"`
	PrintWidth            float32     `json:"prettier.printWidth,omitempty"`
	TabWidth              float32     `json:"prettier.tabWidth,omitempty"`
	UseTabs               bool        `json:"prettier.useTabs"`
	Credentials           Credentials `json:"request.credentials,omitmepty"`
	PollingEnabled        bool        `json:"schema.polling.enable"`
	PollingEndpointFilter string      `json:"schema.polling.endpointFilter,omitempty"`
	PollingInterval       float32     `json:"schema.polling.interval,omitempty"`
	DisableSchemaComments bool        `json:"schema.disableComments"`
	HideTraceResponse     bool        `json:"tracing.hideTracingResponse"`
}

Settings is the setting structure to configure GraphQL Playground.

type Theme

type Theme string

Theme enumerates strings to specify the theme of the playground

const (
	// DarkTheme sets the theme to be dark
	DarkTheme Theme = "dark"
	// LightTheme sets the theme to be Light
	LightTheme Theme = "light"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL