begin;

    create table users(
        id uuid primary key,
        email character varying (255),
        phone text
    );

    insert into public.users(id, email, phone)
    values
        ('dd5add8a-7dd2-4495-bc1a-a1dfe95ef23a', 'a@b.com', '987654321'),
        ('12e684cc-b7c2-492e-8554-9ab3e03fa37f', null, null),
        ('748a81bb-5f71-4dc8-88d9-efe9f03a14b8', null, '123456789');

    create or replace view users_with_phone as select
        id,
        email,
        phone
    from public.users
    where phone is not null;

    create table polls(
        id uuid primary key,
        user_id uuid references users(id)
    );

    insert into public.polls(id, user_id)
    values
      ('98813159-4814-42fa-911d-5cc900bd80b8', 'dd5add8a-7dd2-4495-bc1a-a1dfe95ef23a'),
      ('07dc0104-3811-4a5d-8887-4018c8116e5c', '12e684cc-b7c2-492e-8554-9ab3e03fa37f'),
      ('3bec2818-7bea-40ba-81fa-7d0ba061c3de', '748a81bb-5f71-4dc8-88d9-efe9f03a14b8');

    create
    or replace function author (rec polls) returns users_with_phone stable strict language sql security definer
    set
        search_path = public as $$
        select
            *
        from users_with_phone u
        where u.id = $1.user_id;
    $$;

    select jsonb_pretty(
      graphql.resolve($$
      {
          pollsCollection {
            edges {
              node {
                author {
                  id,
                  email,
                  phone
                }
              }
            }
          }
        }
      $$)
    );

rollback;
