[ ] 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.
I'm trying to resolve globally a simple GraphQL type with NestJS Module, the following type Item
has a product property which returns a Product type
extend type Query {
item(itemId: UUID!): Item
}
type Item {
id: UUID!
reference: String
status: ItemStatus
billingStarted: DateTime
billingEnded: DateTime
product: Product
children: [Item]
}
My resolver code looks like this:
import {Args, Query, Resolver, ResolveProperty, Parent} from '@nestjs/graphql';
import {Item, Product} from '../generated/graphql';
import {Inject, Injectable} from '@nestjs/common';
import {ItemsRepository} from './items.repository';
import {ProductRepository} from './product/product.repository';
@Injectable()
export class ItemsResolver {
constructor(
@Inject('ItemsRepository') private readonly itemsRepository: ItemsRepository,
@Inject('ProductRepository') private readonly productRepository: ProductRepository,
) {
}
@Query()
async item(@Args('itemId') itemId: string): Promise<Item> {
return {id: itemId};
}
@Resolver("Item")
@ResolveProperty("product")
product(@Parent() item): Promise<Product> {
console.log("HITTING HERE")
return {};
}
}
I defined the method product decorating it with @Resolver and @ResolverProperty expecting that whenever an Item.product property get resolved that function would be invoked.
Instead, the server doesn't start and complain about the following error:
(node:53227) UnhandledPromiseRejectionWarning: Error: Item.Item defined in resolvers, but not in schema
How does it get the Item.Item resolver name from this method definition? 馃槼
The reason why I don't want to add the decorator at the Class level is because i'd like to have another function in the same class that resolves a different resolver like this:
@Injectable()
class ItemResolver {
@Resolver("Item")
@ResolveProperty("product")
product(@Parent() item): Promise<Product> {
console.log("HITTING HERE")
return {};
}
@Resolver("Account")
@ResolveProperty("items")
accountItems() {
// Still resolve items from the `Account.items` type
}
}
The server would start and my resolver would be bound under the type Item.product
Nest version: 5.4.0
For Tooling issues:
- Platform: Mac
Could you provide a minimal repostiory which reproduces your issue?
I have the same issue and I fixed it by flipping the order of the decorators:
@Injectable()
class ItemResolver {
// surprisingly this does not work if Resolver is put before ResolveProperty
@ResolveProperty("product")
@Resolver("Item")
product(@Parent() item): Promise<Product> {
console.log("HITTING HERE")
return {};
}
@ResolveProperty("items")
@Resolver("Account")
accountItems() {
// Still resolve items from the `Account.items` type
}
}
Hopefully that solves it for you too
@Ephys could you create a separate issue + provide a minimal repo that reproduces this behavior?
@kamilmysliwiec sure I can do that! :) I'll send that your way when I can
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.