/
module.go
709 lines (599 loc) · 21.2 KB
/
module.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
package core
import (
"context"
"fmt"
"log/slog"
"strings"
"time"
"github.com/dagger/dagger/dagql"
"github.com/dagger/dagger/dagql/call"
"github.com/moby/buildkit/solver/pb"
"github.com/vektah/gqlparser/v2/ast"
)
type Module struct {
Query *Query
// The source of the module
Source dagql.Instance[*ModuleSource] `field:"true" name:"source" doc:"The source for the module."`
// The name of the module
NameField string `field:"true" name:"name" doc:"The name of the module"`
// The original name of the module set in its configuration file (or first configured via withName).
// Different than NameField when a different name was specified for the module via a dependency.
OriginalName string
// The origin sdk of the module set in its configuration file (or first configured via withSDK).
OriginalSDK string
// The doc string of the module, if any
Description string `field:"true" doc:"The doc string of the module, if any"`
// The module's SDKConfig, as set in the module config file
SDKConfig string `field:"true" name:"sdk" doc:"The SDK used by this module. Either a name of a builtin SDK or a module source ref string pointing to the SDK's implementation."`
GeneratedContextDirectory dagql.Instance[*Directory] `field:"true" name:"generatedContextDirectory" doc:"The module source's context plus any configuration and source files created by codegen."`
// Dependencies as configured by the module
DependencyConfig []*ModuleDependency `field:"true" doc:"The dependencies as configured by the module."`
// The module's loaded dependencies, not yet initialized
DependenciesField []dagql.Instance[*Module] `field:"true" name:"dependencies" doc:"Modules used by this module."`
// Deps contains the module's dependency DAG.
Deps *ModDeps
// Runtime is the container that runs the module's entrypoint. It will fail to execute if the module doesn't compile.
Runtime *Container `field:"true" name:"runtime" doc:"The container that runs the module's entrypoint. It will fail to execute if the module doesn't compile."`
// The following are populated while initializing the module
// The module's objects
ObjectDefs []*TypeDef `field:"true" name:"objects" doc:"Objects served by this module."`
// The module's interfaces
InterfaceDefs []*TypeDef `field:"true" name:"interfaces" doc:"Interfaces served by this module."`
// InstanceID is the ID of the initialized module.
InstanceID *call.ID
}
func (*Module) Type() *ast.Type {
return &ast.Type{
NamedType: "Module",
NonNull: true,
}
}
func (*Module) TypeDescription() string {
return "A Dagger module."
}
type ModuleDependency struct {
Source dagql.Instance[*ModuleSource] `field:"true" name:"source" doc:"The source for the dependency module."`
Name string `field:"true" name:"name" doc:"The name of the dependency module."`
}
func (*ModuleDependency) Type() *ast.Type {
return &ast.Type{
NamedType: "ModuleDependency",
NonNull: true,
}
}
func (*ModuleDependency) TypeDescription() string {
return "The configuration of dependency of a module."
}
func (dep ModuleDependency) Clone() *ModuleDependency {
cp := dep
cp.Source.Self = dep.Source.Self.Clone()
return &cp
}
var _ Mod = (*Module)(nil)
func (mod *Module) Name() string {
return mod.NameField
}
func (mod *Module) Dependencies() []Mod {
mods := make([]Mod, len(mod.DependenciesField))
for i, dep := range mod.DependenciesField {
mods[i] = dep.Self
}
return mods
}
func (mod *Module) IDModule() *call.Module {
ref, err := mod.Source.Self.RefString()
if err != nil {
// TODO: this should be impossible by not, right? doesn't seem worth
// propagating error
panic(err)
}
return call.NewModule(mod.InstanceID, mod.Name(), ref)
}
func (mod *Module) Initialize(ctx context.Context, oldSelf dagql.Instance[*Module], newID *call.ID) (*Module, error) {
// construct a special function with no object or function name, which tells
// the SDK to return the module's definition (in terms of objects, fields and
// functions)
getModDefFn, err := newModFunction(
ctx,
mod.Query,
oldSelf.Self,
oldSelf.ID(),
nil,
mod.Runtime,
NewFunction("", &TypeDef{
Kind: TypeDefKindObject,
AsObject: dagql.NonNull(NewObjectTypeDef("Module", "")),
}))
if err != nil {
return nil, fmt.Errorf("failed to create module definition function for module %q: %w", mod.Name(), err)
}
result, err := getModDefFn.Call(ctx, newID, &CallOpts{Cache: true, SkipSelfSchema: true})
if err != nil {
return nil, fmt.Errorf("failed to call module %q to get functions: %w", mod.Name(), err)
}
inst, ok := result.(dagql.Instance[*Module])
if !ok {
return nil, fmt.Errorf("expected Module result, got %T", result)
}
newMod := mod.Clone()
newMod.Description = inst.Self.Description
for _, obj := range inst.Self.ObjectDefs {
newMod, err = newMod.WithObject(ctx, obj)
if err != nil {
return nil, fmt.Errorf("failed to add object to module %q: %w", mod.Name(), err)
}
}
for _, iface := range inst.Self.InterfaceDefs {
newMod, err = newMod.WithInterface(ctx, iface)
if err != nil {
return nil, fmt.Errorf("failed to add interface to module %q: %w", mod.Name(), err)
}
}
newMod.InstanceID = newID
return newMod, nil
}
func (mod *Module) Install(ctx context.Context, dag *dagql.Server) error {
slog.Debug("installing module", "name", mod.Name())
start := time.Now()
defer func() { slog.Debug("done installing module", "name", mod.Name(), "took", time.Since(start)) }()
for _, def := range mod.ObjectDefs {
objDef := def.AsObject.Value
slog.Debug("installing object", "name", mod.Name(), "object", objDef.Name)
// check whether this is a pre-existing object from a dependency module
modType, ok, err := mod.Deps.ModTypeFor(ctx, def)
if err != nil {
return fmt.Errorf("failed to get mod type for type def: %w", err)
}
if ok {
// NB: this is defense-in-depth to prevent SDKs or some other future
// component from allowing modules to extend external objects.
return fmt.Errorf("type %q is already defined by module %q",
objDef.Name,
modType.SourceMod().Name())
}
obj := &ModuleObject{
Module: mod,
TypeDef: objDef,
}
if err := obj.Install(ctx, dag); err != nil {
return err
}
}
for _, def := range mod.InterfaceDefs {
ifaceDef := def.AsInterface.Value
slog.Debug("installing interface", "name", mod.Name(), "interface", ifaceDef.Name)
iface := &InterfaceType{
typeDef: ifaceDef,
mod: mod,
}
if err := iface.Install(ctx, dag); err != nil {
return err
}
}
return nil
}
func (mod *Module) TypeDefs(ctx context.Context) ([]*TypeDef, error) {
typeDefs := make([]*TypeDef, 0, len(mod.ObjectDefs)+len(mod.InterfaceDefs))
for _, def := range mod.ObjectDefs {
typeDef := def.Clone()
if typeDef.AsObject.Valid {
typeDef.AsObject.Value.SourceModuleName = mod.Name()
}
typeDefs = append(typeDefs, typeDef)
}
for _, def := range mod.InterfaceDefs {
typeDef := def.Clone()
if typeDef.AsInterface.Valid {
typeDef.AsInterface.Value.SourceModuleName = mod.Name()
}
typeDefs = append(typeDefs, typeDef)
}
return typeDefs, nil
}
func (mod *Module) DependencySchemaIntrospectionJSON(ctx context.Context, forModule bool) (string, error) {
return mod.Deps.SchemaIntrospectionJSON(ctx, forModule)
}
func (mod *Module) ModTypeFor(ctx context.Context, typeDef *TypeDef, checkDirectDeps bool) (ModType, bool, error) {
var modType ModType
switch typeDef.Kind {
case TypeDefKindString, TypeDefKindInteger, TypeDefKindBoolean, TypeDefKindVoid:
modType = &PrimitiveType{typeDef}
case TypeDefKindList:
underlyingType, ok, err := mod.ModTypeFor(ctx, typeDef.AsList.Value.ElementTypeDef, checkDirectDeps)
if err != nil {
return nil, false, fmt.Errorf("failed to get underlying type: %w", err)
}
if !ok {
return nil, false, nil
}
modType = &ListType{
Elem: typeDef.AsList.Value.ElementTypeDef,
Underlying: underlyingType,
}
case TypeDefKindObject:
if checkDirectDeps {
// check to see if this is from a *direct* dependency
depType, ok, err := mod.Deps.ModTypeFor(ctx, typeDef)
if err != nil {
return nil, false, fmt.Errorf("failed to get type from dependency: %w", err)
}
if ok {
return depType, true, nil
}
}
var found bool
// otherwise it must be from this module
for _, obj := range mod.ObjectDefs {
if obj.AsObject.Value.Name == typeDef.AsObject.Value.Name {
modType = &ModuleObjectType{
typeDef: obj.AsObject.Value,
mod: mod,
}
found = true
break
}
}
if !found {
slog.Debug("module did not find object", "mod", mod.Name(), "object", typeDef.AsObject.Value.Name)
return nil, false, nil
}
case TypeDefKindInterface:
if checkDirectDeps {
// check to see if this is from a *direct* dependency
depType, ok, err := mod.Deps.ModTypeFor(ctx, typeDef)
if err != nil {
return nil, false, fmt.Errorf("failed to get interface type from dependency: %w", err)
}
if ok {
return depType, true, nil
}
}
var found bool
// otherwise it must be from this module
for _, iface := range mod.InterfaceDefs {
if iface.AsInterface.Value.Name == typeDef.AsInterface.Value.Name {
modType = &InterfaceType{
mod: mod,
typeDef: iface.AsInterface.Value,
}
found = true
break
}
}
if !found {
slog.Debug("module did not find interface", "mod", mod.Name(), "interface", typeDef.AsInterface.Value.Name)
return nil, false, nil
}
default:
return nil, false, fmt.Errorf("unexpected type def kind %s", typeDef.Kind)
}
if typeDef.Optional {
modType = &NullableType{
InnerDef: typeDef.WithOptional(false),
Inner: modType,
}
}
return modType, true, nil
}
// verify the typedef is has no reserved names
func (mod *Module) validateTypeDef(ctx context.Context, typeDef *TypeDef) error {
switch typeDef.Kind {
case TypeDefKindList:
return mod.validateTypeDef(ctx, typeDef.AsList.Value.ElementTypeDef)
case TypeDefKindObject:
return mod.validateObjectTypeDef(ctx, typeDef)
case TypeDefKindInterface:
return mod.validateInterfaceTypeDef(ctx, typeDef)
}
return nil
}
func (mod *Module) validateObjectTypeDef(ctx context.Context, typeDef *TypeDef) error {
// check whether this is a pre-existing object from core or another module
modType, ok, err := mod.Deps.ModTypeFor(ctx, typeDef)
if err != nil {
return fmt.Errorf("failed to get mod type for type def: %w", err)
}
if ok {
if sourceMod := modType.SourceMod(); sourceMod != nil && sourceMod != mod {
// already validated, skip
return nil
}
}
obj := typeDef.AsObject.Value
for _, field := range obj.Fields {
if gqlFieldName(field.Name) == "id" {
return fmt.Errorf("cannot define field with reserved name %q on object %q", field.Name, obj.Name)
}
fieldType, ok, err := mod.Deps.ModTypeFor(ctx, field.TypeDef)
if err != nil {
return fmt.Errorf("failed to get mod type for type def: %w", err)
}
if ok {
sourceMod := fieldType.SourceMod()
// fields can reference core types and local types, but not types from
// other modules
if sourceMod != nil && sourceMod.Name() != ModuleName && sourceMod != mod {
return fmt.Errorf("object %q field %q cannot reference external type from dependency module %q",
obj.OriginalName,
field.OriginalName,
sourceMod.Name(),
)
}
}
if err := mod.validateTypeDef(ctx, field.TypeDef); err != nil {
return err
}
}
for _, fn := range obj.Functions {
if gqlFieldName(fn.Name) == "id" {
return fmt.Errorf("cannot define function with reserved name %q on object %q", fn.Name, obj.Name)
}
// Check if this is a type from another (non-core) module, which is currently not allowed
retType, ok, err := mod.Deps.ModTypeFor(ctx, fn.ReturnType)
if err != nil {
return fmt.Errorf("failed to get mod type for type def: %w", err)
}
if ok {
if sourceMod := retType.SourceMod(); sourceMod != nil && sourceMod.Name() != ModuleName && sourceMod != mod {
// already validated, skip
return fmt.Errorf("object %q function %q cannot return external type from dependency module %q",
obj.OriginalName,
fn.OriginalName,
sourceMod.Name(),
)
}
}
if err := mod.validateTypeDef(ctx, fn.ReturnType); err != nil {
return err
}
for _, arg := range fn.Args {
argType, ok, err := mod.Deps.ModTypeFor(ctx, arg.TypeDef)
if err != nil {
return fmt.Errorf("failed to get mod type for type def: %w", err)
}
if ok {
if sourceMod := argType.SourceMod(); sourceMod != nil && sourceMod.Name() != ModuleName && sourceMod != mod {
// already validated, skip
return fmt.Errorf("object %q function %q arg %q cannot reference external type from dependency module %q",
obj.OriginalName,
fn.OriginalName,
arg.OriginalName,
sourceMod.Name(),
)
}
}
if err := mod.validateTypeDef(ctx, arg.TypeDef); err != nil {
return err
}
}
}
return nil
}
func (mod *Module) validateInterfaceTypeDef(ctx context.Context, typeDef *TypeDef) error {
iface := typeDef.AsInterface.Value
// check whether this is a pre-existing interface from core or another module
modType, ok, err := mod.Deps.ModTypeFor(ctx, typeDef)
if err != nil {
return fmt.Errorf("failed to get mod type for type def: %w", err)
}
if ok {
if sourceMod := modType.SourceMod(); sourceMod != nil && sourceMod != mod {
// already validated, skip
return nil
}
}
for _, fn := range iface.Functions {
if gqlFieldName(fn.Name) == "id" {
return fmt.Errorf("cannot define function with reserved name %q on interface %q", fn.Name, iface.Name)
}
if err := mod.validateTypeDef(ctx, fn.ReturnType); err != nil {
return err
}
for _, arg := range fn.Args {
if err := mod.validateTypeDef(ctx, arg.TypeDef); err != nil {
return err
}
}
}
return nil
}
// prefix the given typedef (and any recursively referenced typedefs) with this module's name for any objects
func (mod *Module) namespaceTypeDef(ctx context.Context, typeDef *TypeDef) error {
switch typeDef.Kind {
case TypeDefKindList:
if err := mod.namespaceTypeDef(ctx, typeDef.AsList.Value.ElementTypeDef); err != nil {
return err
}
case TypeDefKindObject:
obj := typeDef.AsObject.Value
// only namespace objects defined in this module
_, ok, err := mod.Deps.ModTypeFor(ctx, typeDef)
if err != nil {
return fmt.Errorf("failed to get mod type for type def: %w", err)
}
if !ok {
obj.Name = namespaceObject(obj.OriginalName, mod.Name(), mod.OriginalName)
}
for _, field := range obj.Fields {
if err := mod.namespaceTypeDef(ctx, field.TypeDef); err != nil {
return err
}
}
for _, fn := range obj.Functions {
if err := mod.namespaceTypeDef(ctx, fn.ReturnType); err != nil {
return err
}
for _, arg := range fn.Args {
if err := mod.namespaceTypeDef(ctx, arg.TypeDef); err != nil {
return err
}
}
}
case TypeDefKindInterface:
iface := typeDef.AsInterface.Value
// only namespace interfaces defined in this module
_, ok, err := mod.Deps.ModTypeFor(ctx, typeDef)
if err != nil {
return fmt.Errorf("failed to get mod type for type def: %w", err)
}
if !ok {
iface.Name = namespaceObject(iface.OriginalName, mod.Name(), mod.OriginalName)
}
for _, fn := range iface.Functions {
if err := mod.namespaceTypeDef(ctx, fn.ReturnType); err != nil {
return err
}
for _, arg := range fn.Args {
if err := mod.namespaceTypeDef(ctx, arg.TypeDef); err != nil {
return err
}
}
}
}
return nil
}
/*
Mod is a module in loaded into the server's DAG of modules; it's the vertex type of the DAG.
It's an interface so we can abstract over user modules and core and treat them the same.
*/
type Mod interface {
// The name of the module
Name() string
// The direct dependencies of this module
Dependencies() []Mod
// TODO describe
Install(context.Context, *dagql.Server) error
// ModTypeFor returns the ModType for the given typedef based on this module's schema.
// The returned type will have any namespacing already applied.
// If checkDirectDeps is true, then its direct dependencies will also be checked.
ModTypeFor(ctx context.Context, typeDef *TypeDef, checkDirectDeps bool) (ModType, bool, error)
// All the TypeDefs exposed by this module (does not include dependencies)
TypeDefs(ctx context.Context) ([]*TypeDef, error)
}
/*
An SDK is an implementation of the functionality needed to generate code for and execute a module.
There is one special SDK, the Go SDK, which is implemented in `goSDK` below. It's used as the "seed" for all
other SDK implementations.
All other SDKs are themselves implemented as Modules, with Functions matching the two defined in this SDK interface.
An SDK Module needs to choose its own SDK for its implementation. This can be "well-known" built-in SDKs like "go",
"python", etc. Or it can be any external module as specified with a module source ref string.
You can thus think of SDK Modules as a DAG of dependencies, with each SDK using a different SDK to implement its Module,
with the Go SDK as the root of the DAG and the only one without any dependencies.
Built-in SDKs are also a bit special in that they come bundled w/ the engine container image, which allows them
to be used without hard dependencies on the internet. They are loaded w/ the `loadBuiltinSDK` function below, which
loads them as modules from the engine container.
*/
type SDK interface {
/* Codegen generates code for the module at the given source directory and subpath.
The Code field of the returned GeneratedCode object should be the generated contents of the module sourceDirSubpath,
in the case where that's different than the root of the sourceDir.
The provided Module is not fully initialized; the Runtime field will not be set yet.
*/
Codegen(context.Context, *ModDeps, dagql.Instance[*ModuleSource]) (*GeneratedCode, error)
/* Runtime returns a container that is used to execute module code at runtime in the Dagger engine.
The provided Module is not fully initialized; the Runtime field will not be set yet.
*/
Runtime(context.Context, *ModDeps, dagql.Instance[*ModuleSource]) (*Container, error)
// Paths that should always be loaded from module sources using this SDK. Ensures that e.g. main.go
// in the Go SDK is always loaded even if dagger.json has include settings that don't include it.
RequiredPaths(context.Context) ([]string, error)
}
var _ HasPBDefinitions = (*Module)(nil)
func (mod *Module) PBDefinitions(ctx context.Context) ([]*pb.Definition, error) {
var defs []*pb.Definition
if mod.Source.Self != nil {
dirDefs, err := mod.Source.Self.PBDefinitions(ctx)
if err != nil {
return nil, err
}
defs = append(defs, dirDefs...)
}
return defs, nil
}
func (mod Module) Clone() *Module {
cp := mod
if mod.Source.Self != nil {
cp.Source.Self = mod.Source.Self.Clone()
}
cp.DependencyConfig = make([]*ModuleDependency, len(mod.DependencyConfig))
for i, dep := range mod.DependencyConfig {
cp.DependencyConfig[i] = dep.Clone()
}
cp.DependenciesField = make([]dagql.Instance[*Module], len(mod.DependenciesField))
for i, dep := range mod.DependenciesField {
cp.DependenciesField[i].Self = dep.Self.Clone()
}
cp.ObjectDefs = make([]*TypeDef, len(mod.ObjectDefs))
for i, def := range mod.ObjectDefs {
cp.ObjectDefs[i] = def.Clone()
}
cp.InterfaceDefs = make([]*TypeDef, len(mod.InterfaceDefs))
for i, def := range mod.InterfaceDefs {
cp.InterfaceDefs[i] = def.Clone()
}
return &cp
}
func (mod *Module) WithDescription(desc string) *Module {
mod = mod.Clone()
mod.Description = strings.TrimSpace(desc)
return mod
}
func (mod *Module) WithObject(ctx context.Context, def *TypeDef) (*Module, error) {
mod = mod.Clone()
if !def.AsObject.Valid {
return nil, fmt.Errorf("expected object type def, got %s: %+v", def.Kind, def)
}
// skip validation+namespacing for module objects being constructed by SDK with* calls
// they will be validated when merged into the real final module
if mod.Deps != nil {
if err := mod.validateTypeDef(ctx, def); err != nil {
return nil, fmt.Errorf("failed to validate type def: %w", err)
}
}
if mod.NameField != "" {
def = def.Clone()
if err := mod.namespaceTypeDef(ctx, def); err != nil {
return nil, fmt.Errorf("failed to namespace type def: %w", err)
}
}
mod.ObjectDefs = append(mod.ObjectDefs, def)
return mod, nil
}
func (mod *Module) WithInterface(ctx context.Context, def *TypeDef) (*Module, error) {
mod = mod.Clone()
if !def.AsInterface.Valid {
return nil, fmt.Errorf("expected interface type def, got %s: %+v", def.Kind, def)
}
// skip validation+namespacing for module objects being constructed by SDK with* calls
// they will be validated when merged into the real final module
if mod.Deps != nil {
if err := mod.validateTypeDef(ctx, def); err != nil {
return nil, fmt.Errorf("failed to validate type def: %w", err)
}
}
if mod.NameField != "" {
def = def.Clone()
if err := mod.namespaceTypeDef(ctx, def); err != nil {
return nil, fmt.Errorf("failed to namespace type def: %w", err)
}
}
mod.InterfaceDefs = append(mod.InterfaceDefs, def)
return mod, nil
}
type CurrentModule struct {
Module *Module
}
func (*CurrentModule) Type() *ast.Type {
return &ast.Type{
NamedType: "CurrentModule",
NonNull: true,
}
}
func (*CurrentModule) TypeDescription() string {
return "Reflective module API provided to functions at runtime."
}
func (mod CurrentModule) Clone() *CurrentModule {
cp := mod
cp.Module = mod.Module.Clone()
return &cp
}