AshGraphQL or query does not parse to correct sql

query: SELECT d0."id", d0."user_id" FROM "doctors" AS d0 LEFT OUTER JOIN "public"."users" AS u1 ON d0."user_id" = u1."id" WHERE (ash_elixir_or(u1."id"::uuid, ARRAY[$1,$2]::uuid)) AND (d0."entity_id"::uuid = $3::uuid::uuid) ORDER BY d0."id" LIMIT $4
query: SELECT d0."id", d0."user_id" FROM "doctors" AS d0 LEFT OUTER JOIN "public"."users" AS u1 ON d0."user_id" = u1."id" WHERE (ash_elixir_or(u1."id"::uuid, ARRAY[$1,$2]::uuid)) AND (d0."entity_id"::uuid = $3::uuid::uuid) ORDER BY d0."id" LIMIT $4
this log is from a query
query Doctors($query: String!) {
doctors(filter: { user: { or: [{ firstName: { like: $query } }, { lastName: { like: $query }}] }}) {
results {
user {
firstName
lastName
phone
picture {
id
url
}
}
}
}
}
query Doctors($query: String!) {
doctors(filter: { user: { or: [{ firstName: { like: $query } }, { lastName: { like: $query }}] }}) {
results {
user {
firstName
lastName
phone
picture {
id
url
}
}
}
}
}
* ** (Postgrex.Error) ERROR 42846 (cannot_coerce) cannot cast type text[] to uuid
* ** (Postgrex.Error) ERROR 42846 (cannot_coerce) cannot cast type text[] to uuid
4 Replies
barnabasj
barnabasj4mo ago
can you show the resource definition? can't really see how that graphql query would generate that sql
Vahagn
VahagnOP4mo ago
defmodule Aldente.Management.Doctor do
use Ash.Resource,
domain: Aldente.Management,
data_layer: AshPostgres.DataLayer,
extensions: [
AshGraphql.Resource
]

alias Aldente.{Servicing, Management, Accounts}

graphql do
type :doctor
end

postgres do
table "doctors"
repo Aldente.Repo
end

actions do
defaults [:read]

read :search do
argument :query, :string, allow_nil?: true
filter expr(ilike(user.first_name, ^arg(:query)) or ilike(user.last_name, ^arg(:query)))
end

create :create do
primary? true
accept [:user_id]
end
end

multitenancy do
strategy :attribute
attribute :entity_id
end

attributes do
uuid_primary_key :id
end

relationships do
belongs_to :user, Accounts.User, public?: true, allow_nil?: false
has_many :visits, Servicing.Visit, public?: true
belongs_to :entity, Management.Entity, allow_nil?: false, public?: true
end
end
defmodule Aldente.Management.Doctor do
use Ash.Resource,
domain: Aldente.Management,
data_layer: AshPostgres.DataLayer,
extensions: [
AshGraphql.Resource
]

alias Aldente.{Servicing, Management, Accounts}

graphql do
type :doctor
end

postgres do
table "doctors"
repo Aldente.Repo
end

actions do
defaults [:read]

read :search do
argument :query, :string, allow_nil?: true
filter expr(ilike(user.first_name, ^arg(:query)) or ilike(user.last_name, ^arg(:query)))
end

create :create do
primary? true
accept [:user_id]
end
end

multitenancy do
strategy :attribute
attribute :entity_id
end

attributes do
uuid_primary_key :id
end

relationships do
belongs_to :user, Accounts.User, public?: true, allow_nil?: false
has_many :visits, Servicing.Visit, public?: true
belongs_to :entity, Management.Entity, allow_nil?: false, public?: true
end
end
I have just added the :search read action, before that we used graphql's filter but this worked
ZachDaniel
ZachDaniel4mo ago
ash_elixir_or(u1."id"::uuid, ARRAY[$1,$2]::uuid)) The question is where is this coming from? That doesn't seem to be related to anything from the graphql query
Vahagn
VahagnOP4mo ago
I have created another action called search and I do the filter in the backend now. Issue was fixed

Did you find this page helpful?