stufflog graphql server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.1 KiB

  1. package graph
  2. import (
  3. "git.aiterp.net/stufflog/server/database"
  4. "git.aiterp.net/stufflog/server/graph/graphcore"
  5. "git.aiterp.net/stufflog/server/graph/loaders"
  6. "git.aiterp.net/stufflog/server/graph/resolvers"
  7. "git.aiterp.net/stufflog/server/services"
  8. "github.com/99designs/gqlgen/graphql"
  9. "github.com/99designs/gqlgen/graphql/handler"
  10. "github.com/gin-gonic/gin"
  11. )
  12. //go:generate go run github.com/99designs/gqlgen --verbose --config gqlgen.yml
  13. // New creates a new GraphQL schema.
  14. func New(bundle services.Bundle, database database.Database) graphql.ExecutableSchema {
  15. return graphcore.NewExecutableSchema(graphcore.Config{
  16. Resolvers: &resolvers.Resolver{
  17. Bundle: bundle,
  18. Database: database,
  19. },
  20. })
  21. }
  22. func Gin(bundle services.Bundle, database database.Database) gin.HandlerFunc {
  23. schema := New(bundle, database)
  24. gqlHandler := handler.NewDefaultServer(schema)
  25. return func(c *gin.Context) {
  26. bundle.Auth.CheckGinSession(c)
  27. c.Request = c.Request.WithContext(
  28. loaders.NewUserLoaderContext(c.Request.Context(), database.Users()),
  29. )
  30. gqlHandler.ServeHTTP(c.Writer, c.Request)
  31. }
  32. }