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

Method loadTypeDefs

cmd/dagger/module_inspect.go:299–406  ·  view source on GitHub ↗

loadTypeDefs loads the objects defined by the given module in an easier to use data structure.

(ctx context.Context, dag *dagger.Client, opts ...loadTypeDefsOpts)

Source from the content-addressed store, hash-verified

297
298// loadTypeDefs loads the objects defined by the given module in an easier to use data structure.
299func (m *moduleDef) loadTypeDefs(ctx context.Context, dag *dagger.Client, opts ...loadTypeDefsOpts) (rerr error) {
300 ctx, loadSpan := Tracer().Start(ctx, "loading type definitions", telemetry.Encapsulate())
301 defer telemetry.EndWithCause(loadSpan, &rerr)
302
303 var o loadTypeDefsOpts
304 if len(opts) > 0 {
305 o = opts[0]
306 }
307
308 var res struct {
309 TypeDefs []*modTypeDef
310 }
311
312 err := dag.Do(ctx, &dagger.Request{
313 Query: loadTypeDefsQuery,
314 Variables: map[string]any{"hideCore": o.HideCore},
315 }, &dagger.Response{
316 Data: &res,
317 })
318 if err != nil {
319 return fmt.Errorf("query module objects: %w", err)
320 }
321
322 m.MainObject = nil
323 m.Objects = nil
324 m.Interfaces = nil
325 m.Enums = nil
326 m.Inputs = nil
327 m.typeDefsByName = make(map[string]*modTypeDef, len(res.TypeDefs))
328
329 for _, typeDef := range res.TypeDefs {
330 if typeDef == nil {
331 return fmt.Errorf("currentTypeDefs returned nil TypeDef")
332 }
333 if typeDef.TypeName == "" {
334 return fmt.Errorf("currentTypeDefs returned %s without canonical name", typeDef.Kind)
335 }
336 if _, found := m.typeDefsByName[typeDef.TypeName]; found {
337 continue
338 }
339 m.typeDefsByName[typeDef.TypeName] = typeDef
340 typeDef.owner = m
341 switch typeDef.Kind {
342 case dagger.TypeDefKindObjectKind:
343 m.Objects = append(m.Objects, typeDef)
344 if typeDef.AsObject != nil {
345 typeDef.AsObject.owner = m
346 typeDef.AsObject.typeDef = typeDef
347 }
348 case dagger.TypeDefKindInterfaceKind:
349 m.Interfaces = append(m.Interfaces, typeDef)
350 if typeDef.AsInterface != nil {
351 typeDef.AsInterface.owner = m
352 typeDef.AsInterface.typeDef = typeDef
353 }
354 case dagger.TypeDefKindEnumKind:
355 m.Enums = append(m.Enums, typeDef)
356 case dagger.TypeDefKindInputKind:

Callers 4

initializeCoreFunction · 0.95
initializeWorkspaceFunction · 0.95
registerCommandsMethod · 0.95
initializeModuleFunction · 0.80

Calls 7

GetTypeDefMethod · 0.95
LoadFunctionTypeDefsMethod · 0.95
EncapsulateMethod · 0.80
TracerFunction · 0.70
gqlFieldNameFunction · 0.70
StartMethod · 0.65
DoMethod · 0.45

Tested by

no test coverage detected