Skip to content

Commit

Permalink
fix: features field fail when no github account
Browse files Browse the repository at this point in the history
  • Loading branch information
42atomys committed Apr 30, 2022
1 parent dd3f2f6 commit 0917135
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions internal/api/api.resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@ func (r *userResolver) Features(ctx context.Context, obj *generated.User) ([]typ
return typesgen.AllFeature, nil
}

acc, err := r.client.Account.Query().
Select("username").
Where(
account.UserID(obj.ID),
account.Provider(string(typesgen.ProviderGithub)),
).
Only(ctx)

if (err != nil) || (acc == nil) {
return features, nil
}

// TODO Move github utils outside of resolvers
httpClient := oauth2.NewClient(context.Background(), oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: os.Getenv("GITHUB_TOKEN")},
Expand All @@ -125,16 +137,8 @@ func (r *userResolver) Features(ctx context.Context, obj *generated.User) ([]typ
} `graphql:"user(login: $login)"`
}

username := r.client.Account.Query().
Select("username").
Where(
account.UserID(obj.ID),
account.Provider(string(typesgen.ProviderGithub)),
).
OnlyX(ctx).Username

err := client.Query(ctx, &query, map[string]interface{}{
"login": githubv4.String(username),
err = client.Query(ctx, &query, map[string]interface{}{
"login": githubv4.String(acc.Username),
})
if err != nil {
log.Error().Err(err).Msg("failed to query github")
Expand Down

0 comments on commit 0917135

Please sign in to comment.