Skip to content

Commit

Permalink
docs: Create multi-language custom types page (#7340)
Browse files Browse the repository at this point in the history
* 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
vikram-dagger and helderco committed May 15, 2024
1 parent 2516b3a commit 42b31b2
Show file tree
Hide file tree
Showing 21 changed files with 142 additions and 7,257 deletions.
74 changes: 74 additions & 0 deletions docs/current_docs/manuals/developer/custom-types.mdx
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
```
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Hello, Foo!
```

:::note
Dagger Modules have only one constructor. Constructors of [custom types](./580472-custom-types.mdx) are not registered; they are constructed by the function that [chains](../chaining.mdx) them.
Dagger Modules have only one constructor. Constructors of [custom types](../custom-types.mdx) are not registered; they are constructed by the function that [chains](../chaining.mdx) them.
:::

:::note
Expand Down
42 changes: 0 additions & 42 deletions docs/current_docs/manuals/developer/go/580472-custom-types.mdx

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 42b31b2

Please sign in to comment.