Inability to Use transformSchema and Custom Directives in Apollo Gateway Configuration with @nestjs/graphql #3296

Current behavior

The issue manifests when attempting to use the transformSchema and publicDirectiveTransformer in the Apollo Gateway configuration within a NestJS application using the code-first approach. Specifically, the transformSchema function never fires, and no console logs are generated, even when placed directly in the transformSchema function.

Additionally, the issue allows for any arbitrary property (like abc: true) to be added to the Gateway configuration without throwing any errors, indicating that the configuration is not being properly validated or processed by the @nestjs/graphql package.

Minimum reproduction code

A minimal reproduction repository is available here:

https://github.com/ahmad-punch/nestjs-gateway-federation2-transformSchema-issue-reproduction-code.git

Steps to reproduce

Minimum Reproduction Code

You can reproduce this issue with the following code setup:

Approach:

  • GraphQL: Code-first
  • Schema Generation: Auto-generated using autoSchemaFile: { federation: 2 }
  • NestJS Modules: @nestjs/graphql, @apollo/gateway

Steps to Reproduce

Generic Steps:

  1. Create a NestJS project with the @nestjs/graphql and @apollo/gateway packages.
  2. Set up the GraphQLModule with the Apollo Gateway Driver as shown in the provided app.module.ts.
  3. Attempt to use transformSchema or any other schema transformation functions.
  4. Observe that transformSchema is never called, and no logs from this function are visible.
  5. Also, add any arbitrary key (like abc: true) to the gateway configuration and observe that it does not throw an error or get processed.

