Is it possible to order by a computed column with graphql ? Assuming to this discussion, it is possible with supabase client API call : https://github.com/orgs/supabase/discussions/7875
But I would like do the same from graphql.
My table with computed column items_count
:
CREATE TABLE IF NOT EXISTS "public"."group" (
"id" SERIAL PRIMARY KEY,
"name" "text" NOT NULL
);
CREATE TABLE IF NOT EXISTS "public"."items" (
"id" SERIAL PRIMARY KEY,
"name" "text" NOT NULL,
"group_id" SERIAL REFERENCES "public"."group"("id")
);
CREATE OR REPLACE FUNCTION public."items_count"("group" public."group")
RETURNS INT
STRICT
VOLATILE
LANGUAGE sql
AS
$$
SELECT COUNT(*)
FROM items
WHERE group_id = "group".id;
$$;
The generated graphql schema returns group
:
type group implements Node {
id: Int!
itemsCollection(...): itemsConnection
items_count: Int
name: String!
nodeId: ID!
}
This query is valid and returns correct result with items_count
field :
query AllGroups($sort: [groupOrderBy!]) {
groupCollection(orderBy: $sort) {
edges {
node {
id
name
items_count
}
}
}
}
But it is not possible to sort by items_count
. Indeed the generated graphql schema returns groupOrderBy
:
input groupOrderBy {
id: OrderByDirection
name: OrderByDirection
}