graphql icon indicating copy to clipboard operation
graphql copied to clipboard

Entity named Subscription breaks ResolveProperty

Open raydirty opened this issue 7 years ago • 4 comments

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

When naming an entity Subscription all services and decorated parameters are undefined.

@Resolver(of => Subscription)
export class SubscriptionResolver {
  constructor(private readonly subscriptionService: SubscriptionService) {}

  @ResolveProperty('child')
  child(@Root() subscription: Subscription): string {
    console.log(this, subscription); // subscription and this.subscriptionService is undefined
    return this.subscriptionService.getTest(); // Cannot read property 'getTest' of undefined
  }
}

Expected behavior

The values shouldn't be undefined

Minimal reproduction of the problem with instructions

  • Git Repo: https://github.com/raydirty/nestjs-resolver-bug

Environment


platform-express version : 6.9.0
graphql version          : 6.5.3
common version           : 6.9.0
core version             : 6.9.0

raydirty avatar Nov 05 '19 06:11 raydirty

I am actually experiencing this issue with any use case for ResolveProperty.


UPDATE

Mine is a different issue.

For any poor sole spending an entire day debugging make sure you import the Resolver annotation from @nestjs/graphql and not from type-graphql. 😩

SawyerHopkins avatar Dec 04 '19 21:12 SawyerHopkins

Aside from this issue, what's the reason for naming any object type "Subscription". Isn't it going to create a lot of confusion (and potential type collisions in the generated GraphQL schema?)

kamilmysliwiec avatar Mar 10 '20 13:03 kamilmysliwiec

I had the same problem here (and it was hard to discover what was going on).

So I think it would be good to have a Note on the docs alerting for that.

What do you think guys?

ps: it might happen with Query, Mutation and so on.

dleitee avatar Apr 21 '20 15:04 dleitee

Creating an object type called either Subscription, Query, or Mutation will surely lead to errors because they collide with GraphQL operation types.

kamilmysliwiec avatar Apr 22 '20 06:04 kamilmysliwiec