Current section

Files

Jump to
dagger lib dagger gen function.ex
Raw

lib/dagger/gen/function.ex

# This file generated by `dagger_codegen`. Please DO NOT EDIT.
defmodule Dagger.Function do
@moduledoc """
Function represents a resolver provided by a Module.
A function always evaluates against a parent object and is given a set of named arguments.
"""
use Dagger.Core.QueryBuilder
@derive Dagger.ID
defstruct [:selection, :client]
@type t() :: %__MODULE__{}
@doc "Arguments accepted by the function, if any."
@spec args(t()) :: {:ok, [Dagger.FunctionArg.t()]} | {:error, term()}
def args(%__MODULE__{} = function) do
selection =
function.selection |> select("args") |> select("id")
with {:ok, items} <- execute(selection, function.client) do
{:ok,
for %{"id" => id} <- items do
%Dagger.FunctionArg{
selection:
query()
|> select("loadFunctionArgFromID")
|> arg("id", id),
client: function.client
}
end}
end
end
@doc "A doc string for the function, if any."
@spec description(t()) :: {:ok, String.t()} | {:error, term()}
def description(%__MODULE__{} = function) do
selection =
function.selection |> select("description")
execute(selection, function.client)
end
@doc "A unique identifier for this Function."
@spec id(t()) :: {:ok, Dagger.FunctionID.t()} | {:error, term()}
def id(%__MODULE__{} = function) do
selection =
function.selection |> select("id")
execute(selection, function.client)
end
@doc "The name of the function."
@spec name(t()) :: {:ok, String.t()} | {:error, term()}
def name(%__MODULE__{} = function) do
selection =
function.selection |> select("name")
execute(selection, function.client)
end
@doc "The type returned by the function."
@spec return_type(t()) :: Dagger.TypeDef.t()
def return_type(%__MODULE__{} = function) do
selection =
function.selection |> select("returnType")
%Dagger.TypeDef{
selection: selection,
client: function.client
}
end
@doc "Returns the function with the provided argument"
@spec with_arg(t(), String.t(), Dagger.TypeDef.t(), [
{:description, String.t() | nil},
{:default_value, Dagger.JSON.t() | nil}
]) :: Dagger.Function.t()
def with_arg(%__MODULE__{} = function, name, type_def, optional_args \\ []) do
selection =
function.selection
|> select("withArg")
|> put_arg("name", name)
|> put_arg("typeDef", Dagger.ID.id!(type_def))
|> maybe_put_arg("description", optional_args[:description])
|> maybe_put_arg("defaultValue", optional_args[:default_value])
%Dagger.Function{
selection: selection,
client: function.client
}
end
@doc "Returns the function with the given doc string."
@spec with_description(t(), String.t()) :: Dagger.Function.t()
def with_description(%__MODULE__{} = function, description) do
selection =
function.selection |> select("withDescription") |> put_arg("description", description)
%Dagger.Function{
selection: selection,
client: function.client
}
end
end