项目作者: hiroaki-yamamoto

项目描述 :
Go binding for GraphQL Playground
高级语言: Go
项目地址: git://github.com/hiroaki-yamamoto/gqlplay.git
创建时间: 2019-08-29T07:53:19Z
项目社区:https://github.com/hiroaki-yamamoto/gqlplay

开源协议:MIT License

下载


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?

  1. package main
  2. import "log"
  3. import (
  4. "github.com/hiroaki-yamamoto/gqlplay"
  5. "github.com/go-chi/chi"
  6. )
  7. func main() {
  8. player := gqlplay.Ground(gqlplay.Option{
  9. Settings: goplay.Settings{
  10. PollingEnabled: false,
  11. Credentials: SameOriginCredentials,
  12. HideTraceResponse: true,
  13. },
  14. Headers: map[string]string{
  15. "X-CSRF-TOKEN": "blablablabla...",
  16. }
  17. })
  18. r := chi.NewRouter()
  19. //...Other code...
  20. r.Get("/playground", player)
  21. svr := http.Server{
  22. Addr: fmt.Sprintf("%s:%d", setting.Host, setting.Port),
  23. Handler: chi.ServerBaseContext(ctx, r),
  24. }
  25. log.Fatal(svr.ListenAndServe())
  26. }

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.