ModDepsForCall loads the module dependencies referenced by the given result call.
(ctx context.Context, rootCall *dagql.ResultCall)
| 276 | |
| 277 | // ModDepsForCall loads the module dependencies referenced by the given result call. |
| 278 | func (q *Query) ModDepsForCall(ctx context.Context, rootCall *dagql.ResultCall) (*SchemaBuilder, error) { |
| 279 | defaultDeps, err := q.DefaultDeps(ctx) |
| 280 | if err != nil { |
| 281 | return nil, fmt.Errorf("default deps: %w", err) |
| 282 | } |
| 283 | dag, err := CurrentDagqlServer(ctx) |
| 284 | if err != nil { |
| 285 | return nil, fmt.Errorf("bootstrap schema: %w", err) |
| 286 | } |
| 287 | |
| 288 | deps := defaultDeps |
| 289 | seenModuleResultIDs := map[uint64]struct{}{} |
| 290 | |
| 291 | appendModule := func(inst dagql.ObjectResult[*Module]) error { |
| 292 | if inst.Self() == nil { |
| 293 | return nil |
| 294 | } |
| 295 | if !inst.Self().Source.Valid { |
| 296 | // Bare dag.module() builder shells are intermediate construction results, |
| 297 | // not source-backed dependency modules to install into a schema. |
| 298 | return nil |
| 299 | } |
| 300 | instID, err := inst.ID() |
| 301 | if err != nil { |
| 302 | return fmt.Errorf("module %q handle ID: %w", inst.Self().Name(), err) |
| 303 | } |
| 304 | if instID == nil || instID.EngineResultID() == 0 { |
| 305 | return fmt.Errorf("module %q is not attached", inst.Self().Name()) |
| 306 | } |
| 307 | if _, seen := seenModuleResultIDs[instID.EngineResultID()]; seen { |
| 308 | return nil |
| 309 | } |
| 310 | seenModuleResultIDs[instID.EngineResultID()] = struct{}{} |
| 311 | deps = deps.Append(NewUserMod(inst)) |
| 312 | return nil |
| 313 | } |
| 314 | |
| 315 | cache, err := dagql.EngineCache(ctx) |
| 316 | if err != nil { |
| 317 | return nil, fmt.Errorf("engine cache: %w", err) |
| 318 | } |
| 319 | clientMetadata, err := engine.ClientMetadataFromContext(ctx) |
| 320 | if err != nil { |
| 321 | return nil, fmt.Errorf("current client metadata: %w", err) |
| 322 | } |
| 323 | if clientMetadata.SessionID == "" { |
| 324 | return nil, fmt.Errorf("empty session ID") |
| 325 | } |
| 326 | if err := cache.WalkResultCall(rootCall, func(ref *dagql.ResultCallRef, frame *dagql.ResultCall) error { |
| 327 | if ref == nil || ref.ResultID == 0 || frame == nil || frame.Type == nil || frame.Type.NamedType != "Module" { |
| 328 | return nil |
| 329 | } |
| 330 | res, err := cache.LoadResultByResultID(ctx, clientMetadata.SessionID, dag, ref.ResultID) |
| 331 | if err != nil { |
| 332 | return fmt.Errorf("load module result %d: %w", ref.ResultID, err) |
| 333 | } |
| 334 | modInst, ok := res.(dagql.ObjectResult[*Module]) |
| 335 | if !ok { |
no test coverage detected