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

Function QueryWithClient

internal/testutil/query.go:32–66  ·  view source on GitHub ↗
(c *dagger.Client, t *testctx.T, query string, opts *QueryOptions)

Source from the content-addressed store, hash-verified

30}
31
32func QueryWithClient[R any](c *dagger.Client, t *testctx.T, query string, opts *QueryOptions) (*R, error) {
33 t.Helper()
34 ctx := t.Context()
35
36 if opts == nil {
37 opts = &QueryOptions{}
38 }
39 if opts.Variables == nil {
40 opts.Variables = make(map[string]any)
41 }
42 if opts.Secrets == nil {
43 opts.Secrets = make(map[string]string)
44 }
45 for n, v := range opts.Secrets {
46 s, err := newSecret(ctx, c, n, v)
47 if err != nil {
48 return nil, err
49 }
50 opts.Variables[n] = s
51 }
52
53 r := new(R)
54 err := c.Do(ctx,
55 &dagger.Request{
56 Query: query,
57 Variables: opts.Variables,
58 OpName: opts.Operation,
59 },
60 &dagger.Response{Data: r},
61 )
62 if err != nil {
63 return nil, err
64 }
65 return r, nil
66}
67
68func newSecret(ctx context.Context, c *dagger.Client, name, value string) (*core.SecretID, error) {
69 query := `query Secret($name: String!, $value: String!) {

Callers 15

TestVariableMethod · 0.92
TestLabelMethod · 0.92
TestWithMountedFileMethod · 0.92
TestDirectoryMethod · 0.92
TestDirectoryErrorsMethod · 0.92
TestFileMethod · 0.92

Calls 3

newSecretFunction · 0.85
ContextMethod · 0.65
DoMethod · 0.45

Tested by 15

TestVariableMethod · 0.74
TestLabelMethod · 0.74
TestWithMountedFileMethod · 0.74
TestDirectoryMethod · 0.74
TestDirectoryErrorsMethod · 0.74
TestFileMethod · 0.74