(ctx context.Context, dag *dagql.Server, opts ...InstallOpts)
| 971 | } |
| 972 | |
| 973 | func (obj *ModuleObject) Install(ctx context.Context, dag *dagql.Server, opts ...InstallOpts) error { |
| 974 | if obj.Module.Self() == nil { |
| 975 | return fmt.Errorf("installing object %q too early", obj.TypeDef.Name) |
| 976 | } |
| 977 | |
| 978 | var opt InstallOpts |
| 979 | if len(opts) > 0 { |
| 980 | opt = opts[0] |
| 981 | } |
| 982 | |
| 983 | classOpts := dagql.ClassOpts[*ModuleObject]{ |
| 984 | Typed: obj, |
| 985 | } |
| 986 | |
| 987 | installDirectives := []*ast.Directive{} |
| 988 | if obj.TypeDef.SourceMap.Valid { |
| 989 | classOpts.SourceMap = obj.TypeDef.SourceMap.Value.Self().TypeDirective() |
| 990 | installDirectives = append(installDirectives, obj.TypeDef.SourceMap.Value.Self().TypeDirective()) |
| 991 | } |
| 992 | |
| 993 | class := dagql.NewClass(dag, classOpts) |
| 994 | if obj.isMainObject() && !opt.SkipConstructor && !opt.Entrypoint { |
| 995 | if err := obj.installConstructor(ctx, dag); err != nil { |
| 996 | return fmt.Errorf("failed to install constructor: %w", err) |
| 997 | } |
| 998 | } |
| 999 | fields, err := obj.fields(ctx) |
| 1000 | if err != nil { |
| 1001 | return err |
| 1002 | } |
| 1003 | |
| 1004 | funs, err := obj.functions(ctx, dag) |
| 1005 | if err != nil { |
| 1006 | return err |
| 1007 | } |
| 1008 | fields = append(fields, funs...) |
| 1009 | |
| 1010 | class.Install(fields...) |
| 1011 | dag.InstallObject(class, installDirectives...) |
| 1012 | |
| 1013 | if obj.isMainObject() && opt.Entrypoint { |
| 1014 | if err := obj.installEntrypointMethods(ctx, dag); err != nil { |
| 1015 | return fmt.Errorf("failed to install entrypoint methods: %w", err) |
| 1016 | } |
| 1017 | } |
| 1018 | |
| 1019 | return nil |
| 1020 | } |
| 1021 | |
| 1022 | func (obj *ModuleObject) isMainObject() bool { |
| 1023 | return gqlObjectName(obj.TypeDef.OriginalName) == gqlObjectName(obj.Module.Self().OriginalName) |
no test coverage detected