Skip to content

Commit

Permalink
docs(gin): missing import playground
Browse files Browse the repository at this point in the history
  • Loading branch information
appleboy committed Feb 18, 2020
1 parent 25d1676 commit 26ee1aa
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions docs/content/recipes/gin.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@ $ go get github.com/gin-gonic/gin
```

In your router file, define the handlers for the GraphQL and Playground endpoints in two different methods and tie then together in the Gin router:

```go
import (
"github.com/99designs/gqlgen/graphql/handler"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"

"github.com/99designs/gqlgen/graphql/handler"
"github.com/99designs/gqlgen/graphql/playground"
)

// Defining the Graphql handler
func graphqlHandler() gin.HandlerFunc {
// NewExecutableSchema and Config are in the generated.go file
// Resolver is in the resolver.go file
// NewExecutableSchema and Config are in the generated.go file
// Resolver is in the resolver.go file
h := handler.NewDefaultServer(NewExecutableSchema(Config{Resolvers: &Resolver{}}))

return func(c *gin.Context) {
Expand All @@ -44,12 +47,13 @@ func playgroundHandler() gin.HandlerFunc {
}

func main() {
// Setting up Gin
r := gin.Default()
// Setting up Gin
r := gin.Default()
r.POST("/query", graphqlHandler())
r.GET("/", playgroundHandler())
r.Run()
}
r.Run()
}

```

## Accessing gin.Context
Expand Down Expand Up @@ -96,7 +100,7 @@ func (r *resolver) Todo(ctx context.Context) (*Todo, error) {
if err != nil {
return nil, err
}

// ...
}
```

0 comments on commit 26ee1aa

Please sign in to comment.