graphile / graphile/global-ids

Roadmap: `nodeId` support in custom return types

Open
#1 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
9
Forks
1
PR merge metrics
No merged PRs in 30d

Description

In addition to the roadmap items outlined in the README, we've identified another use case.

In the following example we have a `user_history` table in a `private` schema with custom queries and mutations exposed in the `public` schema. We create a custom type `public.user_history_item` which matches the underlying table definition.

In this scenario it would be nice if we could expose a `nodeId` computed property on the custom type so that we can interact with it more like a default CRUD operation from the client's perspective.

```sql
create table private.user_history (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
user_id text NOT NULL REFERENCES public.users(auid),
data jsonb NOT NULL,
visited_date timestamptz NOT NULL DEFAULT now()
);

create type public.user_history_item as (
id uuid,
user_id text,
data jsonb,
visited_date timestamptz
);

create function public.get_history(
"between" tstzrange default tstzrange(now() - interval '1 DAY', now())
) returns setof public.user_history_item
as $$
select *
from private.user_history
where
"between" @> visited_date AND
user_id = current_setting('user.auid')::text
order by visited_date desc;
$$ language sql stable strict security definer;

create function public.set_history(
data json
) returns public.user_history_item
as $$
insert into private.user_history (user_id, data, visited_date)
values (
current_setting('user.auid')::text,
data,
now()
)
returning *;
$$ language sql volatile strict security definer;
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.