dagger-sdk icon indicating copy to clipboard operation
dagger-sdk copied to clipboard

Like other dagger sdks hide the id() param.

Open kjuulh opened this issue 1 year ago • 0 comments

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: https://github.com/kjuulh/dagger-sdk/blob/2a29a66217fa4d6c530ea1ce670c8836383e7051/crates/dagger-sdk/src/querybuilder.rs#L56

should be moved to this:

https://github.com/kjuulh/dagger-sdk/blob/2a29a66217fa4d6c530ea1ce670c8836383e7051/crates/dagger-sdk/src/querybuilder.rs#L96-L98

kjuulh avatar Mar 07 '23 20:03 kjuulh