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