#like for codegen
1 messages ยท Page 1 of 1 (latest)
Oh I didn't mention, yesterday I mostly managed to switch the manual code I made against the API to codegen
The old tests still pass, but now I can use ALL of the API
api := New()
// FIXME: use scratch instead
dir := api.Git("github.com/dagger/dagger").
Branch("cloak").
Tree()
contents, err := dir.
WithNewFile("/hello.txt", "world").
File("/hello.txt").
Contents(ctx)
require.NoError(t, err)
require.Equal(t, "world", contents)
Still a bunch of crap to figure out, but it's getting there
we should get the container API "for free" as soon as we merge your PR
oh sick
I was thinking of using the ContentOpt pattern but that's a bit hard to generate (especially to avoid name clashes)
Also, not sure how good it is for discoverability, as you mentioned
I'll do something simple for now and then we can all chime in
Also will like your opinion since you have a bunch of experience with language parsing on bass -- the next step would be to generalize this a bit and generate bindings for ts/js/python/etc
i'm not sure how much of my bass experience will really transfer, but i'm always interested in this kind of thing ๐
@signal hazel @vestal cipher Pushed an update to #3125 with code generation. Still a bit clunky but it's getting there.
There's an example usage here:
The (test) generated API lives here: https://github.com/dagger/dagger/pull/3125/files#diff-3db3c6a0a540cedf2006a707b20cac3d2f91eb112b067c5e62f407849d1f3b57
@signal hazel I implemented the visitor pattern of the JS tool you mentioned, it should be doable to support other languages and reusing common bits
awesome, I just merged the container PR (pt. 1) now if you've been waiting on that. https://github.com/dagger/dagger/pull/3205 is ready too (adds withMountedDirectory)
now i want to write the tests like this, but that's probably flying too close to the sun
a little bit ๐
I don't know yet if we should bundle the core API in the SDK (one off gen) or if the user should always generate on their end
(including the extensions)
I think if we bundle, we're going to hit type mismatches e.g. go.dagger.io/sdk/go/dagger/core.Container will clash with github.com/aluzzardi/myproject/api.Container (and e.g. the codegen netlify bindings will output a myproject/api.Container rather than core.Container)
Rebased and ... it broke codegen ๐
dogfooding! ๐
Yeah probably start without bundling and see how bad we want it?
yeah. maybe we can bundle it in internal/core for ourselves
tests and stuff
oh btw, for now I added a dumb command:
//go:generate cloak client-gen -o ./api/api.gen.go
it's funny how server generation will go away and client gen come back ... classic codegen switcheroo
Right, almost like the whole SSR vs. client-side rendering boomerang
so I assume dagger generate will eventually be client stuff, for now I left it alone and added a separate command
Yeah sounds good. I was just wondering if we still want the client codegen to run containerized if it's going to end up always being implemented in go. I think probably yes because we need to pull schemas and run code and it would be nice if all that was cacheable. Also have access to DiffOp and other stuff which could come in handy someday.
But none of that matters right now
Yeah, wondering the same ...
right now I like the simplicity of not being containerized. It's hard as it is to debug ๐
this is the error I'm getting after the rebase: expected declaration, found Null. Wish me luck
Oh totally, not something we have to go right back to. But there is also appeal in the codegen being an API like it is today. Could download generated clients from your browser and stuff like that
Yep. Also 3rd party SDKs, etc
@signal hazel ah crap. Remember the graphql-go problem where stuff is returned in random order?
lol...
it's killing me
func (r *Directory) WithNewFile(path string, contents string) *Directory {
sometimes path and contents get swapped
and like, this is bad. Not a build error
hmmm ...
that actually might be worse
if they're sorted, instead of returned as declared
I mean, I can sort it myself
but in this case, contents would be before path
which is not what the API intended
ugh
Oh right
I was just looking to see if the spec said anything about order: https://spec.graphql.org/October2021/#sec-Introspection