defmodule AshHqWeb.Pages.Home do use Surface.LiveComponent alias AshHqWeb.Components.{CalloutText, CodeExample, Search} def render(assigns) do ~F"""
Build powerful and extensible Elixir applications with a next generation tool-chain.
A declarative foundation for modern applications. Use extensions like Ash GraphQL and Ash Json Api to add APIs in minutes, or build your own extensions. Plug-and-play with other excellent tools like Phoenix and Absinthe.
""" end defp changeset_example() do """ post = Example.Post.create!(%{ text: "Declarative programming is fun!" }) Example.Post.react!(post, %{type: :like}) Example.Post |> Ash.Query.filter(likes > 10) |> Ash.Query.sort(likes: :desc) |> Example.read!() """ end defp live_view_example() do """ def mount(_params, _session, socket) do form = AshPhoenix.Form.for_create(Example.Post, :create) {:ok, assign(socket, :form, form}} end def handle_event("validate", %{"form" => input}, socket) do form = AshPhoenix.Form.validate(socket.assigns.form, input) {:ok, assign(socket, :form, form)} end def handle_event("submit", _, socket) do case AshPhoenix.Form.submit(socket.assigns.form) do {:ok, post} -> {:ok, redirect_to_post(socket, post)} {:error, form_with_errors} -> {:noreply, assign(socket, :form, form_with_errors)} end end """ end defp graphql_example() do """ graphql do type :post queries do get :get_post, :read list :feed, :read end mutations do create :create_post, :create update :react_to_post, :react end end """ end defp policies_example() do """ policies do policy action_type(:read) do authorize_if expr(visibility == :everyone) authorize_if relates_to_actor_via([:author, :friends]) end end """ end defp notifier_example() do """ pub_sub do module ExampleEndpoint prefix "post" publish_all :create, ["created"] publish :react, ["reaction", :id] event: "reaction" end """ end defp aggregate_example() do """ aggregates do count :likes, :reactions do filter expr(type == :like) end count :dislikes, :reactions do filter expr(type == :dislike) end end calculations do calculate :like_ratio, :float do expr(likes / likes + dislikes) end end """ end defp post_example() do """ defmodule Example.Post do use AshHq.Resource, data_layer: AshPostgres.DataLayer postgres do table "posts" repo Example.Repo end attributes do attribute :text, :string do allow_nil? false end attribute :visibility, :atom do constraints [ one_of: [:friends, :everyone] ] end end actions do update :react do argument :type, Example.Types.ReactionType do allow_nil? false end change manage_relationship( :type, :reactions, type: :append ) end end relationships do belongs_to :author, Example.User do required? true end has_many :reactions, Example.Reaction end end """ end end