MCPcopy Create free account
hub / github.com/dagger/dagger / ParseField

Method ParseField

dagql/interfaces.go:131–163  ·  view source on GitHub ↗

ParseField parses an AST field selection against this interface's field specs. This is used when a query selects fields on an interface-typed return value.

(ctx context.Context, view call.View, astField *ast.Field, vars map[string]any)

Source from the content-addressed store, hash-verified

129// ParseField parses an AST field selection against this interface's field specs.
130// This is used when a query selects fields on an interface-typed return value.
131func (iface *Interface) ParseField(ctx context.Context, view call.View, astField *ast.Field, vars map[string]any) (Selector, *ast.Type, error) {
132 spec, ok := iface.FieldSpec(astField.Name, view)
133 if !ok {
134 return Selector{}, nil, fmt.Errorf("%s has no such field: %q", iface.name, astField.Name)
135 }
136 args := make([]NamedInput, len(astField.Arguments))
137 for i, arg := range astField.Arguments {
138 argSpec, ok := spec.Args.Input(arg.Name, view)
139 if !ok {
140 return Selector{}, nil, fmt.Errorf("%s.%s has no such argument: %q", iface.name, spec.Name, arg.Name)
141 }
142 if argSpec.Internal {
143 return Selector{}, nil, fmt.Errorf("cannot use internal argument %q in selector for %s.%s", arg.Name, iface.name, spec.Name)
144 }
145 val, err := arg.Value.Value(vars)
146 if err != nil {
147 return Selector{}, nil, err
148 }
149 input, err := argSpec.Type.Decoder().DecodeInput(val)
150 if err != nil {
151 return Selector{}, nil, fmt.Errorf("init arg %q value as %T (%s) using %T: %w", arg.Name, argSpec.Type, argSpec.Type.Type(), argSpec.Type.Decoder(), err)
152 }
153 args[i] = NamedInput{
154 Name: arg.Name,
155 Value: input,
156 }
157 }
158 return Selector{
159 Field: astField.Name,
160 Args: args,
161 View: view,
162 }, spec.Type.Type(), nil
163}
164
165// Definition returns the ast.Definition for this interface for the given view.
166func (iface *Interface) Definition(view call.View) *ast.Definition {

Callers

nothing calls this directly

Calls 6

FieldSpecMethod · 0.95
ValueMethod · 0.65
DecodeInputMethod · 0.65
DecoderMethod · 0.65
TypeMethod · 0.65
InputMethod · 0.45

Tested by

no test coverage detected