github.com/Kartograf/gqlgen@v0.7.2/example/starwars/server/server.go (about)

     1  package main
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"log"
     7  	"net/http"
     8  
     9  	"github.com/99designs/gqlgen/example/starwars"
    10  	"github.com/99designs/gqlgen/graphql"
    11  	"github.com/99designs/gqlgen/handler"
    12  )
    13  
    14  func main() {
    15  	http.Handle("/", handler.Playground("Starwars", "/query"))
    16  	http.Handle("/query", handler.GraphQL(starwars.NewExecutableSchema(starwars.NewResolver()),
    17  		handler.ResolverMiddleware(func(ctx context.Context, next graphql.Resolver) (res interface{}, err error) {
    18  			rc := graphql.GetResolverContext(ctx)
    19  			fmt.Println("Entered", rc.Object, rc.Field.Name)
    20  			res, err = next(ctx)
    21  			fmt.Println("Left", rc.Object, rc.Field.Name, "=>", res, err)
    22  			return res, err
    23  		}),
    24  	))
    25  
    26  	log.Fatal(http.ListenAndServe(":8080", nil))
    27  }