@@ -62,14 +62,16 @@ export function makeAssertAllowed(build: GraphileBuild.Build) {
6262 connectionFilterAllowEmptyObjectInput,
6363 } = options ;
6464 const assertAllowed = EXPORTABLE (
65- ( connectionFilterAllowEmptyObjectInput , connectionFilterAllowNullInput ) =>
65+ (
66+ connectionFilterAllowEmptyObjectInput ,
67+ connectionFilterAllowNullInput ,
68+ isEmpty
69+ ) =>
6670 function ( value : unknown , mode : "list" | "object" | "scalar" ) {
6771 if (
6872 mode === "object" &&
6973 ! connectionFilterAllowEmptyObjectInput &&
70- typeof value === "object" &&
71- value !== null &&
72- Object . keys ( value ) . length === 0
74+ isEmpty ( value )
7375 ) {
7476 throw Object . assign (
7577 new Error ( "Empty objects are forbidden in filter argument input." ) ,
@@ -83,12 +85,7 @@ export function makeAssertAllowed(build: GraphileBuild.Build) {
8385 if ( arr ) {
8486 const l = arr . length ;
8587 for ( let i = 0 ; i < l ; i ++ ) {
86- const entry = arr [ i ] ;
87- if (
88- typeof entry === "object" &&
89- entry !== null &&
90- Object . keys ( entry ) . length === 0
91- ) {
88+ if ( isEmpty ( arr [ i ] ) ) {
9289 throw Object . assign (
9390 new Error (
9491 "Empty objects are forbidden in filter argument input."
@@ -111,7 +108,15 @@ export function makeAssertAllowed(build: GraphileBuild.Build) {
111108 ) ;
112109 }
113110 } ,
114- [ connectionFilterAllowEmptyObjectInput , connectionFilterAllowNullInput ]
111+ [
112+ connectionFilterAllowEmptyObjectInput ,
113+ connectionFilterAllowNullInput ,
114+ isEmpty ,
115+ ]
115116 ) ;
116117 return assertAllowed ;
117118}
119+
120+ export function isEmpty ( o : unknown ) : o is Record < string , never > {
121+ return typeof o === "object" && o !== null && Object . keys ( o ) . length === 0 ;
122+ }
0 commit comments