MCPcopy Index your code
hub / github.com/dagger/dagger / runModuleDefInSDK

Method runModuleDefInSDK

core/schema/modulesource.go:2786–2938  ·  view source on GitHub ↗
(ctx context.Context, mod *core.Module)

Source from the content-addressed store, hash-verified

2784}
2785
2786func (s *moduleSourceSchema) runModuleDefInSDK(ctx context.Context, mod *core.Module) (*core.Module, error) {
2787 dag, err := core.CurrentDagqlServer(ctx)
2788 if err != nil {
2789 return nil, fmt.Errorf("failed to get dag server: %w", err)
2790 }
2791
2792 mod = mod.Clone()
2793 src := mod.Source.Value
2794
2795 modName := src.Self().ModuleName
2796
2797 runtimeImpl, ok := src.Self().SDKImpl.AsRuntime()
2798 if !ok {
2799 return nil, ErrSDKRuntimeNotImplemented{SDK: src.Self().SDK.Source}
2800 }
2801
2802 var initialized *core.Module
2803
2804 typeDefsImpl, typeDefsEnabled := src.Self().SDKImpl.AsModuleTypes()
2805 if typeDefsEnabled {
2806 var resultInst dagql.ObjectResult[*core.Module]
2807 resultInst, err = typeDefsImpl.ModuleTypes(ctx, mod.Deps, src, mod)
2808 if err != nil {
2809 return nil, fmt.Errorf("failed to initialize module: %w", err)
2810 }
2811 initialized = resultInst.Self()
2812 } else {
2813 runtime, err := runtimeImpl.Runtime(ctx, mod.Deps, src)
2814 if err != nil {
2815 return nil, fmt.Errorf("failed to get module runtime: %w", err)
2816 }
2817 if ctr, ok := runtime.AsContainer(); ok {
2818 mod.Runtime = dagql.NonNull(ctr)
2819 }
2820
2821 // construct a special function with no object or function name, which tells
2822 // the SDK to return the module's definition (in terms of objects, fields and
2823 // functions)
2824
2825 err = (func() (rerr error) {
2826 ctx, span := core.Tracer(ctx).Start(ctx, "asModule getModDef", telemetry.Internal())
2827 defer telemetry.EndWithCause(span, &rerr)
2828
2829 opScope := "getModDef"
2830 scopedMod, err := sdk.ScopeModuleForSDKOperation(ctx, mod, opScope, dag)
2831 if err != nil {
2832 return fmt.Errorf("failed to create scoped module for getModDef: %w", err)
2833 }
2834 returnType, err := core.SelectTypeDefWithServer(ctx, dag, dagql.Selector{
2835 Field: "withObject",
2836 Args: []dagql.NamedInput{{Name: "name", Value: dagql.String("Module")}},
2837 })
2838 if err != nil {
2839 return fmt.Errorf("failed to create module definition return type for module %q: %w", modName, err)
2840 }
2841
2842 getModDefFn, err := core.NewModFunction(
2843 ctx,

Callers 1

moduleSourceAsModuleMethod · 0.95

Calls 15

CurrentDagqlServerFunction · 0.92
NonNullFunction · 0.92
TracerFunction · 0.92
SelectTypeDefWithServerFunction · 0.92
StringTypeAlias · 0.92
NewModFunctionFunction · 0.92
NewFunctionFunction · 0.92
ExtraDebugFunction · 0.92
NewUserModFunction · 0.92
isSelfCallsEnabledFunction · 0.85

Tested by

no test coverage detected