From 09171352a4982fe584f9de63c0f83c0d4d738eec Mon Sep 17 00:00:00 2001 From: Gregory DALMAR Date: Sat, 30 Apr 2022 21:19:03 +0200 Subject: [PATCH] fix: features field fail when no github account --- internal/api/api.resolvers.go | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/internal/api/api.resolvers.go b/internal/api/api.resolvers.go index 32efdf4f..edbe98de 100644 --- a/internal/api/api.resolvers.go +++ b/internal/api/api.resolvers.go @@ -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")}, @@ -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")