srikanthkyatham

srikanthkyatham

Hi

I hope I am rephrase my usecase. I have trimmed down for clarity sake. Let’s say that, I have a

defmodule ResourceA do
  ...
  attributes do
    attribute :date
  end
end

ResourceB

defmodule ResourceB do
  ...
  attributes do
    attribute :methods, one_of: [:phone, :online]
  end
end

ResourceC - whose job is get values from ResourceA and ResourceB and return it.

defmodule ResourceC do
  ...
  code_interface do
    define :overlap, args:[...]
  end
  actions do
    action :overlaps, .. do
      argument :start_date, :string, allow_nil?: false
      argument :method, :atom, allow_nil?: false
      run fn input, context -> 
          start_date = inputs.arguments.start_date
          method = inputs.arguments.method
          # gets overlaps from ResourceA and ResourceB
          {:ok, result}
      end
    end
  end
end

Now in the Doamin

defmodule Domain do
use  Ash.Domain, extensions:[AshJsonApi.Domain]

resources do
 ...
end

json_api do
  routes do
   base_route "/overlaps", ResourceC do 
     route :get, "/overlaps", :overlaps
   end
  end
end
end

I am able to make the call. I can’t pass query params to the api call. I tried to debug but in vain. I am getting 400 error response. Any help is appreciated.

Thanks.

Showing Posts 1 to 7

zachdaniel

zachdaniel

Creator of Ash

In the code that I can see here, the action does not have start_date or method arguments. Have you added those arguments to the generic action?

zachdaniel

zachdaniel

Creator of Ash

Also, when sharing errors etc. please share as much context, like what the response body was for the 400 error and if there are any logs indicating additional detail etc. Just 400 status could be many many things :slight_smile:

srikanthkyatham

srikanthkyatham OP

Hi

My bad. Yes the start_date and method are arguments for the action.
here is the response.

15:52:27.017 [error] required: Required | is required


  1) test GET /get_slots (ResourceCTest)
     test/xxxx/api/reserve/resources/resourcec_test.exs:27
     Expected to get status 200 but got 400.

     Response body: %{
       "errors" => [
         %{
           "code" => "required",
           "detail" => "is required",
           "id" => "8745f55a-8645-4d96-a35d-2ea152158dfe",
           "meta" => %{},
           "status" => "400",
           "title" => "Required"
         }
       ],
       "jsonapi" => %{"version" => "1.0"}
     }

 code: ApiTestHelper.get_test(new_path, user, org_id, [])
     stacktrace:
       (ash_json_api 1.4.16) lib/ash_json_api/test/test.ex:68: AshJsonApi.Test.get/3
       (xxx 2.0.0) test/support/api_test_helper.ex:12: ApiTestHelper.get_test/4
       test/xxx/api/reserve/resources/resourcec.exs:81: (test)

I have noticed that if I don’t pass the arguments as query parameters. I get the error saying that I am missing the arguments. If I pass the arguments they are not ending up in the Ash.run_action() call being made from the GenericActionRoute. I am not sure what I was missing.

zachdaniel

zachdaniel

Creator of Ash

Hmm…it sounds like a bug? So input.arguments is an empty map?

srikanthkyatham

srikanthkyatham OP

Yes it is empty. I have noticed query_params is being populated in AshJsonApi.Request.parse_query_params, but it is relying on request.route. Not from request.query_params. I did not understand why it was done like that. I didnot dig deeper after that.

zachdaniel

zachdaniel

Creator of Ash

Oh, right, did you set this? AshJsonApi.Resource — ash_json_api v1.7.0

i.e query_params: [:start_date, :method]. I’m trying to remember why we require that to be set :thinking:… I think it is for post and other methods that could include a body and so require being told what is where. In the future we could probably assume that for get requests all of the inputs are query params.

srikanthkyatham

srikanthkyatham OP

Oh I missed that. I got it working. Thanks stupid me. I should have gone through the options first :disappointed:

— All posts loaded —

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 92995 915
New
caslu
I want to open this thread for you all to discuss and help those who really like Ash but are still hesitant to use it in a real project. ...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
GES233
I’m posting this in response to Jose’s recent tweet (Cr. link) : People are sleeping on Elixir for a coding harness: Hot-code swappi...
New
marciol
It would be helpful to have a list of companies worldwide that hire engineers without prior experience in Elixir. Often, it can be quite ...
New
durvia
Anyone running long-lived stateful processes on BEAM? We’re building an AI agent runtime and would love to compare notes. We’re a small ...
New
AstonJ
This might be a bit disturbing for some but it’s happening - computers running on living human neurons. They’ve made them smart enough t...
New

Other Trending Topics Top

marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews