diff --git a/examples/gin/go-graphql-gin-example b/examples/gin/go-graphql-gin-example new file mode 100755 index 0000000..714bbbf Binary files /dev/null and b/examples/gin/go-graphql-gin-example differ diff --git a/examples/gin/main.go b/examples/gin/main.go index 7d7c6fd..4653829 100644 --- a/examples/gin/main.go +++ b/examples/gin/main.go @@ -4,6 +4,7 @@ import ( "io/ioutil" "log" "mime/multipart" + "sync" "github.com/gin-gonic/gin" "github.com/mjarkk/go-graphql" @@ -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 @@ -30,6 +35,9 @@ func main() { return form, err } + lock.Lock() + defer lock.Unlock() + res, _ := graphqlSchema.HandleRequest( c.Request.Method, c.Query, diff --git a/examples/viber/go-graphql-viber-example b/examples/viber/go-graphql-viber-example new file mode 100755 index 0000000..d7bc85b Binary files /dev/null and b/examples/viber/go-graphql-viber-example differ diff --git a/examples/viber/main.go b/examples/viber/main.go index 63cb8a6..315a98e 100644 --- a/examples/viber/main.go +++ b/examples/viber/main.go @@ -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) }