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

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


0

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.


Load 5 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *