loadContextualArg loads a contextual argument from the module context directory or address. For Directory, it will load the directory from the module context directory. For File, it will load the directory containing the file and then query the file ID from this directory. For Container, it will lo
( ctx context.Context, dag *dagql.Server, arg *FunctionArg, )
| 1023 | // |
| 1024 | // This functions returns the ID of the loaded object. |
| 1025 | func (fn *ModuleFunction) loadContextualArg( |
| 1026 | ctx context.Context, |
| 1027 | dag *dagql.Server, |
| 1028 | arg *FunctionArg, |
| 1029 | ) (dagql.IDType, error) { |
| 1030 | if arg.TypeDef.Self().Kind != TypeDefKindObject { |
| 1031 | return nil, fmt.Errorf("contextual argument %q must be an object", arg.OriginalName) |
| 1032 | } |
| 1033 | if dag == nil { |
| 1034 | return nil, fmt.Errorf("dagql server is nil but required for contextual argument %q", arg.OriginalName) |
| 1035 | } |
| 1036 | |
| 1037 | // Handle Container types with DefaultAddress |
| 1038 | if arg.DefaultAddress != "" { |
| 1039 | if arg.TypeDef.Self().AsObject.Value.Self().Name != "Container" { |
| 1040 | return nil, fmt.Errorf("defaultAddress can only be used with Container type, not %s", arg.TypeDef.Self().AsObject.Value.Self().Name) |
| 1041 | } |
| 1042 | return loadContainerFromAddress(ctx, dag, arg.DefaultAddress) |
| 1043 | } |
| 1044 | |
| 1045 | if arg.DefaultPath == "" { |
| 1046 | return nil, fmt.Errorf("argument %q is not a contextual argument", arg.OriginalName) |
| 1047 | } |
| 1048 | |
| 1049 | // Legacy compat: resolve +defaultPath from workspace root for migrated |
| 1050 | // blueprints/toolchains instead of the module's own source directory. |
| 1051 | if fn.mod.Self().LegacyDefaultPath { |
| 1052 | return fn.loadLegacyDefaultPathArg(ctx, dag, arg) |
| 1053 | } |
| 1054 | |
| 1055 | switch arg.TypeDef.Self().AsObject.Value.Self().Name { |
| 1056 | case "Directory": |
| 1057 | dir, err := fn.mod.Self().ContextSource.Value.Self().LoadContextDir(ctx, dag, arg.DefaultPath, CopyFilter{ |
| 1058 | Exclude: arg.Ignore, |
| 1059 | }) |
| 1060 | if err != nil { |
| 1061 | return nil, fmt.Errorf("load contextual directory %q: %w", arg.DefaultPath, err) |
| 1062 | } |
| 1063 | dirID, err := dir.ID() |
| 1064 | if err != nil { |
| 1065 | return nil, fmt.Errorf("get contextual directory ID %q: %w", arg.DefaultPath, err) |
| 1066 | } |
| 1067 | return dagql.NewID[*Directory](dirID), nil |
| 1068 | |
| 1069 | case "File": |
| 1070 | f, err := fn.mod.Self().ContextSource.Value.Self().LoadContextFile(ctx, dag, arg.DefaultPath) |
| 1071 | if err != nil { |
| 1072 | return nil, fmt.Errorf("load contextual file %q: %w", arg.DefaultPath, err) |
| 1073 | } |
| 1074 | fileID, err := f.ID() |
| 1075 | if err != nil { |
| 1076 | return nil, fmt.Errorf("get contextual file ID %q: %w", arg.DefaultPath, err) |
| 1077 | } |
| 1078 | return dagql.NewID[*File](fileID), nil |
| 1079 | |
| 1080 | case "GitRepository", "GitRef": |
| 1081 | return fn.loadContextualGitArg(ctx, dag, arg) |
| 1082 | } |
no test coverage detected