mirror of
https://git.vectorsigma.ru/public/photoview.git
synced 2026-08-03 19:39:19 +00:00
Refactoring of API
- Add request context to all database calls - Update deprecated gqlgen functions - Update go.mod dependencies
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package resolvers
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
api "github.com/photoview/photoview/api/graphql"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@@ -8,7 +10,18 @@ import (
|
||||
//go:generate go run github.com/99designs/gqlgen
|
||||
|
||||
type Resolver struct {
|
||||
Database *gorm.DB
|
||||
database *gorm.DB
|
||||
}
|
||||
|
||||
func NewRootResolver(db *gorm.DB) Resolver {
|
||||
return Resolver{
|
||||
database: db,
|
||||
}
|
||||
}
|
||||
|
||||
// DB returns a database instance that is tied to the given context
|
||||
func (r *Resolver) DB(ctx context.Context) *gorm.DB {
|
||||
return r.database.WithContext(ctx)
|
||||
}
|
||||
|
||||
func (r *Resolver) Mutation() api.MutationResolver {
|
||||
|
||||
Reference in New Issue
Block a user