-
-
Notifications
You must be signed in to change notification settings - Fork 582
feat(postgraphql): inject custom settings into the database #399
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really, this looks good. Can you provide any use case? I'm just curious..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, just one nit 👍
// this prevents an accidentional overwriting | ||
if (typeof pgSettings === 'object') { | ||
for (const key of Object.keys(pgSettings)) { | ||
localSettings.set(key, pgSettings[key]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please wrap the value with String constructor: localSettings.set(key, String(pgSettings[key]))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will. Any thoughts about objects that can be serialized to a json string and injected in postgres?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the user should handle that themself with JSON.serialize. I just want to ensure that the types are clear so that set_config(text, text, bool)
isn't mistaken for a potential different user-defined function such as set_config(test, json, bool)
etc.
A very simple use case is to inject node process related information in your postgres database like the current process id. My specific use case is to make the configuration of my postgres functions configurable from the node process like the configuration of an url prefix which gets concatinated via a postgres function which gets mapped to a graphql field. This is the first preparation for a second pull request I maybe come up to allow the generation of the settings via a middleware like function. Example:
which can then be accessed via Or another approach I have in mind is to open up the middleware stack of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Merged 🎉 - thanks @mlegenhausen |
Released in 3.1.0 🎉 |
…#399) * (feat) Allow the injection of custom postgres settings * Making sure the value that gets set is a string * Linting errors fixed
This pull request adds the
pgSettings
configuration parameter topostgraphql
middleware function. With this parameter it is possible to set custom config values to the postgres connection. These settings can then be accessed viacurrent_setting('my.custom.setting')
in all stored procedures. This is analog to the usage of thejwt.claims
settings but can be defined at middleware initialisation time.I hope you like it.