Skip to content

Commit

Permalink
Fix example/social code (#510)
Browse files Browse the repository at this point in the history
The `Friends` field had higher priority than the `FriendsResolver` method. This is the reason why the field was renamed to a value, that doesn't match the GraphQL resolver.
  • Loading branch information
roaris committed Mar 21, 2022
1 parent 0140894 commit f56ac25
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions example/social/social.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ type contact struct {
}

type user struct {
IDField string
NameField string
RoleField string
Address *[]string
Friends *[]*user
CreatedAt graphql.Time
IDField string
NameField string
RoleField string
Address *[]string
FriendsField *[]*user
CreatedAt graphql.Time
contact
}

Expand All @@ -113,9 +113,9 @@ func (u user) Role() string {
return u.RoleField
}

func (u user) FriendsResolver(args struct{ Page *page }) (*[]*user, error) {
func (u user) Friends(args struct{ Page *page }) (*[]*user, error) {
var from int
numFriends := len(*u.Friends)
numFriends := len(*u.FriendsField)
to := numFriends

if args.Page != nil {
Expand All @@ -133,7 +133,7 @@ func (u user) FriendsResolver(args struct{ Page *page }) (*[]*user, error) {
}
}

friends := (*u.Friends)[from:to]
friends := (*u.FriendsField)[from:to]

return &friends, nil
}
Expand Down Expand Up @@ -188,10 +188,10 @@ var users = []*user{
var usersMap = make(map[string]*user)

func init() {
users[0].Friends = &[]*user{users[1]}
users[1].Friends = &[]*user{users[0], users[2], users[3]}
users[2].Friends = &[]*user{users[1], users[3]}
users[3].Friends = &[]*user{users[1], users[2]}
users[0].FriendsField = &[]*user{users[1]}
users[1].FriendsField = &[]*user{users[0], users[2], users[3]}
users[2].FriendsField = &[]*user{users[1], users[3]}
users[3].FriendsField = &[]*user{users[1], users[2]}
for _, usr := range users {
usersMap[usr.IDField] = usr
}
Expand Down

0 comments on commit f56ac25

Please sign in to comment.