Skip to content
This repository was archived by the owner on Jun 29, 2023. It is now read-only.

Like other dagger sdks hide the id() param. #26

Open
kjuulh opened this issue Mar 7, 2023 · 0 comments
Open

Like other dagger sdks hide the id() param. #26

kjuulh opened this issue Mar 7, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@kjuulh
Copy link
Owner

kjuulh commented Mar 7, 2023

The idea behind this is to support what the other sdks do with id().

I.e.

directory := client.Host().Directory(...)

client.From().Container().WithDirectory("/", directory)

vs

let directory = client.host().directory(...)

client.from().container().with_directory("/", directory.id().await?)

This is quite a bit more verbose, and not as efficient.

All the sdks does this differently, for dynamic languages a directory is transmuted into a directoryId on read time when a final execution is called .exit_code etc. Or in golang, where an interface is implemented to tell the serializer that it contains an ID, and that it should be called, when an arg is tried to be serialized. Such that a directory (struct) as an arg is serialized as id (string).

The benefit of this process is that the intermediary steps aren't executed eagerly. Right now .file() or .directory() are executed when passed to another function, instead of when .exit_code() or equivalent is called.

There are a few blockers for fixing this:

  • Serialization should be moved to execution, this means somehow storing the raw arg, this can be tricky as Rust is not very happy about dynamic types, in go the raw pointer (interface{}) is stored, this is mostly not an option in rust, it can be done, and is potentially our only option. Another option is storing a closure, this preserves input information, but again, rust really, really is janky when storing special expressions like lambdas.
  • Non-standard serialization: Enums are handled differently in graphql, than json, (they are explicit values TYPE instead of "type", i.e. graphql wants non string wrapped types, while json always wants strings wrapped. It isn't possible override serdes implementation here, so instead I've opted to just remove the quotes from the string manually before passing them to the requester. Again, this may be solved using a closure, or embedding extra information in the arg, or implementing an entirely custom serializer, like what is done in go.

This will probably be fixed in a single change. I am probably gonna do some experiments to see what the easiest solution will be.

The specifics are this:

let val = serde_json::to_string(&value).unwrap();

should be moved to this:

let mut fields = vec!["query".to_string()];
for sel in self.path() {

@kjuulh kjuulh added the enhancement New feature or request label Mar 10, 2023
@kjuulh kjuulh self-assigned this Mar 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant