File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import { GraphQLJSONObject } from 'graphql-scalars';
9
9
import { isEqual } from 'lodash' ;
10
10
import { JsonObject } from 'type-fest' ;
11
11
import { SecuredProperty } from '~/common/secured-property' ;
12
+ import { InputException } from './exceptions/input.exception' ;
12
13
import { OptionalField , OptionalFieldOptions } from './optional-field' ;
13
14
14
15
function hashId ( name : string ) {
@@ -81,9 +82,26 @@ export const RichTextField = (options?: OptionalFieldOptions) =>
81
82
OptionalField ( ( ) => RichTextScalar , {
82
83
optional : false ,
83
84
...options ,
84
- transform : RichTextDocument . fromMaybe ,
85
+ transform : ( value ) => {
86
+ const doc = RichTextDocument . fromMaybe ( value ) ;
87
+ if ( doc ) {
88
+ return doc ;
89
+ }
90
+ if ( options ?. nullable ) {
91
+ return null ;
92
+ }
93
+ if ( options ?. optional ) {
94
+ return undefined ;
95
+ }
96
+ // Should never _really_ get here.
97
+ // UI should understand & send null instead of an empty document.
98
+ // Would prefer this to be done with validators.
99
+ // But I believe this needs to `null`s to be validated.
100
+ // skipMissingProperties -> skipUndefinedProperties
101
+ throw new InputException ( 'RichText must be given' ) ;
102
+ } ,
85
103
} ) ,
86
- IsObject ( ) , // TODO validate empty blocks becomes null becomes validation error
104
+ IsObject ( ) ,
87
105
) ;
88
106
89
107
/** @internal */
You can’t perform that action at this time.
0 commit comments