setCallInputs sets the call inputs for the function call. It first loads the argument set by the user. Then the default values. Finally the contextual arguments.
(ctx context.Context, opts *CallOpts)
| 144 | // Then the default values. |
| 145 | // Finally the contextual arguments. |
| 146 | func (fn *ModuleFunction) setCallInputs(ctx context.Context, opts *CallOpts) ([]*FunctionCallArgValue, error) { |
| 147 | callInputs := make([]*FunctionCallArgValue, len(opts.Inputs)) |
| 148 | hasArg := map[string]bool{} |
| 149 | |
| 150 | for i, input := range opts.Inputs { |
| 151 | normalizedName := gqlArgName(input.Name) |
| 152 | arg, ok := fn.args[normalizedName] |
| 153 | if !ok { |
| 154 | return nil, fmt.Errorf("find arg %q", input.Name) |
| 155 | } |
| 156 | |
| 157 | name := arg.metadata.OriginalName |
| 158 | |
| 159 | converted, err := arg.modType.ConvertToSDKInput(ctx, input.Value) |
| 160 | if err != nil { |
| 161 | return nil, fmt.Errorf("convert arg %q: %w", input.Name, err) |
| 162 | } |
| 163 | |
| 164 | if len(arg.metadata.Ignore) > 0 && !arg.metadata.isContextual() { // contextual args already have ignore applied |
| 165 | converted, err = fn.applyIgnoreOnDir(ctx, opts.Server, arg.metadata, converted) |
| 166 | if err != nil { |
| 167 | return nil, fmt.Errorf("apply ignore pattern on arg %q: %w", input.Name, err) |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | encoded, err := json.Marshal(converted) |
| 172 | if err != nil { |
| 173 | return nil, fmt.Errorf("marshal arg %q: %w", input.Name, err) |
| 174 | } |
| 175 | |
| 176 | callInputs[i] = &FunctionCallArgValue{ |
| 177 | Name: name, |
| 178 | Value: encoded, |
| 179 | } |
| 180 | |
| 181 | hasArg[name] = true |
| 182 | } |
| 183 | |
| 184 | // Load default value |
| 185 | for _, argRes := range fn.metadata.Args { |
| 186 | arg := argRes.Self() |
| 187 | name := arg.OriginalName |
| 188 | if hasArg[name] { |
| 189 | continue |
| 190 | } |
| 191 | userDefault, hasUserDefault, err := fn.UserDefault(ctx, arg.Name) |
| 192 | if err != nil { |
| 193 | return nil, fmt.Errorf("load user defaults for function %q: %w", fn.metadata.Name, err) |
| 194 | } |
| 195 | hasModuleDefault := (arg.DefaultValue != nil) |
| 196 | |
| 197 | var defaultInput *FunctionCallArgValue |
| 198 | if hasUserDefault { |
| 199 | // 1. User-defined user default |
| 200 | userDefaultInput, err := userDefault.CallInput(ctx) |
| 201 | if err != nil { |
| 202 | return nil, err |
| 203 | } |
no test coverage detected