Steps Using GitHub Repository:

  1. Clone the repository:

    Plain text
    Copy to clipboard
    Open code in new window
    EnlighterJS 3 Syntax Highlighter
    <code>git clone https://github.com/ahmad-punch/nestjs-gateway-federation2-transformSchema-issue-reproduction-code.git`
    </code>
    <code>git clone https://github.com/ahmad-punch/nestjs-gateway-federation2-transformSchema-issue-reproduction-code.git` </code>
    git clone https://github.com/ahmad-punch/nestjs-gateway-federation2-transformSchema-issue-reproduction-code.git`
    
    
  2. Navigate to the platform-service folder, install dependencies, and start the service:

    Plain text
    Copy to clipboard
    Open code in new window
    EnlighterJS 3 Syntax Highlighter
    <code> cd /platform-service
    npm install
    npm run dev `
    </code>
    <code> cd /platform-service npm install npm run dev ` </code>
       cd /platform-service 
       npm install
       npm run dev  `
    
    
  3. Once the platform service is started, navigate to the gateway folder, install dependencies, and start the gateway service:

    Plain text
    Copy to clipboard
    Open code in new window
    EnlighterJS 3 Syntax Highlighter
    <code> cd ../gateway
    npm install
    npm run dev
    `
    </code>
    <code> cd ../gateway npm install npm run dev ` </code>
     cd ../gateway
     npm install
     npm run dev 
     `
    
    
  4. Open the GraphQL Playground for the gateway, and execute the following query:

    Plain text
    Copy to clipboard
    Open code in new window
    EnlighterJS 3 Syntax Highlighter
    <code> query {
    findAllTest {
    exampleField
    }
    }
    `
    </code>
    <code> query { findAllTest { exampleField } } ` </code>
       query {
       findAllTest {
       exampleField
           }
         } 
       `
    
    
  5. Observe the logs of the gateway server. You will notice that the gateway does not detect the directive, nor does it run any logs mentioned in the transformSchema function in the app.module.ts of the gateway. However, it should.

Expected behavior

  • The transformSchema function should be called, and logs should be visible to confirm that the schema is being transformed.
  • The configuration should be validated to prevent arbitrary keys from being added without causing an error.
  • The Gateway should be able to correctly handle and apply custom directives from subgraphs (like @public), allowing them to control behavior such as skipping authentication checks.

Package version

12.2.0

Graphql version

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> "dependencies": {
"@apollo/gateway": "^2.8.1",
"@apollo/server": "^4.11.0",
"@apollo/subgraph": "^2.8.1",
"@nestjs/apollo": "^12.2.0",
"@nestjs/common": "^10.0.0",
"@nestjs/config": "^3.2.3",
"@nestjs/core": "^10.0.0",
"@nestjs/graphql": "^12.2.0",
"@nestjs/microservices": "^10.3.10",
"@nestjs/mongoose": "^10.0.10",
"@nestjs/platform-express": "^10.0.0",
"graphql": "^16.9.0",
"jsonwebtoken": "^9.0.2",
"mongoose": "^8.5.1",
"reflect-metadata": "^0.2.0",
"rxjs": "^7.8.1"
}
</code>
<code> "dependencies": { "@apollo/gateway": "^2.8.1", "@apollo/server": "^4.11.0", "@apollo/subgraph": "^2.8.1", "@nestjs/apollo": "^12.2.0", "@nestjs/common": "^10.0.0", "@nestjs/config": "^3.2.3", "@nestjs/core": "^10.0.0", "@nestjs/graphql": "^12.2.0", "@nestjs/microservices": "^10.3.10", "@nestjs/mongoose": "^10.0.10", "@nestjs/platform-express": "^10.0.0", "graphql": "^16.9.0", "jsonwebtoken": "^9.0.2", "mongoose": "^8.5.1", "reflect-metadata": "^0.2.0", "rxjs": "^7.8.1" } </code>
    "dependencies": {
                                 "@apollo/gateway": "^2.8.1",
                                 "@apollo/server": "^4.11.0",
                                 "@apollo/subgraph": "^2.8.1",
                                 "@nestjs/apollo": "^12.2.0",
                                 "@nestjs/common": "^10.0.0",
                                 "@nestjs/config": "^3.2.3",
                                 "@nestjs/core": "^10.0.0",
                                 "@nestjs/graphql": "^12.2.0",
                                 "@nestjs/microservices": "^10.3.10",
                                 "@nestjs/mongoose": "^10.0.10",
                                 "@nestjs/platform-express": "^10.0.0",
                                  "graphql": "^16.9.0",
                                  "jsonwebtoken": "^9.0.2",
                                  "mongoose": "^8.5.1",
                                  "reflect-metadata": "^0.2.0",
                                  "rxjs": "^7.8.1"
                           }

NestJS version

10.0.0

Node.js version

18.17.0

In which operating systems have you tested?

  • [ ] macOS
  • [X] Windows
  • [ ] Linux

Other

Why I’m Doing This

The main goal is to add a directive in the subgraph (e.g., @public) that will instruct the supergraph/gateway to leave certain queries public, effectively bypassing authentication for those queries. The gateway should respect this directive, allowing the subgraph to control which queries require authentication and which do not.

However, due to the issues outlined above, the intended behavior cannot be achieved. The transformSchema function is not being called, custom directives are not processed correctly, and the configuration is not being validated properly. This blocks the implementation of a flexible, directive-based authentication system in a federated GraphQL architecture.

This issue is also created in Nestjs graphql repo
https://github.com/nestjs/graphql/issues/3296

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Inability to Use transformSchema and Custom Directives in Apollo Gateway Configuration with @nestjs/graphql #3296

Current behavior

The issue manifests when attempting to use the transformSchema and publicDirectiveTransformer in the Apollo Gateway configuration within a NestJS application using the code-first approach. Specifically, the transformSchema function never fires, and no console logs are generated, even when placed directly in the transformSchema function.

Additionally, the issue allows for any arbitrary property (like abc: true) to be added to the Gateway configuration without throwing any errors, indicating that the configuration is not being properly validated or processed by the @nestjs/graphql package.

Minimum reproduction code

A minimal reproduction repository is available here:

https://github.com/ahmad-punch/nestjs-gateway-federation2-transformSchema-issue-reproduction-code.git

Steps to reproduce

Minimum Reproduction Code

You can reproduce this issue with the following code setup:

Approach:

  • GraphQL: Code-first
  • Schema Generation: Auto-generated using autoSchemaFile: { federation: 2 }
  • NestJS Modules: @nestjs/graphql, @apollo/gateway

Steps to Reproduce

Generic Steps:

  1. Create a NestJS project with the @nestjs/graphql and @apollo/gateway packages.
  2. Set up the GraphQLModule with the Apollo Gateway Driver as shown in the provided app.module.ts.
  3. Attempt to use transformSchema or any other schema transformation functions.
  4. Observe that transformSchema is never called, and no logs from this function are visible.
  5. Also, add any arbitrary key (like abc: true) to the gateway configuration and observe that it does not throw an error or get processed.

Steps Using GitHub Repository:

  1. Clone the repository:

    Plain text
    Copy to clipboard
    Open code in new window
    EnlighterJS 3 Syntax Highlighter
    <code>git clone https://github.com/ahmad-punch/nestjs-gateway-federation2-transformSchema-issue-reproduction-code.git`
    </code>
    <code>git clone https://github.com/ahmad-punch/nestjs-gateway-federation2-transformSchema-issue-reproduction-code.git` </code>
    git clone https://github.com/ahmad-punch/nestjs-gateway-federation2-transformSchema-issue-reproduction-code.git`
    
    
  2. Navigate to the platform-service folder, install dependencies, and start the service:

    Plain text
    Copy to clipboard
    Open code in new window
    EnlighterJS 3 Syntax Highlighter
    <code> cd /platform-service
    npm install
    npm run dev `
    </code>
    <code> cd /platform-service npm install npm run dev ` </code>
       cd /platform-service 
       npm install
       npm run dev  `
    
    
  3. Once the platform service is started, navigate to the gateway folder, install dependencies, and start the gateway service:

    Plain text
    Copy to clipboard
    Open code in new window
    EnlighterJS 3 Syntax Highlighter
    <code> cd ../gateway
    npm install
    npm run dev
    `
    </code>
    <code> cd ../gateway npm install npm run dev ` </code>
     cd ../gateway
     npm install
     npm run dev 
     `
    
    
  4. Open the GraphQL Playground for the gateway, and execute the following query:

    Plain text
    Copy to clipboard
    Open code in new window
    EnlighterJS 3 Syntax Highlighter
    <code> query {
    findAllTest {
    exampleField
    }
    }
    `
    </code>
    <code> query { findAllTest { exampleField } } ` </code>
       query {
       findAllTest {
       exampleField
           }
         } 
       `
    
    
  5. Observe the logs of the gateway server. You will notice that the gateway does not detect the directive, nor does it run any logs mentioned in the transformSchema function in the app.module.ts of the gateway. However, it should.

Expected behavior

  • The transformSchema function should be called, and logs should be visible to confirm that the schema is being transformed.
  • The configuration should be validated to prevent arbitrary keys from being added without causing an error.
  • The Gateway should be able to correctly handle and apply custom directives from subgraphs (like @public), allowing them to control behavior such as skipping authentication checks.

Package version

12.2.0

Graphql version

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> "dependencies": {
"@apollo/gateway": "^2.8.1",
"@apollo/server": "^4.11.0",
"@apollo/subgraph": "^2.8.1",
"@nestjs/apollo": "^12.2.0",
"@nestjs/common": "^10.0.0",
"@nestjs/config": "^3.2.3",
"@nestjs/core": "^10.0.0",
"@nestjs/graphql": "^12.2.0",
"@nestjs/microservices": "^10.3.10",
"@nestjs/mongoose": "^10.0.10",
"@nestjs/platform-express": "^10.0.0",
"graphql": "^16.9.0",
"jsonwebtoken": "^9.0.2",
"mongoose": "^8.5.1",
"reflect-metadata": "^0.2.0",
"rxjs": "^7.8.1"
}
</code>
<code> "dependencies": { "@apollo/gateway": "^2.8.1", "@apollo/server": "^4.11.0", "@apollo/subgraph": "^2.8.1", "@nestjs/apollo": "^12.2.0", "@nestjs/common": "^10.0.0", "@nestjs/config": "^3.2.3", "@nestjs/core": "^10.0.0", "@nestjs/graphql": "^12.2.0", "@nestjs/microservices": "^10.3.10", "@nestjs/mongoose": "^10.0.10", "@nestjs/platform-express": "^10.0.0", "graphql": "^16.9.0", "jsonwebtoken": "^9.0.2", "mongoose": "^8.5.1", "reflect-metadata": "^0.2.0", "rxjs": "^7.8.1" } </code>
    "dependencies": {
                                 "@apollo/gateway": "^2.8.1",
                                 "@apollo/server": "^4.11.0",
                                 "@apollo/subgraph": "^2.8.1",
                                 "@nestjs/apollo": "^12.2.0",
                                 "@nestjs/common": "^10.0.0",
                                 "@nestjs/config": "^3.2.3",
                                 "@nestjs/core": "^10.0.0",
                                 "@nestjs/graphql": "^12.2.0",
                                 "@nestjs/microservices": "^10.3.10",
                                 "@nestjs/mongoose": "^10.0.10",
                                 "@nestjs/platform-express": "^10.0.0",
                                  "graphql": "^16.9.0",
                                  "jsonwebtoken": "^9.0.2",
                                  "mongoose": "^8.5.1",
                                  "reflect-metadata": "^0.2.0",
                                  "rxjs": "^7.8.1"
                           }

NestJS version

10.0.0

Node.js version

18.17.0

In which operating systems have you tested?

  • [ ] macOS
  • [X] Windows
  • [ ] Linux

Other

Why I’m Doing This

The main goal is to add a directive in the subgraph (e.g., @public) that will instruct the supergraph/gateway to leave certain queries public, effectively bypassing authentication for those queries. The gateway should respect this directive, allowing the subgraph to control which queries require authentication and which do not.

However, due to the issues outlined above, the intended behavior cannot be achieved. The transformSchema function is not being called, custom directives are not processed correctly, and the configuration is not being validated properly. This blocks the implementation of a flexible, directive-based authentication system in a federated GraphQL architecture.

This issue is also created in Nestjs graphql repo
https://github.com/nestjs/graphql/issues/3296

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật