Repository navigation
Labels
kind/bugSomething isn't working
Description
Overview
The Go generated client executes the query when a scalar or list is requested.
dagger/codegen/generator/templates/src/object.go.tmpl
Lines 40 to 44 in fdbf190
| {{- else if or $field.TypeRef.IsScalar $field.TypeRef.IsList }} | |
| var response {{ $field.TypeRef | FormatType }} | |
| q = q.Bind(&response) | |
| return response, q.Execute(ctx, r.c) | |
| {{- end }} |
Problem
When it's a list of objects you need to select the fields.
I looked the API for a problematic case:
type Container {
envVariables: [EnvVariable!]!
}
type EnvVariable {
name: String!
value: String!
}In fact when attempting to call it:
diff --git a/sdk/go/dagger/client_test.go b/sdk/go/dagger/client_test.go
index bd5fbefd..74263ae0 100644
--- a/sdk/go/dagger/client_test.go
+++ b/sdk/go/dagger/client_test.go
@@ -101,3 +101,23 @@ func TestContainer(t *testing.T) {
require.NoError(t, err)
require.Equal(t, "3.16.2\n", contents)
}
+
+func TestList(t *testing.T) {
+ t.Parallel()
+
+ ctx := context.Background()
+
+ c, err := Connect(ctx)
+ require.NoError(t, err)
+ defer c.Close()
+
+ alpine := c.
+ Core().
+ Container().
+ From("alpine:3.16.2")
+
+ envs, err := alpine.EnvVariables(ctx)
+
+ require.NoError(t, err)
+ require.Equal(t, "PATH", envs[0].Name)
+}I get an error:
Error: Received unexpected error:
input:1: Field "envVariables" of type "[EnvVariable!]!" must have a sub selection.
/cc @aluzzardi @dolanor
### Tasks
- [x] https://github.com/dagger/dagger/pull/4683
- [x] https://github.com/dagger/dagger/pull/5375
- [x] https://github.com/dagger/dagger/pull/5523
Activity
aluzzardi commentedon Nov 16, 2022
@sipsma's suggestion in #3860
Yeah, basically a workaround so it stops hurting. Of course with extensions the pain will come back at some point.
Agreed. This might be the cleanest solution, although I'm not sure either about edge cases.
Also creates a disparity between
Object(need to callObject.Field(ctx)-- it's lazy) and[Object!]!(need to callObject.Field-- it's not lazy). We could have both APIs be the same, but the behavior would be different (lazy vs non-lazy) which can be confusing. Implementation would also need to be different (return "pre-fetched" field vs query the API).There's also a half-baked option which is auto-selecting
IDto make the query work, keeping leaf resolvers as usual. The problem though is how to "resume the query" (when calling.Field(ctx)). Either we re-run the full query with the extra field (but there's no way in GraphQL to select the Nth element, so we'd be callingfieldon ALL elements) OR we find a different way to resume the query (top-level selector ... but that's very manual)vito commentedon Jan 19, 2023
A similar issue came up when I was implementing
Stat(#3764). The GraphQL interface is something likeDirectory { stat(path: String): FileInfo! }withFileInfobeing a type sort of likefs.FileInfo. But right now you actually have to select each individual field likesize, err := dir.Stat().Size(ctx).It's not the exact same problem, but maybe our solution here could address both.
19 remaining items
helderco commentedon Jun 30, 2023
Python fix has been merged. Only Node.js remaining.
gerhard commentedon Jun 30, 2023
OK!
We want to get a new release out this week, which leaves us with today.
Would delaying it by a few more hours make a difference for Node.js?
helderco commentedon Jun 30, 2023
That depends on @TomChv, but probably not enough time.
gerhard commentedon Jun 30, 2023
Not a problem, it's OK to leave it for the next release. 👍 @TomChv
gerhard commentedon Jul 26, 2023
Having talked to @TomChv about this, it seems that this one should be part of https://github.com/dagger/dagger/milestone/18. WDYT @helderco?
FWIW:
helderco commentedon Jul 26, 2023
As early as @TomChv can do it. 👍
feat: handle list of object
Node.js: Fix returning lists of objects (#5523)