mirror of https://git.sr.ht/~sircmpwn/core-go
client: rename Execute to Do
583d0b1bcb
("client/graphql: handle GraphQL errors") changed
Execute behavior by wrapping the result into a struct with "data"
and "errors" fields. This is a breaking change, but it's hard to
spot when upgrading core-go because it won't cause a compilation
error.
Rename Execute to Do to break the build and force callers to update
accordingly.
This commit is contained in:
parent
23808bb099
commit
864816cfbc
|
@ -320,23 +320,6 @@ func FetchMetaProfile(ctx context.Context, username string, user *AuthContext) e
|
|||
panic(errors.New("Cannot fetch profile from ourselves"))
|
||||
}
|
||||
|
||||
type GraphQLProfile struct {
|
||||
ID int `json:"id"`
|
||||
Username string `json:"username"`
|
||||
Email string `json:"email"`
|
||||
URL *string `json:"url"`
|
||||
Location *string `json:"location"`
|
||||
Bio *string `json:"bio"`
|
||||
UserType string `json:"userType"`
|
||||
SuspensionNotice string `json:"suspensionNotice"`
|
||||
}
|
||||
|
||||
type GraphQLResponse struct {
|
||||
Data struct {
|
||||
Me GraphQLProfile `json:"me"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
query := client.GraphQLQuery{
|
||||
Query: `
|
||||
query {
|
||||
|
@ -352,13 +335,24 @@ func FetchMetaProfile(ctx context.Context, username string, user *AuthContext) e
|
|||
}`,
|
||||
}
|
||||
|
||||
var result GraphQLResponse
|
||||
if err := client.Execute(ctx, username,
|
||||
var result struct {
|
||||
Me struct {
|
||||
ID int `json:"id"`
|
||||
Username string `json:"username"`
|
||||
Email string `json:"email"`
|
||||
URL *string `json:"url"`
|
||||
Location *string `json:"location"`
|
||||
Bio *string `json:"bio"`
|
||||
UserType string `json:"userType"`
|
||||
SuspensionNotice string `json:"suspensionNotice"`
|
||||
} `json:"me"`
|
||||
}
|
||||
if err := client.Do(ctx, username,
|
||||
"meta.sr.ht", query, &result); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
profile := result.Data.Me
|
||||
profile := result.Me
|
||||
return database.WithTx(ctx, nil, func(tx *sql.Tx) error {
|
||||
// TODO: Make the database representation consistent with this
|
||||
ut := strings.ToLower(profile.UserType)
|
||||
|
@ -474,11 +468,6 @@ func LookupUser(ctx context.Context, username string, user *AuthContext) error {
|
|||
// should not be trusted)
|
||||
func LookupTokenRevocation(ctx context.Context,
|
||||
username string, hash [64]byte, clientID string) (bool, error) {
|
||||
type GraphQLResponse struct {
|
||||
Data struct {
|
||||
RevocationStatus bool `json:"tokenRevocationStatus"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
query := client.GraphQLQuery{
|
||||
Query: `
|
||||
|
@ -491,12 +480,14 @@ func LookupTokenRevocation(ctx context.Context,
|
|||
},
|
||||
}
|
||||
|
||||
var result GraphQLResponse
|
||||
if err := client.Execute(ctx, username,
|
||||
var result struct {
|
||||
RevocationStatus bool `json:"tokenRevocationStatus"`
|
||||
}
|
||||
if err := client.Do(ctx, username,
|
||||
"meta.sr.ht", query, &result); err != nil {
|
||||
return true, err
|
||||
}
|
||||
return result.Data.RevocationStatus, nil
|
||||
return result.RevocationStatus, nil
|
||||
}
|
||||
|
||||
func OAuth2(token string, hash [64]byte, w http.ResponseWriter,
|
||||
|
|
|
@ -25,7 +25,7 @@ type InternalAuth struct {
|
|||
NodeID string `json:"node_id"`
|
||||
}
|
||||
|
||||
func Execute(ctx context.Context, username string, svc string,
|
||||
func Do(ctx context.Context, username string, svc string,
|
||||
query GraphQLQuery, result interface{}) error {
|
||||
|
||||
body, err := json.Marshal(query)
|
||||
|
|
Loading…
Reference in New Issue