@@ -1621,4 +1621,120 @@ 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 (
1638+ "widget" ,
1639+ "123" ,
1640+ defaultSelectionWithSpecialFields ,
1641+ "widget" ,
1642+ { select : { id : true , richText : true } }
1643+ ) ;
1644+ expect ( result . query ) . toContain ( "richText" ) ;
1645+ expect ( result . query ) . toContain ( "markdown" ) ;
1646+ expect ( result . query ) . toContain ( "truncatedHTML" ) ;
1647+ } ) ;
1648+
1649+ test ( "auto-expands fileField: true to sub-selection from defaultSelection" , ( ) => {
1650+ const result = findOneOperation (
1651+ "widget" ,
1652+ "123" ,
1653+ defaultSelectionWithSpecialFields ,
1654+ "widget" ,
1655+ { select : { id : true , fileField : true } }
1656+ ) ;
1657+ expect ( result . query ) . toContain ( "fileField" ) ;
1658+ expect ( result . query ) . toContain ( "url" ) ;
1659+ expect ( result . query ) . toContain ( "mimeType" ) ;
1660+ expect ( result . query ) . toContain ( "fileName" ) ;
1661+ } ) ;
1662+
1663+ test ( "auto-expands roleField: true to sub-selection from defaultSelection" , ( ) => {
1664+ const result = findOneOperation (
1665+ "widget" ,
1666+ "123" ,
1667+ defaultSelectionWithSpecialFields ,
1668+ "widget" ,
1669+ { select : { id : true , roleField : true } }
1670+ ) ;
1671+ expect ( result . query ) . toContain ( "roleField" ) ;
1672+ expect ( result . query ) . toContain ( "key" ) ;
1673+ expect ( result . query ) . toContain ( "name" ) ;
1674+ } ) ;
1675+
1676+ test ( "preserves explicit object selections without overwriting" , ( ) => {
1677+ const result = findOneOperation (
1678+ "widget" ,
1679+ "123" ,
1680+ defaultSelectionWithSpecialFields ,
1681+ "widget" ,
1682+ { select : { id : true , richText : { markdown : true } } }
1683+ ) ;
1684+ expect ( result . query ) . toContain ( "markdown" ) ;
1685+ expect ( result . query ) . not . toContain ( "truncatedHTML" ) ;
1686+ } ) ;
1687+
1688+ test ( "leaves normal scalar fields untouched" , ( ) => {
1689+ const result = findOneOperation (
1690+ "widget" ,
1691+ "123" ,
1692+ defaultSelectionWithSpecialFields ,
1693+ "widget" ,
1694+ { select : { id : true , name : true } }
1695+ ) ;
1696+ expect ( result . query ) . toContain ( "id" ) ;
1697+ expect ( result . query ) . toContain ( "name" ) ;
1698+ expect ( result . query ) . not . toContain ( "richText" ) ;
1699+ } ) ;
1700+ } ) ;
1701+
1702+ describe ( "findManyOperation" , ( ) => {
1703+ test ( "auto-expands richText: true in findMany" , ( ) => {
1704+ const result = findManyOperation ( "widgets" , defaultSelectionWithSpecialFields , "widget" , {
1705+ select : { id : true , richText : true } ,
1706+ } ) ;
1707+ expect ( result . query ) . toContain ( "richText" ) ;
1708+ expect ( result . query ) . toContain ( "markdown" ) ;
1709+ expect ( result . query ) . toContain ( "truncatedHTML" ) ;
1710+ } ) ;
1711+
1712+ test ( "auto-expands fileField: true in findMany" , ( ) => {
1713+ const result = findManyOperation ( "widgets" , defaultSelectionWithSpecialFields , "widget" , {
1714+ select : { id : true , fileField : true } ,
1715+ } ) ;
1716+ expect ( result . query ) . toContain ( "fileField" ) ;
1717+ expect ( result . query ) . toContain ( "url" ) ;
1718+ expect ( result . query ) . toContain ( "mimeType" ) ;
1719+ } ) ;
1720+ } ) ;
1721+
1722+ describe ( "actionOperation" , ( ) => {
1723+ test ( "auto-expands richText: true in action" , ( ) => {
1724+ const result = actionOperation (
1725+ "createWidget" ,
1726+ defaultSelectionWithSpecialFields ,
1727+ "widget" ,
1728+ "widget" ,
1729+ {
1730+ widget : { type : "CreateWidgetInput" , value : { name : "test" } } ,
1731+ } ,
1732+ { select : { id : true , richText : true } }
1733+ ) ;
1734+ expect ( result . query ) . toContain ( "richText" ) ;
1735+ expect ( result . query ) . toContain ( "markdown" ) ;
1736+ expect ( result . query ) . toContain ( "truncatedHTML" ) ;
1737+ } ) ;
1738+ } ) ;
1739+ } ) ;
16241740} ) ;
0 commit comments