Skip to content

hiroaki-yamamoto/gqlplay

Repository files navigation

GraphQL Playground Handler Function with Playground Settings in Golang

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

About

Go binding for GraphQL Playground

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages