-
Notifications
You must be signed in to change notification settings - Fork 573
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: Create multi-language custom types page (#7340)
* docs: Create multi-language custom types page Signed-off-by: Vikram Vaswani <vikram@dagger.io> * Deleted files Signed-off-by: Vikram Vaswani <vikram@dagger.io> * Fix link Signed-off-by: Vikram Vaswani <vikram@dagger.io> * Update netlify.toml Signed-off-by: Vikram Vaswani <vikram@dagger.io> * Normalize snippets to be more similar Signed-off-by: Helder Correia <174525+helderco@users.noreply.github.com> * Revert snippet file structure Signed-off-by: Vikram Vaswani <vikram@dagger.io> * Fix sidebar Signed-off-by: Vikram Vaswani <vikram@dagger.io> --------- Signed-off-by: Vikram Vaswani <vikram@dagger.io> Signed-off-by: Helder Correia <174525+helderco@users.noreply.github.com> Co-authored-by: Helder Correia <174525+helderco@users.noreply.github.com>
- Loading branch information
1 parent
2516b3a
commit 42b31b2
Showing
21 changed files
with
142 additions
and
7,257 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
--- | ||
slug: /manuals/developer/custom-types | ||
displayed_sidebar: "current" | ||
toc_max_heading_level: 2 | ||
title: "Custom Types" | ||
--- | ||
import Tabs from '@theme/Tabs'; | ||
import TabItem from '@theme/TabItem'; | ||
|
||
# Custom Types | ||
|
||
A Dagger module can have multiple object types defined. It's important to understand that they are only accessible through [chaining](./chaining.mdx), starting from a function in the main object. | ||
|
||
<Tabs groupId="language"> | ||
<TabItem value="Go"> | ||
|
||
Here is an example of a `github` Dagger module, with a function named `DaggerOrganization` | ||
that returns a custom `Organization` type, itself containing a collection of | ||
`Account` types: | ||
|
||
```go file=./snippets/custom-types/go/main.go | ||
``` | ||
|
||
</TabItem> | ||
<TabItem value="Python"> | ||
|
||
Here is an example of a `github` Dagger module, with a function named `dagger_organization` | ||
that returns a custom `Organization` type, itself containing a collection of | ||
`Account` types: | ||
|
||
```python file=./snippets/custom-types/python/main.py | ||
``` | ||
|
||
The [`dagger.field`](https://dagger-io.readthedocs.io/en/latest/module.html#dagger.field) descriptors expose getter functions without arguments, for their [attributes](./python/944887-attribute-functions.mdx). | ||
|
||
</TabItem> | ||
<TabItem value="TypeScript"> | ||
|
||
Here is an example of a `github` Dagger module, with a function named `daggerOrganization` | ||
that returns a custom `Organization` type, itself containing a collection of | ||
`Account` types: | ||
|
||
```typescript file=./snippets/custom-types/typescript/index.ts | ||
``` | ||
|
||
TypeScript has multiple ways to support complex data types. However, the Dagger TypeScript SDK only supports it through fields (decorated with `@field()`) inside classes because `type` and `interface` keywords do not allows decorators. | ||
</TabItem> | ||
</Tabs> | ||
|
||
|
||
:::note | ||
When the Dagger Engine extends the Dagger API schema with these types, it prefixes | ||
their names with the name of the main object: | ||
- Github | ||
- GithubAccount | ||
- GithubOrganization | ||
|
||
This is to prevent possible naming conflicts when loading multiple modules, | ||
which is reflected in code generation (for example, when using this module in | ||
another one as a dependency). | ||
::: | ||
|
||
Here's an example of calling a Dagger Function from this module to get all member URLs: | ||
|
||
```shell | ||
dagger call dagger-organization members url | ||
``` | ||
|
||
The result will be: | ||
|
||
``` | ||
https://github.com/jane | ||
https://github.com/john | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 0 additions & 42 deletions
42
docs/current_docs/manuals/developer/go/580472-custom-types.mdx
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
docs/current_docs/manuals/developer/go/snippets/custom-types/.gitattributes
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
docs/current_docs/manuals/developer/go/snippets/custom-types/dagger.json
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.