Browse Source

Moved SessionResolver and UserResolver into resolvers/types package, updated references to it.

1.0
Gisle Aune 6 years ago
parent
commit
36939ffc59
  1. 26
      resolver/session.go
  2. 16
      resolver/types/session.go
  3. 2
      resolver/types/user.go

26
resolver/session.go

@ -4,6 +4,7 @@ import (
"context" "context"
"git.aiterp.net/rpdata/api/internal/session" "git.aiterp.net/rpdata/api/internal/session"
"git.aiterp.net/rpdata/api/resolver/types"
) )
// LoginArgs is args // LoginArgs is args
@ -13,12 +14,12 @@ type LoginArgs struct {
} }
// Session resolves query.session // Session resolves query.session
func (r *QueryResolver) Session(ctx context.Context) (*SessionResolver, error) {
return &SessionResolver{S: session.FromContext(ctx)}, nil
func (r *QueryResolver) Session(ctx context.Context) (*types.SessionResolver, error) {
return &types.SessionResolver{S: session.FromContext(ctx)}, nil
} }
// Login resolves mutation.login // Login resolves mutation.login
func (r *MutationResolver) Login(ctx context.Context, args *LoginArgs) (*SessionResolver, error) {
func (r *MutationResolver) Login(ctx context.Context, args *LoginArgs) (*types.SessionResolver, error) {
session := session.FromContext(ctx) session := session.FromContext(ctx)
err := session.Login(args.Username, args.Password) err := session.Login(args.Username, args.Password)
@ -26,26 +27,13 @@ func (r *MutationResolver) Login(ctx context.Context, args *LoginArgs) (*Session
return nil, err return nil, err
} }
return &SessionResolver{S: session}, nil
return &types.SessionResolver{S: session}, nil
} }
// Logout resolves mutation.logout // Logout resolves mutation.logout
func (r *MutationResolver) Logout(ctx context.Context) (*SessionResolver, error) {
func (r *MutationResolver) Logout(ctx context.Context) (*types.SessionResolver, error) {
session := session.FromContext(ctx) session := session.FromContext(ctx)
session.Logout() session.Logout()
return &SessionResolver{S: session}, nil
}
// SessionResolver resolves Session
type SessionResolver struct{ S *session.Session }
// User resolves Session.user
func (r *SessionResolver) User() *UserResolver {
user := r.S.User()
if user == nil {
return nil
}
return &UserResolver{U: user}
return &types.SessionResolver{S: session}, nil
} }

16
resolver/types/session.go

@ -0,0 +1,16 @@
package types
import "git.aiterp.net/rpdata/api/internal/session"
// SessionResolver resolves Session
type SessionResolver struct{ S *session.Session }
// User resolves Session.user
func (r *SessionResolver) User() *UserResolver {
user := r.S.User()
if user == nil {
return nil
}
return &UserResolver{U: user}
}

2
resolver/user.go → resolver/types/user.go

@ -1,4 +1,4 @@
package resolver
package types
import "git.aiterp.net/rpdata/api/internal/session" import "git.aiterp.net/rpdata/api/internal/session"
Loading…
Cancel
Save