Skip to content

Commit

Permalink
examples: fix code
Browse files Browse the repository at this point in the history
  • Loading branch information
mjarkk committed Oct 5, 2021
1 parent 7dca9ab commit aee34e0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
Binary file added examples/gin/go-graphql-gin-example
Binary file not shown.
10 changes: 9 additions & 1 deletion examples/gin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"io/ioutil"
"log"
"mime/multipart"
"sync"

"github.com/gin-gonic/gin"
"github.com/mjarkk/go-graphql"
Expand All @@ -12,11 +13,15 @@ import (
func main() {
r := gin.Default()

graphqlSchema, err := graphql.ParseSchema(QueryRoot{}, MethodRoot{}, nil)
graphqlSchema := graphql.NewSchema()
err := graphqlSchema.Parse(QueryRoot{}, MethodRoot{}, nil)
if err != nil {
log.Fatal(err)
}

// The GraphQL is not thread safe so we use this lock to prevent race conditions and other errors
var lock sync.Mutex

r.Any("/graphql", func(c *gin.Context) {
var form *multipart.Form

Expand All @@ -30,6 +35,9 @@ func main() {
return form, err
}

lock.Lock()
defer lock.Unlock()

res, _ := graphqlSchema.HandleRequest(
c.Request.Method,
c.Query,
Expand Down
Binary file added examples/viber/go-graphql-viber-example
Binary file not shown.
3 changes: 2 additions & 1 deletion examples/viber/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import (
func main() {
app := fiber.New()

graphqlSchema, err := graphql.ParseSchema(QueryRoot{}, MethodRoot{}, nil)
graphqlSchema := graphql.NewSchema()
err := graphqlSchema.Parse(QueryRoot{}, MethodRoot{}, nil)
if err != nil {
log.Fatal(err)
}
Expand Down

0 comments on commit aee34e0

Please sign in to comment.