-
-
Notifications
You must be signed in to change notification settings - Fork 570
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(pgsettings): Only use settings of type string or number #589
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.
Thanks for raising this PR! 🙏 This is a good start, but I'd like a few tweaks in behaviour before it's ready to merge.
I'm thinking at the moment that this should go into v4 because it's effectively a breaking change; however if it's important to you that it goes into v3 we should discuss the comments I've made and come up with a non-breaking way forward (I'm thinking wherever the throws are we should instead output deprecation notices and then String(...)
as you've done).
Let me know which way you want to go with this 👍
'some.setting.not.defined': null, | ||
'some.setting.zero': null, | ||
'number.setting': '42', | ||
'obj': 'bar', |
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.
These colons should be commas.
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 it would be better to just completely omit the null
values than to set them to null - it should be more efficient and should be equivalent (assuming the values are not set globally, for example).
@@ -163,7 +163,7 @@ async function setupPgClientTransaction ({ | |||
// this prevents an accidentional overwriting | |||
if (typeof pgSettings === 'object') { | |||
for (const key of Object.keys(pgSettings)) { | |||
localSettings.set(key, String(pgSettings[key])) | |||
localSettings.set(key, !!pgSettings[key] ? String(pgSettings[key]) : null) |
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.
This is not a safe way to check if the value should be excluded - they might deliberately be setting it to the empty string ""
or to the number zero 0
and this will instead set null
. A safer way would be pgSettings[key] != null ? String(...) : null
; however I'd rather throw if the values are invalid:
strings and numbers should be passed through, null/undefined should be dropped, and everything else should throw an error.
-- #566 (comment)
So I'd like to see some typeof
's around here. For anyone wondering: I'm deliberately suggesting we should throw on booleans, and on objects that have a toString
value.
@benjie
|
Yup; with
Generally you should add what it is (as you have done) and what it should be - i.e. append "expected string or number" (no need to include
Yes, literally everything that doesn't match
Because in SQL it's not clear if you'd check for it to exist or be |
For example, instead of an undefined pgSetting becoming "undefined" turn it into null so set_config can still accept it
I based this PR off of v4 |
and addressed all of the requested changes, I think. |
I'd still like to see this; but the tests need to pass on CI first 👍 |
Thanks @skvale! |
…e#589) * feat(pgsettings): Convert falsy settings to null instead of strings For example, instead of an undefined pgSetting becoming "undefined" turn it into null so set_config can still accept it * feat(pgsettings): Ignore undefined an null pgSettings and throw for object types * feat(pgsettings): Throw error for boolean values * lint(tests): Add a missing comma
* chore(tsdoc): enable TSDoc linting (#577) * chore: add tests for GRAPHILE_TURBO (#582) * chore(types): export GraphileResolverContext * chore(release): use yarn commands * feat(watch): manual schema reload notification (#583) * chore(git): ignore .env file (#590) * chore(tests): use Jest GraphQL schema serializer (#589) * feat(omit) take "many" on constraints into account (#565) * feat(omit) take "many" on constraints into account Closes #505. * move `@omit many` constraint condition to "many" relations only and simplify the conditions a bit, outdenting `makeField` by one level Co-authored-by: Benjie Gillam <[email protected]> * feat(pg): support non-scalar range values (#591) Co-authored-by: Benjie Gillam <[email protected]> * Fix issues after rebase * More reliable? Co-authored-by: David Baumgold <[email protected]> Co-authored-by: Andreas Bergmaier <[email protected]>
For example, instead of anundefined
pgSetting becoming"undefined"
turn it intonull
soset_config
can still accept itFixes: #566