nestjs / graphql

GraphQL (TypeScript) module for Nest framework (node.js) 🍷
https://docs.nestjs.com/graphql/quick-start
MIT License
1.46k stars 397 forks source link

Working with interface types resolvers #880

Closed ScreamZ closed 4 years ago

ScreamZ commented 4 years ago

I'm submitting a...


[ ] Regression 
[ ] Bug report
[ x ] Feature request
[ x ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

I would like to define resolvers for interface types, which are normally not allowed.

Currently, I'm doing this to handle those cases:

For those who want more about it, read my initial issue at https://stackoverflow.com/questions/61867673/nestjs-x-graphql-x-typegoose-issue-on-sub-resolver

// One annotation per things that implement my CurrentUserDTO interface
@Resolver(() => IndividualUserDTO)
@Resolver(() => ProfessionnalUserDTO)
export class CurrentUserDTOResolver {
  constructor(
    private readonly supplierService: SupplierService,
    private readonly volunteerService: VolunteerService,
    private readonly productService: ProductService,
  ) {}

  @ResolveField(() => [Supplier])
  async suppliers(@Parent() user: CurrentUserDTO) {
    return user.suppliers.length > 0
      ? this.supplierService.find({ _id: { $in: user.suppliers } })
      : [];
  }
}

Interrogation

While this is working great, I would like to be sure I'm not hacking the library in terms of practice to make this work

I saw that an inheritResolversFromInterfaces property exists in apollo https://www.apollographql.com/docs/apollo-server/api/apollo-server/#makeexecutableschema

But I can't figure out how to use it in NestJS… Maybe you could help me? Look like it's not implemented to pass args to makeExecutableSchema

Environment


➜ yarn list --depth=0 --pattern nest
yarn list v1.22.4
β”œβ”€ @nestjs/cli@7.1.4
β”œβ”€ @nestjs/common@7.0.9
β”œβ”€ @nestjs/config@0.4.0
β”œβ”€ @nestjs/core@7.0.9
β”œβ”€ @nestjs/graphql@7.3.5
β”œβ”€ @nestjs/jwt@7.0.0
β”œβ”€ @nestjs/mapped-types@0.0.3
β”œβ”€ @nestjs/passport@7.0.0
β”œβ”€ @nestjs/platform-express@7.0.9
β”œβ”€ @nestjs/schematics@7.0.0
β”œβ”€ @nestjs/testing@7.0.9
└─ nestjs-typegoose@7.1.22

kamilmysliwiec commented 4 years ago

I would like to define resolvers for interface types, which are normally not allowed.

It's impossible to define resolvers for interface types (in general).

ScreamZ commented 4 years ago

Figured out later, thanks

dberardo-com commented 6 months ago

is this still an issue ? does the flag inheritResolversFromInterfaces have any meaning ?