aboutsummaryrefslogtreecommitdiffstats
path: root/graphql/resolvers/identity.go
blob: ee40d4d813dac99947a464834e9a8f2184d8f552 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package resolvers

import (
	"context"

	"github.com/MichaelMure/git-bug/graphql/graph"
	"github.com/MichaelMure/git-bug/identity"
)

var _ graph.IdentityResolver = &identityResolver{}

type identityResolver struct{}

func (identityResolver) ID(ctx context.Context, obj *identity.Interface) (string, error) {
	return (*obj).Id().String(), nil
}

func (identityResolver) HumanID(ctx context.Context, obj *identity.Interface) (string, error) {
	return (*obj).Id().Human(), nil
}

func (identityResolver) Name(ctx context.Context, obj *identity.Interface) (*string, error) {
	return nilIfEmpty((*obj).Name())
}

func (identityResolver) Email(ctx context.Context, obj *identity.Interface) (*string, error) {
	return nilIfEmpty((*obj).Email())
}

func (identityResolver) Login(ctx context.Context, obj *identity.Interface) (*string, error) {
	return nilIfEmpty((*obj).Login())
}

func (identityResolver) DisplayName(ctx context.Context, obj *identity.Interface) (string, error) {
	return (*obj).DisplayName(), nil
}

func (identityResolver) AvatarURL(ctx context.Context, obj *identity.Interface) (*string, error) {
	return nilIfEmpty((*obj).AvatarUrl())
}

func (identityResolver) IsProtected(ctx context.Context, obj *identity.Interface) (bool, error) {
	return (*obj).IsProtected(), nil
}

func nilIfEmpty(s string) (*string, error) {
	if s == "" {
		return nil, nil
	}
	return &s, nil
}