New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve modules quality by examples #7217
Labels
Comments
marcosnils
changed the title
Improve module quality by examples
Improve modules quality by examples
Apr 29, 2024
In "solution 1", what steps does the user follow, to add an example to a module? |
In "solution 1", can you generate a CLI example too? |
Both solution 1 and 2 steps to create examples has been added here #7217 (comment)
Yes, both solutions would allow it 🙏 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Problem #
In many cases it's not clear for module consumers how to use them once they find them in the Daggerverse. Even though https://daggerverse.dev has detailed docs about the module functions, their arguments and return types, sometimes modules are designed to be consumed in a particular way which is currently hard to express given the current module documentation features.
For example, looking at this module: https://daggerverse.dev/mod/github.com/jcsirot/daggerverse/java@c591e9e0b99def2fc8a67bb090fca5cd06cf6a1d
Daggerverse.dev doesn't show anything about how this module could be used but if you navigate to the module README file here https://github.com/jcsirot/daggerverse/tree/c591e9e0b99def2fc8a67bb090fca5cd06cf6a1d/java#usage, you can find more approachable example(s) on how this module can be utilized.
The purpose of this proposal is to elevate our modules quality by enabling module authors to define examples of their existing modules and surface them in the Daggerverse.
Solution #
Similar to other package managers and indexers like npm, pkg.go.dev, docs.rs, pulumi registry, etc. the goal is to provide Dagger module authors a way to define examples for their modules and later render them in Daggerverse.dev so consumers have a better UX while using them.
The challenge is that we would like Dagger module examples to follow the same UX that other aspects of the Dagger platform have. This translates to these examples ideally being defined through working code and the ability to be consumed in any of the officially supported SDKs.
After brainstorming with Dagger team members @vito @helderco and @jedevc, we came to the conclusion that there seems to be 2 possible way of providing such experience:
dagql.ID
object from Dagger core types and perform GraphQL code generation to multiple SDK's.Pros:
Cons:
example:
We want to write an example for the
java
module mentioned abovenote: the
if
statement above won't be present in the final example snippet for this approach given that's not part of the GraphQL query sent to the engineby manipulating the resulting
dagql.ID
of the returned container, we can then translate the above function call into the following GraphQL expression:Once we have the corresponding GraphQL query, we could use some code generation to translate the query into other SDKs.
#1
and copy them verbatim in the Daggerverse docs without any SDK specific example generationPros:
Cons:
A follow-up idea around this approach to make examples multi-language, is to rely on LLMs for automatic code translation across multiple SDKs. This presents its own challenges by itself, but some preliminary tests are already showing some promising results.
UX proposal #
Some ideas came up internally at Dagger about how we could approach this. The one that's getting the most traction is following a similar pattern how
Go
handles examples in their docs (https://go.dev/blog/examples) by establishing a convention on how to define them to then render them accordingly in the package docs.The proposed UX is as follows:
Given a module
M
, with a typeT
and functionF
, any files under a./examples
folder in the modulesource
directory with the conventions described below will be counted as module examples.Multiple example functions for a module/type/function may be provided by appending a distinct suffix to the name:
note: using
Go
as an example here. This applies for all the other SDK's with their standard code conventionsOnce these examples are defined, they'd become part of a new
core.Example
type in the core GraphQLcore.Module
type here (https://github.com/marcosnils/dagger/blob/9baaa467f14bd4abf5399da1608b9d17d07e8fd7/core/module.go?plain=1#L17) and thecore.Function
type (https://github.com/marcosnils/dagger/blob/9baaa467f14bd4abf5399da1608b9d17d07e8fd7/core/typedef.go?plain=1#L18) which can be later queried.In order to not penalize the module initialization time with example parsing, we're proposing to add a new
WithExamples
flag and to thecore.ModuleSource
type here (https://github.com/marcosnils/dagger/blob/9baaa467f14bd4abf5399da1608b9d17d07e8fd7/core/modulesource.go?plain=1#L48) so we can have better control when to trigger this example parsing logic. The resulting graphql query would be something like:Next steps
We're planning to spend a few cycles on solution
#1
to get a feel about how approachable it is and hopefully come up with a working PoC to share with the community. Any other ideas or suggestions are always welcome.The text was updated successfully, but these errors were encountered: