MCPcopy Create free account
hub / github.com/cli/cli / operationVariables

Function operationVariables

script/ghmock/gqlscaffold.go:72–93  ·  view source on GitHub ↗
(op *ast.OperationDefinition, raw json.RawMessage)

Source from the content-addressed store, hash-verified

70}
71
72func operationVariables(op *ast.OperationDefinition, raw json.RawMessage) (map[string]any, error) {
73 var values map[string]any
74 if len(raw) > 0 {
75 if err := json.Unmarshal(raw, &values); err != nil {
76 return nil, fmt.Errorf("reading GraphQL variables: %w", err)
77 }
78 }
79 if values == nil {
80 values = map[string]any{}
81 }
82 for _, def := range op.VariableDefinitions {
83 if _, supplied := values[def.Variable]; supplied || def.DefaultValue == nil {
84 continue
85 }
86 value, err := def.DefaultValue.Value(nil)
87 if err != nil {
88 return nil, fmt.Errorf("reading default for $%s: %w", def.Variable, err)
89 }
90 values[def.Variable] = value
91 }
92 return values, nil
93}
94
95// fillObject adds the fields that sel asks for and obj lacks. With record set,
96// it remembers where it added them, so they can be reported.

Callers 2

trimGraphQLFunction · 0.85
useVariablesMethod · 0.85

Calls 2

ValueMethod · 0.80
ErrorfMethod · 0.65

Tested by

no test coverage detected