As a possible way to measure the readability of the documentation I wanted to see what ChatGPT could do with the documentation and several attempts at prompt engineering.
I put this prompt into ChatGPT:
"Your role is a developer.
The result required is to write an Ash Resource using the Ash DSL, Ash framework and elixir supporting code where required.
The Ash DSL is described at the following links:
DSL: Ash.Resource — ash v2.17.17
DSL: Ash.Api — ash v2.17.17
Get Started With Postgres — ash_postgres v1.3.65
DSL: AshPostgres.DataLayer — ash_postgres v1.3.65
Getting Started With Graphql — ash_graphql v0.26.8
DSL: AshGraphql.Resource — ash_graphql v0.26.8
The goal is to make a Customer resource as follows:
- include an attributes block that defines typical customer schema fields and validation constraints.
- use the postgres datalayer
- define an actions block with a set of meaningful action names for managing the resource.
- include an api block that uses the defined actions
- has an Ash Api interface for the resource that uses the actions.
- include an Ash graphql configuration block.
Output must describe the steps required to produce a valid elixir application using the Ash framework and Ash DSL. The output must include all supporting elixir configuration, code and mix tasks including ash database migration generators and ecto database migrations required to run the application."
From here down is what ChatGPT 3.5 produced, (it is not correct):
To create a Customer resource using the Ash framework and DSL in an Elixir application, we’ll need to follow a series of steps. I’ll outline the steps and provide code examples for each part of the process.
Please note that this is a high-level overview, and you may need to adapt it to your specific project structure and requirements.
Step 1: Set Up Your Elixir Project
Assuming you have Elixir and Mix installed, you can create a new Elixir project with the following command:
mix new my_customer_app
Change into the project directory:
cd my_customer_app
Step 2: Add Dependencies
In your mix.exs
file, add the following dependencies:
defp deps do
[
{:ash, "~> 0.3"},
{:ash_postgres, "~> 0.3"},
{:ash_graphql, "~> 0.3"},
{:ecto, "~> 3.5"},
{:postgrex, "~> 0.15"},
# Add other dependencies as needed
]
end
Then, run mix deps.get
to fetch the dependencies.
Step 3: Define the Customer Resource
Create a new module for the Customer resource using Ash DSL. You can do this by creating a file customer_resource.ex
in the lib/my_customer_app/resources
directory (you may need to create the resources
directory if it doesn’t exist):
defmodule MyApp.CustomerResource do
use Ash.Resource,
name: :customer,
data_layer: Ash.Postgres.DataLayer
attributes do
field :name, :string
field :email, :string
# Add other fields and validation constraints as needed
end
actions do
create
read
update
delete
end
api do
actions [:create, :read, :update, :delete]
end
graphql do
type :customer do
fields [:id, :name, :email]
end
end
end
Step 4: Create Ecto Migration for Customer
Generate an Ecto migration to create the Customer table in your database:
mix ecto.gen.migration create_customer_table
Open the generated migration file (in the priv/repo/migrations
directory) and define the schema for the Customer table. For example:
defmodule MyCustomerApp.Repo.Migrations.CreateCustomerTable do
use Ecto.Migration
def change do
create table(:customers) do
add :name, :string
add :email, :string
timestamps()
end
end
end
Then, run the migration:
mix ecto.migrate
Step 5: Configure Ash
In your config/config.exs
file, configure Ash with your database connection and resource:
config :my_customer_app, MyCustomerApp.Repo,
adapter: Ecto.Adapters.Postgres,
database: "my_customer_app_dev",
username: "postgres",
password: "password",
hostname: "localhost"
config :my_customer_app, Ash,
data_layers: [MyCustomerApp.Repo],
resources: [MyApp.CustomerResource]
Step 6: Generate GraphQL Schema
Create a module to define your GraphQL schema in lib/my_customer_app_web/schema.ex
:
defmodule MyCustomerAppWeb.Schema do
use Ash.GraphQL.Schema
query do
field :customer, type: :customer
# Add other queries as needed
end
mutation do
field :createCustomer, type: :customer
field :updateCustomer, type: :customer
field :deleteCustomer, type: :customer
# Add other mutations as needed
end
end
Step 7: Mount the GraphQL Endpoint
In your Phoenix router (lib/my_customer_app_web/router.ex
), mount the GraphQL endpoint:
forward "/graphql", Absinthe.Plug,
schema: MyCustomerAppWeb.Schema,
context: %{}
Step 8: Run the Application
Now you can start your Elixir application:
mix phx.server
Your Ash-based Customer resource is now integrated into your Elixir application. You can access the GraphQL endpoint to interact with the Customer resource.
Please note that this is a simplified example, and in a real-world application, you would likely need to add more features like authentication, authorization, and error handling based on your specific requirements. Additionally, you should configure your production and test environments accordingly.