Open ahmad-punch opened 3 months ago
I was reading and I am not sure but this seems relevant:
https://github.com/nestjs/graphql/pull/2059#issue-1159936226
+1 on this directive support is needed if you want to use a real router instead of Apollo Gateway
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:
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.