-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Adds {field}.hooks.validate.[create|update|delete]
hooks
#9057
Conversation
// | { | ||
// create?: ResolveInputFieldHook<ListTypeInfo, 'create', FieldKey> | ||
// update?: ResolveInputFieldHook<ListTypeInfo, 'update', FieldKey> | ||
// } |
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.
We cannot extend the type without it being a breaking change
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 26d3772:
|
32d187a
to
6bf7d86
Compare
6bf7d86
to
4bd0398
Compare
if ((config as any).isIndexed === 'unique') { | ||
throw Error("isIndexed: 'unique' is not a supported option for field type checkbox") | ||
throw TypeError("isIndexed: 'unique' is not a supported option for field type checkbox") |
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 a type error, and I think we should remove this in the future
I think the distinctions between our nulls is poorly defined. We have too many nulls.
Arguably we can unify some parts of this, or restructure it for progressive enhancement with less "conflicting" configuration. Leaves some questions around |
e0a6096
to
fad12d5
Compare
fad12d5
to
8329260
Compare
@@ -24,7 +27,7 @@ export type TextFieldConfig<ListTypeInfo extends BaseListTypeInfo> = | |||
match?: { regex: RegExp, explanation?: string } | |||
length?: { min?: number, max?: number } | |||
} | |||
defaultValue?: string | |||
defaultValue?: string | 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.
Unlike other fields, the ambiguity of ?:
representing ''
or null
is why this needs to exist.
We should allow null
as a defaultValue
typically, and maybe check it at build time too.
Similar to #9056
This pull request needed to adopt a slightly different approach, since we can't reasonably change the types of field hooks when field types are part of our public API, and they are not statically determined by nature as the field types themselves return functions, not an object like
list
.This is only a slight inconvenience though, since we can throw a runtime error to prevent incompatibilities at the point of creating the GraphQL resolvers (
parseFieldHooks
). I do want to flatten this in the future, but, for optimistic usecases you could start using.validation.*
field hooks now. This won't be compatible with many of the native field types, but that compatibility can come later.Additionally, as part of this pull request (and part of the
validateInput
hooks), thetext
now accepts a default value type ofnull
. This was mentioned as a pain point in #7158 (reply in thread), but has remained unresolved for some time.If
db.isNullable: false
, and you passdefaultValue: null
, you will end up with a Prisma error if your text input is undefined (this behavior is typical of other fields). Ifdb.isNullable: true
, thendefaultValue: null
will be exactly that.