golevelup / nestjs

A collection of badass modules and utilities to help you level up your NestJS applications 🚀
MIT License
2.28k stars 262 forks source link

discover graphql mutations, queries, subscriptions? #692

Open apopapazisis opened 8 months ago

apopapazisis commented 8 months ago

is it possible to discover graphql mutations, queries, subscriptions?

WonderPanda commented 8 months ago

Yes, it should be possible. You will just have to refer to the NestJS code to determine what metadata gets attached when those decorators are used and then you can use the Discovery package to look them up

apopapazisis commented 8 months ago

@WonderPanda I try to do this

import { NestFactory } from '@nestjs/core';
import { Module } from '@nestjs/common';
import { DiscoveryModule, DiscoveryService } from '@golevelup/nestjs-discovery';
import { GraphQLSchemaBuilderModule } from '@nestjs/graphql';

@Module({
  imports: [
    DiscoveryModule,
    GraphQLSchemaBuilderModule
  ]
})

class CustomModule {}

const main = async () => {
  const app = await NestFactory.create(CustomModule);
  await app.init();

  const discoveryService = app.get(DiscoveryService);
  const resolvers = await discoveryService.providersWithMetaAtKey('graphql:resolver');

  console.log(resolvers)
};
main();

which returns an empty array, I am not sure that the code I have is 100% correct.

underfisk commented 1 month ago

@apopapazisis Would it be possible to have a repro (maybe gh repo) to help with this? There's some potential tweaks such as the gql resolver symbol being invalid :sweat_smile: