Importing "@authenticated" directive using nestjs, apollo, and code-first approach

52 views Asked by At

I am using NestJS server with microservices and Apollo Router. I want to add "@authenticated" directive to my resolvers so I can omit authentication on requests to routes that do not require it. When using @Directive("@authenticated"), I get an error saying that I either have to use "@federation__authenticated" (which throws error saying it doesn't exist), or import "@authenticated" as a feature in my schema.

The problem is I am using code-first approach and can't really mutate my schema like this, I need to import the feature programatically somewhere in the app.

I thought I could do it in my module definition, but it seems there is not an attribute recognised in NextJS that would let me do that.

Currently I work with something like this:

GraphQLModule.forRootAsync<ApolloFederationDriverConfig>({
      imports: [ConfigModule.forFeature(GQLconfig)],
      inject: [GQLconfig.KEY],
      driver: ApolloFederationDriver,
      useFactory: (config: ConfigType<typeof GQLconfig>) => {
        return {
          playground: config.playground,
          debug: false,
          path: '/graphql',
          autoSchemaFile: {
            federation: 2,
          },
        };
      },
    }),

I tried using "@federation__authenticated" directive instead, but it didn't work at all.

Edit

Apparently, "@authenticated" is not a directive @nestjs/graphql re-exports, but it still has to be useable somehow when using code first approach.

0

There are 0 answers