lib/dagger/gen/object_type_def.ex

# This file generated by `dagger_codegen`. Please DO NOT EDIT.
defmodule Dagger.ObjectTypeDef do
  @moduledoc "A definition of a custom object defined in a Module."

  use Dagger.Core.QueryBuilder

  @derive Dagger.ID

  defstruct [:selection, :client]

  @type t() :: %__MODULE__{}

  @doc "The function used to construct new instances of this object, if any"
  @spec constructor(t()) :: Dagger.Function.t() | nil
  def constructor(%__MODULE__{} = object_type_def) do
    selection =
      object_type_def.selection |> select("constructor")

    %Dagger.Function{
      selection: selection,
      client: object_type_def.client
    }
  end

  @doc "The doc string for the object, if any."
  @spec description(t()) :: {:ok, String.t()} | {:error, term()}
  def description(%__MODULE__{} = object_type_def) do
    selection =
      object_type_def.selection |> select("description")

    execute(selection, object_type_def.client)
  end

  @doc "Static fields defined on this object, if any."
  @spec fields(t()) :: {:ok, [Dagger.FieldTypeDef.t()]} | {:error, term()}
  def fields(%__MODULE__{} = object_type_def) do
    selection =
      object_type_def.selection |> select("fields") |> select("id")

    with {:ok, items} <- execute(selection, object_type_def.client) do
      {:ok,
       for %{"id" => id} <- items do
         %Dagger.FieldTypeDef{
           selection:
             query()
             |> select("loadFieldTypeDefFromID")
             |> arg("id", id),
           client: object_type_def.client
         }
       end}
    end
  end

  @doc "Functions defined on this object, if any."
  @spec functions(t()) :: {:ok, [Dagger.Function.t()]} | {:error, term()}
  def functions(%__MODULE__{} = object_type_def) do
    selection =
      object_type_def.selection |> select("functions") |> select("id")

    with {:ok, items} <- execute(selection, object_type_def.client) do
      {:ok,
       for %{"id" => id} <- items do
         %Dagger.Function{
           selection:
             query()
             |> select("loadFunctionFromID")
             |> arg("id", id),
           client: object_type_def.client
         }
       end}
    end
  end

  @doc "A unique identifier for this ObjectTypeDef."
  @spec id(t()) :: {:ok, Dagger.ObjectTypeDefID.t()} | {:error, term()}
  def id(%__MODULE__{} = object_type_def) do
    selection =
      object_type_def.selection |> select("id")

    execute(selection, object_type_def.client)
  end

  @doc "The name of the object."
  @spec name(t()) :: {:ok, String.t()} | {:error, term()}
  def name(%__MODULE__{} = object_type_def) do
    selection =
      object_type_def.selection |> select("name")

    execute(selection, object_type_def.client)
  end

  @doc "If this ObjectTypeDef is associated with a Module, the name of the module. Unset otherwise."
  @spec source_module_name(t()) :: {:ok, String.t()} | {:error, term()}
  def source_module_name(%__MODULE__{} = object_type_def) do
    selection =
      object_type_def.selection |> select("sourceModuleName")

    execute(selection, object_type_def.client)
  end
end