@@ -1621,4 +1621,98 @@ describe("operation builders", () => {
16211621 ` ) ;
16221622 } ) ;
16231623 } ) ;
1624+
1625+ describe ( "selection auto-expansion" , ( ) => {
1626+ const defaultSelectionWithSpecialFields = {
1627+ __typename : true ,
1628+ id : true ,
1629+ name : true ,
1630+ richText : { markdown : true , truncatedHTML : true } ,
1631+ fileField : { url : true , mimeType : true , fileName : true } ,
1632+ roleField : { key : true , name : true } ,
1633+ } ;
1634+
1635+ describe ( "findOneOperation" , ( ) => {
1636+ test ( "auto-expands richText: true to sub-selection from defaultSelection" , ( ) => {
1637+ const result = findOneOperation ( "widget" , "123" , defaultSelectionWithSpecialFields , "widget" , {
1638+ select : { id : true , richText : true } ,
1639+ } ) ;
1640+ expect ( result . query ) . toContain ( "richText" ) ;
1641+ expect ( result . query ) . toContain ( "markdown" ) ;
1642+ expect ( result . query ) . toContain ( "truncatedHTML" ) ;
1643+ } ) ;
1644+
1645+ test ( "auto-expands fileField: true to sub-selection from defaultSelection" , ( ) => {
1646+ const result = findOneOperation ( "widget" , "123" , defaultSelectionWithSpecialFields , "widget" , {
1647+ select : { id : true , fileField : true } ,
1648+ } ) ;
1649+ expect ( result . query ) . toContain ( "fileField" ) ;
1650+ expect ( result . query ) . toContain ( "url" ) ;
1651+ expect ( result . query ) . toContain ( "mimeType" ) ;
1652+ expect ( result . query ) . toContain ( "fileName" ) ;
1653+ } ) ;
1654+
1655+ test ( "auto-expands roleField: true to sub-selection from defaultSelection" , ( ) => {
1656+ const result = findOneOperation ( "widget" , "123" , defaultSelectionWithSpecialFields , "widget" , {
1657+ select : { id : true , roleField : true } ,
1658+ } ) ;
1659+ expect ( result . query ) . toContain ( "roleField" ) ;
1660+ expect ( result . query ) . toContain ( "key" ) ;
1661+ expect ( result . query ) . toContain ( "name" ) ;
1662+ } ) ;
1663+
1664+ test ( "preserves explicit object selections without overwriting" , ( ) => {
1665+ const result = findOneOperation ( "widget" , "123" , defaultSelectionWithSpecialFields , "widget" , {
1666+ select : { id : true , richText : { markdown : true } } ,
1667+ } ) ;
1668+ expect ( result . query ) . toContain ( "markdown" ) ;
1669+ expect ( result . query ) . not . toContain ( "truncatedHTML" ) ;
1670+ } ) ;
1671+
1672+ test ( "leaves normal scalar fields untouched" , ( ) => {
1673+ const result = findOneOperation ( "widget" , "123" , defaultSelectionWithSpecialFields , "widget" , { select : { id : true , name : true } } ) ;
1674+ expect ( result . query ) . toContain ( "id" ) ;
1675+ expect ( result . query ) . toContain ( "name" ) ;
1676+ expect ( result . query ) . not . toContain ( "richText" ) ;
1677+ } ) ;
1678+ } ) ;
1679+
1680+ describe ( "findManyOperation" , ( ) => {
1681+ test ( "auto-expands richText: true in findMany" , ( ) => {
1682+ const result = findManyOperation ( "widgets" , defaultSelectionWithSpecialFields , "widget" , {
1683+ select : { id : true , richText : true } ,
1684+ } ) ;
1685+ expect ( result . query ) . toContain ( "richText" ) ;
1686+ expect ( result . query ) . toContain ( "markdown" ) ;
1687+ expect ( result . query ) . toContain ( "truncatedHTML" ) ;
1688+ } ) ;
1689+
1690+ test ( "auto-expands fileField: true in findMany" , ( ) => {
1691+ const result = findManyOperation ( "widgets" , defaultSelectionWithSpecialFields , "widget" , {
1692+ select : { id : true , fileField : true } ,
1693+ } ) ;
1694+ expect ( result . query ) . toContain ( "fileField" ) ;
1695+ expect ( result . query ) . toContain ( "url" ) ;
1696+ expect ( result . query ) . toContain ( "mimeType" ) ;
1697+ } ) ;
1698+ } ) ;
1699+
1700+ describe ( "actionOperation" , ( ) => {
1701+ test ( "auto-expands richText: true in action" , ( ) => {
1702+ const result = actionOperation (
1703+ "createWidget" ,
1704+ defaultSelectionWithSpecialFields ,
1705+ "widget" ,
1706+ "widget" ,
1707+ {
1708+ widget : { type : "CreateWidgetInput" , value : { name : "test" } } ,
1709+ } ,
1710+ { select : { id : true , richText : true } }
1711+ ) ;
1712+ expect ( result . query ) . toContain ( "richText" ) ;
1713+ expect ( result . query ) . toContain ( "markdown" ) ;
1714+ expect ( result . query ) . toContain ( "truncatedHTML" ) ;
1715+ } ) ;
1716+ } ) ;
1717+ } ) ;
16241718} ) ;
0 commit comments