Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ash.Patch.Extend generate garbled code in Resource on Windows #205

Closed
pcharbon70 opened this issue Jan 21, 2025 · 2 comments
Closed

Ash.Patch.Extend generate garbled code in Resource on Windows #205

pcharbon70 opened this issue Jan 21, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@pcharbon70
Copy link

On Windows platform only when using the ash.patch.extend to extend a resource with Graphql the diff does not work and you end up with garbled code in the updated resource.

Original resource:

defmodule AshServer.Accounts.App do
  @moduledoc """
  Ressource representing an application in the eco-system.
  """
  use Ash.Resource,
    domain: AshServer.Accounts,
    data_layer: AshPostgres.DataLayer

  alias AshServer.Accounts.PermissionGroup
  alias AshServer.Accounts.User

  postgres do
    table "apps"
    repo AshServer.Repo
  end

  actions do
    create :create do
      accept [:name, :description, :is_active, :creator_id]
    end

    read :read do
      primary? true
    end

    update :update do
      accept [:description, :is_active, :updater_id]
    end

    destroy :destroy do
    end
  end

  attributes do
    attribute :id, :uuid_v7 do
      description "Identificateur"
      writable? false
      default &Ash.UUIDv7.generate/0
      primary_key? true
      allow_nil? false
    end

    attribute :name, :string, allow_nil?: false, description: "Nom"
    attribute :description, :string, allow_nil?: false, description: "Description"
    attribute :is_active, :boolean, description: "Actif?"

    create_timestamp :created_at, description: "Création"
    update_timestamp :updated_at, description: "Mis-à-jour"
  end

  relationships do
    has_many :permission_groups, PermissionGroup
    belongs_to :creator, User
    belongs_to :updater, User
  end

  identities do
    identity :unique_name, [:name]
  end
end

After running mix ash.patch.extend:

defmodule AshServer.Accounts.App do
  @moduledoc """
  Ressource representing an application in the eco-system.
  """
  use Ash.Resource,
    domain: AshServer.Accounts,
    data_layer: AshPostgres.DataLayer,
    extensions: [AshGraphql.Resource]

  alias AshServer.Accounts.PermissionGroup
  alias AshServer.Accounts.User

  graphql do
    type :app
    endepo(AshServer.Repo)
  end

  postgres do
    table "apps"
    repo AshServer.Repo
    endnd
  end

  actions do
    create :create do
      accept [:name, :description, :is_active, :creator_id]
    end

    read :read do
      primary? true
    end

    update :update do
      accept [:description, :is_active, :updater_id]
    end

    destroy :destroy do
    end

    endpdate_timestamp(:updated_at, description: "Mis-à-jour")
  end

  attributes do
    attribute :id, :uuid_v7 do
      description "Identificateur"
      writable? false
      default &Ash.UUIDv7.generate/0
      primary_key? true
      allow_nil? false
    end

    attribute :name, :string, allow_nil?: false, description: "Nom"
    attribute :description, :string, allow_nil?: false, description: "Description"
    attribute :is_active, :boolean, description: "Actif?"

    create_timestamp :created_at, description: "Création"
    update_timestamp :updated_at, description: "Mis-à-jour"
    endelongs_to(:updater, User)
  end

  relationships do
    has_many :permission_groups, PermissionGroup
    belongs_to :creator, User
    belongs_to :updater, User
    enddentity(:unique_name, [:name])
  end

  identities do
    identity :unique_name, [:name]
    endype(:app)
  end
end

Expected behavior
The extension and graphql section should be inserted into the resource without making it uncompilable.
It seems to have something to do with the end keyword as it gets inserted in different places.

** Runtime

  • Elixir version 1.17.3
  • Erlang OTP 27 [erts-15.2]
  • OS Windows 11
  • Igniter version 0.5.88

Additional context
This seems to be OS specific to Windows as I tested it on Ubuntu and it worked fine.

@pcharbon70 pcharbon70 added the bug Something isn't working label Jan 21, 2025
@zachdaniel
Copy link
Contributor

Can you try the latest versions and let me know if you have this same experience?

@pcharbon70-leco
Copy link

Thanks for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants