@@ -8,11 +8,31 @@ import (
88 "github.com/MichaelMure/git-bug/api/graphql/models"
99 "github.com/MichaelMure/git-bug/bug"
1010 "github.com/MichaelMure/git-bug/commentary"
11+ "github.com/MichaelMure/git-bug/entity"
1112)
1213
1314var _ graph.BugResolver = & bugResolver {}
1415
15- type bugResolver struct {}
16+ type bugResolver struct {
17+ identityResolver
18+ }
19+
20+ // resolveIdentity is a helper function to call the identityResolver
21+ func (r bugResolver ) resolveIdentity (id entity.Id ) (models.IdentityWrapper , error ) {
22+ return r .identityResolver .resolveIdentity (id )
23+ }
24+
25+ func (r bugResolver ) resolveAllIdentities (ids []entity.Id ) ([]models.IdentityWrapper , error ) {
26+ result := make ([]models.IdentityWrapper , len (ids ))
27+ for i , id := range ids {
28+ identity , err := r .resolveIdentity (id )
29+ if err != nil {
30+ return nil , err
31+ }
32+ result [i ] = identity
33+ }
34+ return result , nil
35+ }
1636
1737func (bugResolver ) ID (_ context.Context , obj models.BugWrapper ) (string , error ) {
1838 return obj .Id ().String (), nil
@@ -22,6 +42,10 @@ func (bugResolver) HumanID(_ context.Context, obj models.BugWrapper) (string, er
2242 return obj .Id ().Human (), nil
2343}
2444
45+ func (r bugResolver ) Author (_ context.Context , obj models.BugWrapper ) (models.IdentityWrapper , error ) {
46+ return r .resolveIdentity (obj .Author ())
47+ }
48+
2549func (bugResolver ) Status (_ context.Context , obj models.BugWrapper ) (models.Status , error ) {
2650 return convertStatus (obj .Status ())
2751}
@@ -126,7 +150,7 @@ func (bugResolver) Timeline(_ context.Context, obj models.BugWrapper, after *str
126150 return connections .TimelineItemCon (timeline , edger , conMaker , input )
127151}
128152
129- func (bugResolver ) Actors (_ context.Context , obj models.BugWrapper , after * string , before * string , first * int , last * int ) (* models.IdentityConnection , error ) {
153+ func (r bugResolver ) Actors (_ context.Context , obj models.BugWrapper , after * string , before * string , first * int , last * int ) (* models.IdentityConnection , error ) {
130154 input := models.ConnectionInput {
131155 Before : before ,
132156 After : after ,
@@ -150,15 +174,15 @@ func (bugResolver) Actors(_ context.Context, obj models.BugWrapper, after *strin
150174 }, nil
151175 }
152176
153- actors , err := obj .Actors ()
177+ actors , err := r . resolveAllIdentities ( obj .Actors () )
154178 if err != nil {
155179 return nil , err
156180 }
157181
158182 return connections .IdentityCon (actors , edger , conMaker , input )
159183}
160184
161- func (bugResolver ) Participants (_ context.Context , obj models.BugWrapper , after * string , before * string , first * int , last * int ) (* models.IdentityConnection , error ) {
185+ func (r bugResolver ) Participants (_ context.Context , obj models.BugWrapper , after * string , before * string , first * int , last * int ) (* models.IdentityConnection , error ) {
162186 input := models.ConnectionInput {
163187 Before : before ,
164188 After : after ,
@@ -182,7 +206,7 @@ func (bugResolver) Participants(_ context.Context, obj models.BugWrapper, after
182206 }, nil
183207 }
184208
185- participants , err := obj .Participants ()
209+ participants , err := r . resolveAllIdentities ( obj .Participants () )
186210 if err != nil {
187211 return nil , err
188212 }
0 commit comments