Fix missing __typename checks and standalone var declarations
Add __typename to GraphQL queries and type guards in risk view, risk list, user view, and user list commands to prevent silent garbage output when a wrong node type ID is passed. Wrap standalone var declarations in var () blocks per style guide. Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
@@ -27,6 +27,7 @@ import (
|
||||
const viewQuery = `
|
||||
query($id: ID!) {
|
||||
node(id: $id) {
|
||||
__typename
|
||||
... on Profile {
|
||||
id
|
||||
fullName
|
||||
@@ -46,6 +47,7 @@ query($id: ID!) {
|
||||
|
||||
type viewResponse struct {
|
||||
Node *struct {
|
||||
Typename string `json:"__typename"`
|
||||
ID string `json:"id"`
|
||||
FullName string `json:"fullName"`
|
||||
EmailAddress string `json:"emailAddress"`
|
||||
@@ -106,6 +108,10 @@ func NewCmdView(f *cmdutil.Factory) *cobra.Command {
|
||||
return fmt.Errorf("user %s not found", args[0])
|
||||
}
|
||||
|
||||
if resp.Node.Typename != "Profile" {
|
||||
return fmt.Errorf("expected Profile node, got %s", resp.Node.Typename)
|
||||
}
|
||||
|
||||
if *flagOutput == cmdutil.OutputJSON {
|
||||
return cmdutil.PrintJSON(f.IOStreams.Out, resp.Node)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user