这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@PedroBern
Copy link
Contributor

Description

Add a new example of how to extend the relay id into the graphql endpoint.

There are some reasons for somebody to need this, for example #5658

But before merging, somebody could improve it, the trigger below works with a serial pk, but for some reason, it's broken for uuid, don't know why.

The example:

CREATE OR REPLACE FUNCTION public.set_relay_id ()
  RETURNS TRIGGER
  LANGUAGE plpgsql
  AS $$
DECLARE
  _new record;
  _json_string text;
BEGIN
  _new := NEW;
  -- assuming the pk column is named "pk" and the table has an "id" text column
  -- same as [1, "public", "table_name", "pk"]
  _json_string = concat(
    '[1, "', TG_TABLE_SCHEMA, '", "', TG_TABLE_NAME, '", ', _new.pk, ']');
  _new."id" = encode(_json_string::bytea, 'base64');
  RETURN _new;
END;
$$;

CREATE TRIGGER "set_authors_relay_id"
BEFORE INSERT ON public.authors
FOR EACH ROW
EXECUTE FUNCTION public.set_relay_id ();

COMMENT ON TRIGGER "set_authors_relay_id" ON public.authors IS
  'trigger to set value of column "id" after insert';

Changelog

  • CHANGELOG.md is updated with user-facing content relevant to this PR. If no changelog is required, then add the no-changelog-required label.

Affected components

  • Docs

Related Issues

Catalog upgrade

Does this PR change Hasura Catalog version?

  • No

Metadata

Does this PR add a new Metadata feature?

  • No

GraphQL

  • No new GraphQL schema is generated

Breaking changes

  • No Breaking changes

@PedroBern PedroBern requested a review from a team as a code owner October 21, 2020 12:35
@hasura-bot
Copy link
Contributor

Beep boop! 🤖

Hey @PedroBern, thanks for your PR!

One of my human friends will review this PR and get back to you as soon as possible.

Stay awesome! 😎

@netlify
Copy link

netlify bot commented Oct 21, 2020

Deploy preview for hasura-docs ready!

Built with commit 661dca8

https://deploy-preview-6054--hasura-docs.netlify.app

@Stefmore02
Copy link
Contributor

Closing as this PR is in .rst and not .mdx docs. If you can port it over to .mdx please feel free to open a new PR.

@Stefmore02 Stefmore02 closed this Jul 13, 2023
@hasura-bot
Copy link
Contributor

Beep boop! 🤖

Hey @PedroBern!

Sorry that your PR wasn’t merged.

Do take a look at any of the other open issues to see if you’d like to take something up! We’re around on Discord if you have any questions 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants