@@ -1505,4 +1505,86 @@ describe('Codegen Executor', () => {
15051505 expect ( result . length ) . toBe ( 1 ) ;
15061506 expect ( result [ 0 ] . content ) . toContain ( 'export type WpCoreImageBlockForGalleryFragment = ' ) ;
15071507 } ) ;
1508+
1509+ describe ( 'Federation' , ( ) => {
1510+ it ( 'should include federation directives and scalar when federation: true ' , async ( ) => {
1511+ const { result } = await executeCodegen ( {
1512+ schema : [ SIMPLE_TEST_SCHEMA ] ,
1513+ generates : {
1514+ 'out1.graphql' : {
1515+ plugins : [ 'schema-ast' ] ,
1516+ } ,
1517+ } ,
1518+ config : {
1519+ federation : true ,
1520+ } ,
1521+ } ) ;
1522+
1523+ expect ( result [ 0 ] . content ) . toContain ( 'directive @external on FIELD_DEFINITION' ) ;
1524+ expect ( result [ 0 ] . content ) . toContain (
1525+ 'directive @requires(fields: _FieldSet!) on FIELD_DEFINITION' ,
1526+ ) ;
1527+ expect ( result [ 0 ] . content ) . toContain (
1528+ 'directive @provides(fields: _FieldSet!) on FIELD_DEFINITION' ,
1529+ ) ;
1530+ expect ( result [ 0 ] . content ) . toContain (
1531+ 'directive @key(fields: _FieldSet!) on OBJECT | INTERFACE' ,
1532+ ) ;
1533+ expect ( result [ 0 ] . content ) . toContain ( 'scalar _FieldSet' ) ;
1534+ } ) ;
1535+ it ( 'should not include federation directives and scalar when federation: true and disableFederationDirectiveAndScalarInjection: true' , async ( ) => {
1536+ const { result } = await executeCodegen ( {
1537+ schema : [ SIMPLE_TEST_SCHEMA ] ,
1538+ generates : {
1539+ 'out1.graphql' : {
1540+ plugins : [ 'schema-ast' ] ,
1541+ } ,
1542+ } ,
1543+ config : {
1544+ federation : true ,
1545+ disableFederationDirectiveAndScalarInjection : true ,
1546+ } ,
1547+ } ) ;
1548+
1549+ expect ( result [ 0 ] . content ) . not . toContain ( 'directive @external on FIELD_DEFINITION' ) ;
1550+ expect ( result [ 0 ] . content ) . not . toContain (
1551+ 'directive @requires(fields: _FieldSet!) on FIELD_DEFINITION' ,
1552+ ) ;
1553+ expect ( result [ 0 ] . content ) . not . toContain (
1554+ 'directive @provides(fields: _FieldSet!) on FIELD_DEFINITION' ,
1555+ ) ;
1556+ expect ( result [ 0 ] . content ) . not . toContain (
1557+ 'directive @key(fields: _FieldSet!) on OBJECT | INTERFACE' ,
1558+ ) ;
1559+ expect ( result [ 0 ] . content ) . not . toContain ( 'scalar _FieldSet' ) ;
1560+ expect ( result [ 0 ] . content ) . toContain ( 'type MyType' ) ;
1561+ } ) ;
1562+ it ( 'should not include federation directives and scalar when federation: false and disableFederationDirectiveAndScalarInjection: true' , async ( ) => {
1563+ const { result } = await executeCodegen ( {
1564+ schema : [ SIMPLE_TEST_SCHEMA ] ,
1565+ generates : {
1566+ 'out1.graphql' : {
1567+ plugins : [ 'schema-ast' ] ,
1568+ } ,
1569+ } ,
1570+ config : {
1571+ federation : false ,
1572+ disableFederationDirectiveAndScalarInjection : true ,
1573+ } ,
1574+ } ) ;
1575+
1576+ expect ( result [ 0 ] . content ) . not . toContain ( 'directive @external on FIELD_DEFINITION' ) ;
1577+ expect ( result [ 0 ] . content ) . not . toContain (
1578+ 'directive @requires(fields: _FieldSet!) on FIELD_DEFINITION' ,
1579+ ) ;
1580+ expect ( result [ 0 ] . content ) . not . toContain (
1581+ 'directive @provides(fields: _FieldSet!) on FIELD_DEFINITION' ,
1582+ ) ;
1583+ expect ( result [ 0 ] . content ) . not . toContain (
1584+ 'directive @key(fields: _FieldSet!) on OBJECT | INTERFACE' ,
1585+ ) ;
1586+ expect ( result [ 0 ] . content ) . not . toContain ( 'scalar _FieldSet' ) ;
1587+ expect ( result [ 0 ] . content ) . toContain ( 'type MyType' ) ;
1588+ } ) ;
1589+ } ) ;
15081590} ) ;
0 commit comments