-
-
Notifications
You must be signed in to change notification settings - Fork 674
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mark a @Field property as resolved by a @FieldResolver #440
Comments
The
So create your own interface that takes two parameters - object type and model type. |
This just did the opposite for me. I viewed the newly generated |
Isn't this just moving the responsibility but not solving the problem? You still have to maintain a new type? |
What problem solving? Moving from compile-time to runtime with
I can't maintain every use case of TypeGraphQL - maybe should I also add a third parameter with a list of allowed keys that you can oveerride the type? With #193 you would be able to point the type and field that you want to implement resolver for. |
I suppose I could have worded the OP better. The suggestion of a new option I am using Nest's |
Yes, sorry for confusing - checked in the code and it uses types info only for creating new fields, not for implementing resolvers. |
Apologies in either case, but I don't know if this is serious or sarcasm. I don't think changing the
In that case, you could do away with my suggestion of a new option and just warn if the type from |
I've just noticed, we're actually discussing two separate problems which can't be solved with one solution.
Whatever solution you do for 1) to make the above type safe, you've still made a mistake that your |
I won't implement new runtime check option if the new syntax of pointing type and field solves that problem too and also allow for custom names of method: @ObjectType()
class Author {
@Field(type => [Post])
posts: Post[]
}
@Resolver()
class Post Resolver
@FieldResolver(of => Author, author => author.posts)
getAuthorPosts(@Root() author: Author, @Args() args: PostsArgs) {
// ...
}
} |
Ahh, I read the issue you linked but at first glance didn't quite understand how it would solve the problem. But yes, you're correct. You don't duplicate the field type with that new syntax so can never get it wrong 👍 |
Great! So closing this issue as it will be fixed in #193 🔒 |
Is your feature request related to a problem? Please describe.
We have
@ObjectType()
classes which are reused by the front end, however many properties are resolved by@Resolver()
classes using@ResolveProperty()
(we're using NestJS).This means we have to ensure that our property resolver signature matches what's declared in the object type, and if they are different, which one gets used in the schema generation?
Describe the solution you'd like
An option on the
@Field()
decorator like,{ expectFieldResolver: true }
which tells type-graphql that this field should have a corresponding@FieldResolver()
(or@ResolverProperty()
in NestJS applications) with a matching signature.If the property resolver doesn't exist on any
@Resolver()
class, or the signature is different, a warning/error should be emitted from the schema generation stage.Describe alternatives you've considered
I've tried using the
ResolverInterface
interface but our@Root()
type is an instance of our TypeORM@Entity()
class and not an instance of our@ObjectType()
class. We have tried... implements ResolverInterface<MyEntity>
so that@Root()
is the correct type, but sometimes the field resolver returns an@ObjectType()
instance (or a scalar), and other times it returns a related@Entity()
class, which goes against theResolverInterface
definition.Another solution I've considered is to just omit the
@Field()
definition on the@ObjectType()
class but then these types are missing properties when they're imported by the UI.The text was updated successfully, but these errors were encountered: