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