Inability to Use transformSchema
and Custom Directives in Apollo Gateway Configuration with @nestjs/graphql
#3296
Labels
transformSchema
and Custom Directives in Apollo Gateway Configuration with @nestjs/graphql
#3296
Is there an existing issue for this?
Current behavior
The issue manifests when attempting to use the
transformSchema
andpublicDirectiveTransformer
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
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:
autoSchemaFile: { federation: 2 }
@nestjs/graphql
,@apollo/gateway
GitHub Repository:
A minimal reproduction repository is available here:
https://github.com/ahmad-punch/nestjs-gateway-federation2-transformSchema-issue-reproduction-code.git
Steps to Reproduce
Generic Steps:
@nestjs/graphql
and@apollo/gateway
packages.GraphQLModule
with the Apollo Gateway Driver as shown in the providedapp.module.ts
.transformSchema
or any other schema transformation functions.transformSchema
is never called, and no logs from this function are visible.abc: true
) to the gateway configuration and observe that it does not throw an error or get processed.Steps Using GitHub Repository:
Clone the repository:
git clone https://github.com/ahmad-punch/nestjs-gateway-federation2-transformSchema-issue-reproduction-code.git`
Navigate to the platform-service folder, install dependencies, and start the service:
Once the platform service is started, navigate to the gateway folder, install dependencies, and start the gateway service:
Open the GraphQL Playground for the gateway, and execute the following query:
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 theapp.module.ts
of the gateway. However, it should.Expected behavior
transformSchema
function should be called, and logs should be visible to confirm that the schema is being transformed.@public
), allowing them to control behavior such as skipping authentication checks.Package version
12.2.0
Graphql version
NestJS version
10.0.0
Node.js version
18.17.0
In which operating systems have you tested?
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.The text was updated successfully, but these errors were encountered: