Repository navigation
implement new conventions for IDable objects - #5881
Conversation
This is an assorted set of sweeping changes that fix the longstanding
bug involved with traversing lists of ID-able objects in the SDK. We've
worked around this issue about 10 times in the past two weeks, and now I
understand why!
In short, we need a reliable way to go from foos: [Foo!]!, to selecting
the Nth Foo, and querying against it.
In Go this looks like the following, which actually panics prior to
this commit:
funs, _ := mod.Functions(ctx)
for _, fun := range funs {
fun.Name(ctx) // BOOM
}
This was panicking because the implementation for returning lists of
objects only dealt with scalars, leaving the rest of the object "hollow"
(nil q or c fields). It could have populated c, but q was impossible:
how do you chain queries from the Nth element in a list? If you had a
list of ID-able objects you could at least query them by ID and chain
from there, but how do you know how to query by ID?
This commit adds a new rule: all ID-able objects implement a top-level
`loadFooFromID(id: FooID!): Foo!` resolver. That means when an SDK sees
a list of [Foo!]! objects, it knows it can just fetch IDs and then
create objects that query from loadFooFromID(id: $id).
This new rule is leveraged by a new `core/schema/` helper for
registering resolvers that follow this pattern, to help cut down on a
ton of boilerplate. (I think more code can be deleted than what's in
this commit, may look after.)
Now that there's a dedicated constructor for this, we can start removing
the optional ID arg from other constructors, which also means that
ID-able objects can now be constructed with required args. I applied
this change to GeneratedCode, Module, and Function, and deprecated the
id args everywhere else.
Along the way, I had to rename CacheID to CacheVolumeID. This has long
been a thorn in every SDK developer's side, since it's the _only ID
type_ that doesn't match its corresponding object type. We're about to
make breaking changes for Services v2 so I figure this is worth doing
now.
Also, bumps graphql-go-tools to a version that doesn't just swallow
schema errors and result in cryptic second-order runtime errors.
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
* One was of all custom scalars (IDs + Platform + JSON) and was ultimately used to detect enums during marshaling. This is now handled using an interface instead that all enum values conform to. * The other was, and had to be, only IDs. This was used for detecting if FooID! types should be converted to object counterparts. Now we just rely on type names always being Type+"ID", which we can do now that they're all consistent. Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
| """ | ||
| Create a new TypeDef with a given kind. | ||
| """ | ||
| typeDef: TypeDef! |
There was a problem hiding this comment.
"given kind"? I suppose you meant to add a "kind" argument?
There was a problem hiding this comment.
Ah woops - I had an intermediate state where it took a required kind argument with the goal of avoiding partial instantiation, but I rolled that back; it's kind of nice to be able to skip it since it's set for you by withListOf and withObject, and it didn't fix partial instantiation anyway since for lists you need the element type, and for objects you need a name/etc.
| {{ if eq ($.Name | FormatName) "Container" }} | ||
| *r = *dag.Container(ContainerOpts{ | ||
| ID: ContainerID(id), | ||
| }) | ||
| {{ else if eq ($.Name | FormatName) "Directory" }} | ||
| *r = *dag.Directory(DirectoryOpts{ | ||
| ID: DirectoryID(id), | ||
| }) | ||
| {{ else if eq ($.Name | FormatName) "Socket" }} | ||
| *r = *dag.Socket(SocketOpts{ | ||
| ID: SocketID(id), | ||
| }) | ||
| {{ else if eq ($.Name | FormatName) "Module" }} | ||
| *r = *dag.Module(ModuleOpts{ | ||
| ID: ModuleID(id), | ||
| }) | ||
| {{ else if eq ($.Name | FormatName) "Function" }} | ||
| *r = *dag.Function(FunctionID(id)) | ||
| {{ else if eq ($.Name | FormatName) "File" }} | ||
| *r = *dag.File(FileID(id)) | ||
| {{ else if eq ($.Name | FormatName) "Secret" }} | ||
| *r = *dag.Secret(SecretID(id)) | ||
| {{ else if eq ($.Name | FormatName) "Cache" }} | ||
| cacheID := CacheID(id) | ||
| *r = CacheVolume{ | ||
| q: dag.q, | ||
| c: dag.c, | ||
| id: &cacheID, | ||
| } | ||
| {{ end }} | ||
| *r = *dag.Load{{ $.Name | FormatName }}FromID({{$.Name | FormatName}}ID(id)) |
| "Loads a file by ID." | ||
| file(id: FileID!): File | ||
| "Loads a file by ID." | ||
| file(id: FileID!): File @deprecated(reason: "Use loadFileFromID instead.") |
There was a problem hiding this comment.
| file(id: FileID!): File @deprecated(reason: "Use loadFileFromID instead.") | |
| file(id: FileID!): File @deprecated(reason: "Use `loadFileFromID` instead.") |
Backticks on field references in deprecation messages get interpreted by the sdks to convert naming convention.
| // one wants to type dagger mod init --sdk=github.com/dagger/dagger-sdk-go. | ||
| var WellKnownSDKRuntimes = map[string]string{ | ||
| "go": "vito/dagger-sdk-go:no-ptrs@sha256:2bb26bae3f30b920a4530b7495127fe4986102b06a99ff170500e83c25739b27", | ||
| "go": "vito/dagger-sdk-go:f239c6f6c3ceaa1f760b589fac43b1d0704e45d3@sha256:915f41b414b12a878c60d96869f8ff8155e6ce122b1849303b995b65a343591f", |
There was a problem hiding this comment.
Tag based on git commit 👍
| @classmethod | ||
| def _from_id_query_field(cls): | ||
| return "loadCacheVolumeFromID" |
There was a problem hiding this comment.
Now this can be removed since the field name is predictable now 🙂
There was a problem hiding this comment.
Oh nice! I started pulling on this thread but ran into unfamiliar areas of code, so I'll just prioritize merging this for now to unblock your other PR
| // TODO: workaround bug in codegen | ||
| objID, err := def.ID(ctx) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to get object id: %w", err) | ||
| } | ||
| def = *dag.TypeDef( | ||
| dagger.TypeDefOpts{ | ||
| ID: objID, | ||
| }, | ||
| ) |
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
* implement new conventions for IDable objects
This is an assorted set of sweeping changes that fix the longstanding
bug involved with traversing lists of ID-able objects in the SDK. We've
worked around this issue about 10 times in the past two weeks, and now I
understand why!
In short, we need a reliable way to go from foos: [Foo!]!, to selecting
the Nth Foo, and querying against it.
In Go this looks like the following, which actually panics prior to
this commit:
funs, _ := mod.Functions(ctx)
for _, fun := range funs {
fun.Name(ctx) // BOOM
}
This was panicking because the implementation for returning lists of
objects only dealt with scalars, leaving the rest of the object "hollow"
(nil q or c fields). It could have populated c, but q was impossible:
how do you chain queries from the Nth element in a list? If you had a
list of ID-able objects you could at least query them by ID and chain
from there, but how do you know how to query by ID?
This commit adds a new rule: all ID-able objects implement a top-level
`loadFooFromID(id: FooID!): Foo!` resolver. That means when an SDK sees
a list of [Foo!]! objects, it knows it can just fetch IDs and then
create objects that query from loadFooFromID(id: $id).
This new rule is leveraged by a new `core/schema/` helper for
registering resolvers that follow this pattern, to help cut down on a
ton of boilerplate. (I think more code can be deleted than what's in
this commit, may look after.)
Now that there's a dedicated constructor for this, we can start removing
the optional ID arg from other constructors, which also means that
ID-able objects can now be constructed with required args. I applied
this change to GeneratedCode, Module, and Function, and deprecated the
id args everywhere else.
Along the way, I had to rename CacheID to CacheVolumeID. This has long
been a thorn in every SDK developer's side, since it's the _only ID
type_ that doesn't match its corresponding object type. We're about to
make breaking changes for Services v2 so I figure this is worth doing
now.
Also, bumps graphql-go-tools to a version that doesn't just swallow
schema errors and result in cryptic second-order runtime errors.
Signed-off-by: Alex Suraci <[email protected]>
* sdk/rust: remove CacheVolumeID special-case, regen
Signed-off-by: Alex Suraci <[email protected]>
* regen node, python
Signed-off-by: Alex Suraci <[email protected]>
* python: remove noqa now that deprecations are back
Signed-off-by: Alex Suraci <[email protected]>
* sdk/go: refactor away high-maintenance type maps
* One was of all custom scalars (IDs + Platform + JSON) and was
ultimately used to detect enums during marshaling. This is now handled
using an interface instead that all enum values conform to.
* The other was, and had to be, only IDs. This was used for detecting if
FooID! types should be converted to object counterparts. Now we just
rely on type names always being Type+"ID", which we can do now that
they're all consistent.
Signed-off-by: Alex Suraci <[email protected]>
* re-bootstrap go sdk
Signed-off-by: Alex Suraci <[email protected]>
* add changie
Signed-off-by: Alex Suraci <[email protected]>
* fix up deprecation syntax + typeDef doc
Signed-off-by: Alex Suraci <[email protected]>
* regen SDKs
Signed-off-by: Alex Suraci <[email protected]>
* add missing doc + regen
Signed-off-by: Alex Suraci <[email protected]>
---------
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Christian Schlatter <[email protected]>
* implement new conventions for IDable objects
This is an assorted set of sweeping changes that fix the longstanding
bug involved with traversing lists of ID-able objects in the SDK. We've
worked around this issue about 10 times in the past two weeks, and now I
understand why!
In short, we need a reliable way to go from foos: [Foo!]!, to selecting
the Nth Foo, and querying against it.
In Go this looks like the following, which actually panics prior to
this commit:
funs, _ := mod.Functions(ctx)
for _, fun := range funs {
fun.Name(ctx) // BOOM
}
This was panicking because the implementation for returning lists of
objects only dealt with scalars, leaving the rest of the object "hollow"
(nil q or c fields). It could have populated c, but q was impossible:
how do you chain queries from the Nth element in a list? If you had a
list of ID-able objects you could at least query them by ID and chain
from there, but how do you know how to query by ID?
This commit adds a new rule: all ID-able objects implement a top-level
`loadFooFromID(id: FooID!): Foo!` resolver. That means when an SDK sees
a list of [Foo!]! objects, it knows it can just fetch IDs and then
create objects that query from loadFooFromID(id: $id).
This new rule is leveraged by a new `core/schema/` helper for
registering resolvers that follow this pattern, to help cut down on a
ton of boilerplate. (I think more code can be deleted than what's in
this commit, may look after.)
Now that there's a dedicated constructor for this, we can start removing
the optional ID arg from other constructors, which also means that
ID-able objects can now be constructed with required args. I applied
this change to GeneratedCode, Module, and Function, and deprecated the
id args everywhere else.
Along the way, I had to rename CacheID to CacheVolumeID. This has long
been a thorn in every SDK developer's side, since it's the _only ID
type_ that doesn't match its corresponding object type. We're about to
make breaking changes for Services v2 so I figure this is worth doing
now.
Also, bumps graphql-go-tools to a version that doesn't just swallow
schema errors and result in cryptic second-order runtime errors.
Signed-off-by: Alex Suraci <[email protected]>
* sdk/rust: remove CacheVolumeID special-case, regen
Signed-off-by: Alex Suraci <[email protected]>
* regen node, python
Signed-off-by: Alex Suraci <[email protected]>
* python: remove noqa now that deprecations are back
Signed-off-by: Alex Suraci <[email protected]>
* sdk/go: refactor away high-maintenance type maps
* One was of all custom scalars (IDs + Platform + JSON) and was
ultimately used to detect enums during marshaling. This is now handled
using an interface instead that all enum values conform to.
* The other was, and had to be, only IDs. This was used for detecting if
FooID! types should be converted to object counterparts. Now we just
rely on type names always being Type+"ID", which we can do now that
they're all consistent.
Signed-off-by: Alex Suraci <[email protected]>
* re-bootstrap go sdk
Signed-off-by: Alex Suraci <[email protected]>
* add changie
Signed-off-by: Alex Suraci <[email protected]>
* fix up deprecation syntax + typeDef doc
Signed-off-by: Alex Suraci <[email protected]>
* regen SDKs
Signed-off-by: Alex Suraci <[email protected]>
* add missing doc + regen
Signed-off-by: Alex Suraci <[email protected]>
---------
Signed-off-by: Alex Suraci <[email protected]>
* implement new conventions for IDable objects
This is an assorted set of sweeping changes that fix the longstanding
bug involved with traversing lists of ID-able objects in the SDK. We've
worked around this issue about 10 times in the past two weeks, and now I
understand why!
In short, we need a reliable way to go from foos: [Foo!]!, to selecting
the Nth Foo, and querying against it.
In Go this looks like the following, which actually panics prior to
this commit:
funs, _ := mod.Functions(ctx)
for _, fun := range funs {
fun.Name(ctx) // BOOM
}
This was panicking because the implementation for returning lists of
objects only dealt with scalars, leaving the rest of the object "hollow"
(nil q or c fields). It could have populated c, but q was impossible:
how do you chain queries from the Nth element in a list? If you had a
list of ID-able objects you could at least query them by ID and chain
from there, but how do you know how to query by ID?
This commit adds a new rule: all ID-able objects implement a top-level
`loadFooFromID(id: FooID!): Foo!` resolver. That means when an SDK sees
a list of [Foo!]! objects, it knows it can just fetch IDs and then
create objects that query from loadFooFromID(id: $id).
This new rule is leveraged by a new `core/schema/` helper for
registering resolvers that follow this pattern, to help cut down on a
ton of boilerplate. (I think more code can be deleted than what's in
this commit, may look after.)
Now that there's a dedicated constructor for this, we can start removing
the optional ID arg from other constructors, which also means that
ID-able objects can now be constructed with required args. I applied
this change to GeneratedCode, Module, and Function, and deprecated the
id args everywhere else.
Along the way, I had to rename CacheID to CacheVolumeID. This has long
been a thorn in every SDK developer's side, since it's the _only ID
type_ that doesn't match its corresponding object type. We're about to
make breaking changes for Services v2 so I figure this is worth doing
now.
Also, bumps graphql-go-tools to a version that doesn't just swallow
schema errors and result in cryptic second-order runtime errors.
Signed-off-by: Alex Suraci <[email protected]>
* sdk/rust: remove CacheVolumeID special-case, regen
Signed-off-by: Alex Suraci <[email protected]>
* regen node, python
Signed-off-by: Alex Suraci <[email protected]>
* python: remove noqa now that deprecations are back
Signed-off-by: Alex Suraci <[email protected]>
* sdk/go: refactor away high-maintenance type maps
* One was of all custom scalars (IDs + Platform + JSON) and was
ultimately used to detect enums during marshaling. This is now handled
using an interface instead that all enum values conform to.
* The other was, and had to be, only IDs. This was used for detecting if
FooID! types should be converted to object counterparts. Now we just
rely on type names always being Type+"ID", which we can do now that
they're all consistent.
Signed-off-by: Alex Suraci <[email protected]>
* re-bootstrap go sdk
Signed-off-by: Alex Suraci <[email protected]>
* add changie
Signed-off-by: Alex Suraci <[email protected]>
* fix up deprecation syntax + typeDef doc
Signed-off-by: Alex Suraci <[email protected]>
* regen SDKs
Signed-off-by: Alex Suraci <[email protected]>
* add missing doc + regen
Signed-off-by: Alex Suraci <[email protected]>
---------
Signed-off-by: Alex Suraci <[email protected]>
* implement new conventions for IDable objects
This is an assorted set of sweeping changes that fix the longstanding
bug involved with traversing lists of ID-able objects in the SDK. We've
worked around this issue about 10 times in the past two weeks, and now I
understand why!
In short, we need a reliable way to go from foos: [Foo!]!, to selecting
the Nth Foo, and querying against it.
In Go this looks like the following, which actually panics prior to
this commit:
funs, _ := mod.Functions(ctx)
for _, fun := range funs {
fun.Name(ctx) // BOOM
}
This was panicking because the implementation for returning lists of
objects only dealt with scalars, leaving the rest of the object "hollow"
(nil q or c fields). It could have populated c, but q was impossible:
how do you chain queries from the Nth element in a list? If you had a
list of ID-able objects you could at least query them by ID and chain
from there, but how do you know how to query by ID?
This commit adds a new rule: all ID-able objects implement a top-level
`loadFooFromID(id: FooID!): Foo!` resolver. That means when an SDK sees
a list of [Foo!]! objects, it knows it can just fetch IDs and then
create objects that query from loadFooFromID(id: $id).
This new rule is leveraged by a new `core/schema/` helper for
registering resolvers that follow this pattern, to help cut down on a
ton of boilerplate. (I think more code can be deleted than what's in
this commit, may look after.)
Now that there's a dedicated constructor for this, we can start removing
the optional ID arg from other constructors, which also means that
ID-able objects can now be constructed with required args. I applied
this change to GeneratedCode, Module, and Function, and deprecated the
id args everywhere else.
Along the way, I had to rename CacheID to CacheVolumeID. This has long
been a thorn in every SDK developer's side, since it's the _only ID
type_ that doesn't match its corresponding object type. We're about to
make breaking changes for Services v2 so I figure this is worth doing
now.
Also, bumps graphql-go-tools to a version that doesn't just swallow
schema errors and result in cryptic second-order runtime errors.
Signed-off-by: Alex Suraci <[email protected]>
* sdk/rust: remove CacheVolumeID special-case, regen
Signed-off-by: Alex Suraci <[email protected]>
* regen node, python
Signed-off-by: Alex Suraci <[email protected]>
* python: remove noqa now that deprecations are back
Signed-off-by: Alex Suraci <[email protected]>
* sdk/go: refactor away high-maintenance type maps
* One was of all custom scalars (IDs + Platform + JSON) and was
ultimately used to detect enums during marshaling. This is now handled
using an interface instead that all enum values conform to.
* The other was, and had to be, only IDs. This was used for detecting if
FooID! types should be converted to object counterparts. Now we just
rely on type names always being Type+"ID", which we can do now that
they're all consistent.
Signed-off-by: Alex Suraci <[email protected]>
* re-bootstrap go sdk
Signed-off-by: Alex Suraci <[email protected]>
* add changie
Signed-off-by: Alex Suraci <[email protected]>
* fix up deprecation syntax + typeDef doc
Signed-off-by: Alex Suraci <[email protected]>
* regen SDKs
Signed-off-by: Alex Suraci <[email protected]>
* add missing doc + regen
Signed-off-by: Alex Suraci <[email protected]>
---------
Signed-off-by: Alex Suraci <[email protected]>
* implement new conventions for IDable objects
This is an assorted set of sweeping changes that fix the longstanding
bug involved with traversing lists of ID-able objects in the SDK. We've
worked around this issue about 10 times in the past two weeks, and now I
understand why!
In short, we need a reliable way to go from foos: [Foo!]!, to selecting
the Nth Foo, and querying against it.
In Go this looks like the following, which actually panics prior to
this commit:
funs, _ := mod.Functions(ctx)
for _, fun := range funs {
fun.Name(ctx) // BOOM
}
This was panicking because the implementation for returning lists of
objects only dealt with scalars, leaving the rest of the object "hollow"
(nil q or c fields). It could have populated c, but q was impossible:
how do you chain queries from the Nth element in a list? If you had a
list of ID-able objects you could at least query them by ID and chain
from there, but how do you know how to query by ID?
This commit adds a new rule: all ID-able objects implement a top-level
`loadFooFromID(id: FooID!): Foo!` resolver. That means when an SDK sees
a list of [Foo!]! objects, it knows it can just fetch IDs and then
create objects that query from loadFooFromID(id: $id).
This new rule is leveraged by a new `core/schema/` helper for
registering resolvers that follow this pattern, to help cut down on a
ton of boilerplate. (I think more code can be deleted than what's in
this commit, may look after.)
Now that there's a dedicated constructor for this, we can start removing
the optional ID arg from other constructors, which also means that
ID-able objects can now be constructed with required args. I applied
this change to GeneratedCode, Module, and Function, and deprecated the
id args everywhere else.
Along the way, I had to rename CacheID to CacheVolumeID. This has long
been a thorn in every SDK developer's side, since it's the _only ID
type_ that doesn't match its corresponding object type. We're about to
make breaking changes for Services v2 so I figure this is worth doing
now.
Also, bumps graphql-go-tools to a version that doesn't just swallow
schema errors and result in cryptic second-order runtime errors.
Signed-off-by: Alex Suraci <[email protected]>
* sdk/rust: remove CacheVolumeID special-case, regen
Signed-off-by: Alex Suraci <[email protected]>
* regen node, python
Signed-off-by: Alex Suraci <[email protected]>
* python: remove noqa now that deprecations are back
Signed-off-by: Alex Suraci <[email protected]>
* sdk/go: refactor away high-maintenance type maps
* One was of all custom scalars (IDs + Platform + JSON) and was
ultimately used to detect enums during marshaling. This is now handled
using an interface instead that all enum values conform to.
* The other was, and had to be, only IDs. This was used for detecting if
FooID! types should be converted to object counterparts. Now we just
rely on type names always being Type+"ID", which we can do now that
they're all consistent.
Signed-off-by: Alex Suraci <[email protected]>
* re-bootstrap go sdk
Signed-off-by: Alex Suraci <[email protected]>
* add changie
Signed-off-by: Alex Suraci <[email protected]>
* fix up deprecation syntax + typeDef doc
Signed-off-by: Alex Suraci <[email protected]>
* regen SDKs
Signed-off-by: Alex Suraci <[email protected]>
* add missing doc + regen
Signed-off-by: Alex Suraci <[email protected]>
---------
Signed-off-by: Alex Suraci <[email protected]>
Follow-up to dagger#5881, this is a refactor to simplify converting an ID scalar to object based on the new convention. Signed-off-by: Helder Correia <[email protected]>
Follow-up to #5881, this is a refactor to simplify converting an ID scalar to object based on the new convention. Signed-off-by: Helder Correia <[email protected]>
This is an assorted set of sweeping changes that fix the longstanding bug involved with traversing lists of ID-able objects in the SDK. We've worked around this issue about 10 times in the past two weeks, and now I understand why!
In short, we need a reliable way to go from
foos: [Foo!]!to selecting the NthFooand querying against it.In Go this looks like the following, which actually panics prior to this PR:
This was panicking because the implementation for returning lists of objects only dealt with scalars, leaving the rest of the object "hollow" (no
qandcfields). It could have populatedc, butqwas impossible: how do you chain queries from the Nth element in a list? If you had a list of ID-able objects you could at least query them by ID and chain from there, but how do you know how to query by ID?This commit adds a new rule: all ID-able objects implement a top-level
loadFooFromID(id: FooID!): Foo!resolver. That means when an SDK sees a list of[Foo!]!objects, it knows it can just fetch IDs and then create objects that query fromloadFooFromID(id: $id).This new rule is leveraged by a new
core/schema/helper for registering resolvers that follow this pattern, to help cut down on a ton of boilerplate:Now that there's a dedicated constructor for objects from their ID we can start removing the optional
id:arg from other constructors, which also means that ID-able objects can now be constructed with required args. I applied this change toGeneratedCode,Module, andFunction, and deprecated theid:args everywhere else.BREAKING: Along the way, I had to rename
CacheIDtoCacheVolumeID. This has long been a thorn in every SDK developer's side, since it's the only ID type that doesn't match its corresponding object type. We're about to make breaking changes for Services v2 so I figure this is worth doing now.Also, bumps
graphql-go-toolsto a version that doesn't just swallow schema errors and result in cryptic second-order runtime errors.Also, removes the various maps from Go/NodeJS codegen that required maintaining a list of ID types and other scalar types.