Graphql: Resolver doesn't resolve custom ObjectType names

Created on 21 May 2019  路  10Comments  路  Source: nestjs/graphql

I'm submitting a...


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

Current behavior

If you rename an ObjectType via the decorator the resolver (@Resolver) of nestjs can't resolve the correct schema. The generated gql schema is fine though.

Expected behavior

The @Resolver from @nestjs/graphql resolves custom names like the @Resolver from type-graphql

Minimal reproduction of the problem with instructions

https://github.com/xXKeyleXx/graphql-minimal-resolver-object-type

Resolver

import { ResolveProperty, Resolver, Root } from '@nestjs/graphql';

@Resolver(of => QuestionSchema)
export class QuestionResolver {
  constructor(
    private questionService: QuestionService,
  ) {
  }

  @ResolveProperty()
  async property(@Root() root: any): Promise<QuestionPropertySchema> {
    ...
  }
}

Typescript Schema

import { Field, ID, ObjectType } from 'type-graphql';

@ObjectType('Question')
export class QuestionSchema {
  @Field(type => ID)
  id: string;
}

Generated Schema

type Question {
  id: ID!
}

What is the motivation / use case for changing the behavior?

I would like to have different names in the schema and the actual class because I want the classname to correspond to the file(name) structure we chose.

Environment

+
@nestjs/common: 6.2.3,
@nestjs/core: 6.2.3,
@nestjs/graphql: 6.2.1,
apollo-server-express: 2.5.0
type-graphql: 0.17.4
graphql: 14.3.0 

For Tooling issues:
- Node version: v10.15.3
- Platform:  Linux (Docker)
needs clarification

Most helpful comment

Using @Resolver() directly from type-graphql will cause side-effects. This issue is about something else that we have to fix on our side

All 10 comments

Please, provide a minimal repository which reproduces your issue :)

If you change import of Resolver from @nest/graphql to type-graphql its normally working.
This is bug of nest wrapper.
Apparently nest have a bug in initialization?
OR if you allow resolvers not in schema - its working too

 resolverValidationOptions:   {
        allowResolversNotInSchema: true,
      },

I don't remember exactly what it was, but when you switch Resolver from @nest/graphql to type-graphql something else stopped working (I think it was the params of the property resolvers didn't get injected correctly)

I don't remember exactly what it was, but when you switch Resolver from @nest/graphql to type-graphql something else stopped working (I think it was the params of the property resolvers didn't get injected correctly)

Try to set allowResolversNotInSchema: true, in graphql module configuration

Using @Resolver() directly from type-graphql will cause side-effects. This issue is about something else that we have to fix on our side

Using @Resolver() directly from type-graphql will cause side-effects. This issue is about something else that we have to fix on our side

Im not saying that is resolve issue - this is for vector of searching error

But with allowResolversNotInSchema: true we have one problem, @ResolveProperty() in field resolver context === undefined

Fixed in 6.2.4

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

liudonghua123 picture liudonghua123  路  3Comments

joseym picture joseym  路  4Comments

galkin picture galkin  路  4Comments

harm-less picture harm-less  路  4Comments

radarsu picture radarsu  路  3Comments