(op *ast.OperationDefinition, raw json.RawMessage)
| 70 | } |
| 71 | |
| 72 | func 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. |
no test coverage detected