identity.go

 1package resolvers
 2
 3import (
 4	"context"
 5
 6	"github.com/MichaelMure/git-bug/identity"
 7)
 8
 9type identityResolver struct{}
10
11func (identityResolver) ID(ctx context.Context, obj *identity.Interface) (string, error) {
12	return (*obj).Id(), nil
13}
14
15func (identityResolver) Name(ctx context.Context, obj *identity.Interface) (*string, error) {
16	return nilIfEmpty((*obj).Name())
17}
18
19func (identityResolver) Email(ctx context.Context, obj *identity.Interface) (*string, error) {
20	return nilIfEmpty((*obj).Email())
21}
22
23func (identityResolver) Login(ctx context.Context, obj *identity.Interface) (*string, error) {
24	return nilIfEmpty((*obj).Login())
25}
26
27func (identityResolver) DisplayName(ctx context.Context, obj *identity.Interface) (string, error) {
28	return (*obj).DisplayName(), nil
29}
30
31func (identityResolver) AvatarURL(ctx context.Context, obj *identity.Interface) (*string, error) {
32	return nilIfEmpty((*obj).AvatarUrl())
33}
34
35func (identityResolver) IsProtected(ctx context.Context, obj *identity.Interface) (bool, error) {
36	return (*obj).IsProtected(), nil
37}
38
39func nilIfEmpty(s string) (*string, error) {
40	if s == "" {
41		return nil, nil
42	}
43	return &s, nil
44}