@@ -288,6 +288,106 @@ describe("validateFixtureInput", () => {
288288 expect ( result . errors ) . toHaveLength ( 0 ) ;
289289 } ) ;
290290
291+ it ( "handles empty objects in union when inline fragment doesn't match" , ( ) => {
292+ const queryAST = parse ( `
293+ query {
294+ data {
295+ searchResults {
296+ ... on Item {
297+ id
298+ count
299+ }
300+ }
301+ }
302+ }
303+ ` ) ;
304+
305+ const fixtureInput = {
306+ data : {
307+ searchResults : [
308+ {
309+ id : "gid://test/Item/1" ,
310+ count : 5
311+ } ,
312+ { } // Empty object - represents Metadata that didn't match the Item fragment
313+ ]
314+ }
315+ } ;
316+
317+ const result = validateFixtureInput ( queryAST , schema , fixtureInput ) ;
318+
319+ // Empty object {} is valid - GraphQL returns this for union members that don't match any fragments
320+ expect ( result . errors ) . toHaveLength ( 0 ) ;
321+ } ) ;
322+
323+ it ( "handles empty objects in interface fragment inside union" , ( ) => {
324+ const queryAST = parse ( `
325+ query {
326+ data {
327+ products {
328+ ... on Purchasable {
329+ price
330+ currency
331+ }
332+ }
333+ }
334+ }
335+ ` ) ;
336+
337+ const fixtureInput = {
338+ data : {
339+ products : [
340+ {
341+ price : 1000 ,
342+ currency : "USD"
343+ } ,
344+ { } // Empty object - GiftCard that doesn't implement Purchasable
345+ ]
346+ }
347+ } ;
348+
349+ const result = validateFixtureInput ( queryAST , schema , fixtureInput ) ;
350+
351+ // Empty object {} is valid - represents a union member that doesn't implement the interface
352+ expect ( result . errors ) . toHaveLength ( 0 ) ;
353+ } ) ;
354+
355+ it ( "handles objects with only __typename when inline fragment doesn't match" , ( ) => {
356+ const queryAST = parse ( `
357+ query {
358+ data {
359+ searchResults {
360+ __typename
361+ ... on Item {
362+ id
363+ count
364+ }
365+ }
366+ }
367+ }
368+ ` ) ;
369+
370+ const fixtureInput = {
371+ data : {
372+ searchResults : [
373+ {
374+ __typename : "Item" ,
375+ id : "gid://test/Item/1" ,
376+ count : 5
377+ } ,
378+ {
379+ __typename : "Metadata" // Only typename, no other fields
380+ }
381+ ]
382+ }
383+ } ;
384+
385+ const result = validateFixtureInput ( queryAST , schema , fixtureInput ) ;
386+
387+ // Object with only __typename is valid - Metadata doesn't match the Item fragment
388+ expect ( result . errors ) . toHaveLength ( 0 ) ;
389+ } ) ;
390+
291391 it ( "handles nested inline fragments" , ( ) => {
292392 const queryAST = parse ( `
293393 query {
@@ -1053,6 +1153,38 @@ describe("validateFixtureInput", () => {
10531153 expect ( result . errors [ 0 ] ) . toBe ( 'Cannot validate nonExistentField: missing type information' ) ;
10541154 } ) ;
10551155
1156+ it ( "detects empty objects in non-union context" , ( ) => {
1157+ const queryAST = parse ( `
1158+ query {
1159+ data {
1160+ items {
1161+ id
1162+ count
1163+ }
1164+ }
1165+ }
1166+ ` ) ;
1167+
1168+ const fixtureInput = {
1169+ data : {
1170+ items : [
1171+ {
1172+ id : "gid://test/Item/1" ,
1173+ count : 5
1174+ } ,
1175+ { } // Empty object in non-union context - should error
1176+ ]
1177+ }
1178+ } ;
1179+
1180+ const result = validateFixtureInput ( queryAST , schema , fixtureInput ) ;
1181+
1182+ // Empty object {} is invalid in non-union context - missing required fields
1183+ expect ( result . errors ) . toHaveLength ( 2 ) ;
1184+ expect ( result . errors [ 0 ] ) . toBe ( "Missing expected fixture data for id" ) ;
1185+ expect ( result . errors [ 1 ] ) . toBe ( "Missing expected fixture data for count" ) ;
1186+ } ) ;
1187+
10561188 it ( "detects missing fields when __typename is not selected in union with inline fragments" , ( ) => {
10571189 const queryAST = parse ( `
10581190 query {
0 commit comments