ash-project / ash_json_api

The JSON:API extension for the Ash Framework
https://hexdocs.pm/ash_json_api
MIT License
62 stars 42 forks source link

Json Api Index action gives a read/1 not existing or private error #60

Closed tommasop closed 2 years ago

tommasop commented 2 years ago

Describe the bug I have a Category resource I need to filter by report_id

  actions do
    create :create do
      argument :report_id, :uuid do
        allow_nil? false
      end

      change manage_relationship(:report_id, :report, type: :append_and_remove)
    end

    read :read do
      argument :report_id, :uuid do
        allow_nil? false
      end

      filter expr(report_id == ^arg(:report_id))
    end

    read :report_categories do
      argument :report_id, :uuid do
        allow_nil? false
      end

      filter expr(report_id == ^arg(:report_id))
    end
  end

  json_api do
    # Specify a json:api resource type
    type "categories"

    routes do
      base "/categories"
      index :report_categories
    end

  end

If I try to get `http://localhost:4001/categories?report_id=c693adaa-144a-429d-9056-e2acda624fa0

I receive this error:

09:49:49.855 [error] #PID<0.566.0> running MmsBiztalkWeb.Router (connection #PID<0.565.0>, stream id 1) terminated
Server: localhost:4001 (http)
Request: GET /export_categories/categories?report_id=c693adaa-144a-429d-9056-e2acda624fa0
** (exit) an exception was raised:
    ** (UndefinedFunctionError) function MmsBiztalk.Support.Category.read/1 is undefined or private
        (mms_biztalk 0.1.0) MmsBiztalk.Support.Category.read(#Ash.Query<resource: MmsBiztalk.Support.Category, arguments: %{report_id: "c693adaa-144a-429d-9056-e2acda624fa0"}, filter: #Ash.Filter<report_id == "c693adaa-144a-429d-9056-e2acda624fa0">>)
        (ash_json_api 0.30.1) lib/ash_json_api/controllers/helpers.ex:56: anonymous fn/1 in AshJsonApi.Controllers.Helpers.fetch_records/1
        (ash_json_api 0.30.1) lib/ash_json_api/controllers/index.ex:20: AshJsonApi.Controllers.Index.call/2
        (mms_biztalk 0.1.0) lib/plug/router.ex:246: anonymous fn/4 in MmsBiztalkWeb.Plugs.CategoriesApi.dispatch/2
        (telemetry 1.1.0) /home/tommasop/code/work/magic/mms_biztalk/deps/telemetry/src/telemetry.erl:320: :telemetry.span/3
        (mms_biztalk 0.1.0) lib/plug/router.ex:242: MmsBiztalkWeb.Plugs.CategoriesApi.dispatch/2
        (mms_biztalk 0.1.0) lib/mms_biztalk_web/plugs/categories_api.ex:1: MmsBiztalkWeb.Plugs.CategoriesApi.plug_builder_call/2
        (plug 1.14.0) lib/plug.ex:168: Plug.forward/4

Expected behavior I expect the action to return all the categories with report_id = c693adaa-144a-429d-9056-e2acda624fa0

** Runtime

Sorry I've been banned again from Discord and I'm not able to get access back :(

tommasop commented 2 years ago

My bad I set the wrong api interface in router