Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add operation messages via RAISE NOTICE #16

Merged
merged 9 commits into from
Jul 28, 2020
Merged

feat: add operation messages via RAISE NOTICE #16

merged 9 commits into from
Jul 28, 2020

Conversation

benjie
Copy link
Member

@benjie benjie commented Apr 7, 2020

Fixes #12 (cc @demianuco)

PostGraphile will subscribe to NOTICE events from PostgreSQL during mutations, and any notice with error code OPMSG (operation message) will be added to the mutation payload messages field.

Important:

  • This feature only applies to mutations
  • Any PL/pgSQL function may raise these notices
  • Additional information can be added to the OPMSG by passing a JSON value to the detail field
  • RAISE NOTICE may have message length limits; it's your responsibility to colour inside the lines
  • Clients must be configured (via client_min_messages) to receive NOTICE messages; this is PostgreSQL's default configuration.
  • If the server is configured (via log_min_messages) to log NOTICEs then, well, the NOTICEs will be logged; PostgreSQL's default configuration does not log NOTICE.

Example:

raise notice 
  '2 + 2 is %, minus 1 that''s %; quick maths.',
  (2 + 2),
  (2 + 2 - 1)
using
  errcode = 'OPMSG',
  detail = json_build_object(
    'level', 'info',
    'path', array_to_json(ARRAY['noticePath']),
    'anything_else', 'can_go_here'
  )::text;

@benjie
Copy link
Member Author

benjie commented Apr 7, 2020

Rebased on #17 (after merge to master) to make the diff smaller and more focussed.

@mathroc
Copy link

mathroc commented Apr 14, 2020

I don’t understand how notices are filtered, it looks like code different from OPMSG would be processed too, am I missing something ?

@benjie
Copy link
Member Author

benjie commented Apr 15, 2020

👀 I was so tired that day. I wasn't confident merging because I knew I'd overlooked something but couldn't figure out what. Thanks for spotting @mathroc! Added test and fixed.

@benjie benjie changed the base branch from master to main July 28, 2020 11:51
@benjie benjie merged commit bb4db34 into main Jul 28, 2020
@benjie benjie deleted the notices branch July 28, 2020 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow messages to be registered from any SQL function
3 participants