Replies: 4 comments 2 replies
-
@djpate I don't understand what you want to achieve. |
Beta Was this translation helpful? Give feedback.
-
I'm trying to implement something similar to the averageRating method in the examples. @Field(type => Float, { nullable: true })
averageRating(@Arg("since") sinceDate: Date): number | null {
const ratings = this.ratings.filter(rate => rate.date > sinceDate);
if (!ratings.length) return null;
const ratingsSum = ratings.reduce((a, b) => a + b, 0);
return ratingsSum / ratings.length;
} in the method above, so @ObjectType()
export class PhishingTest {
@Field(type => ID)
id(): sting => {
return `${this.id}-foobar` <---- this.id here is undefined
} |
Beta Was this translation helpful? Give feedback.
-
To be clear, this works fine If I use a FieldResolver() on the resolver itself. I'd much rather use it on the type thought |
Beta Was this translation helpful? Give feedback.
-
OK i've figured it out. I need to use @root() as an argument to my field method in the ObectType and that gives me access to the actual object. |
Beta Was this translation helpful? Give feedback.
-
Assume I have the following resolver
and I have a post type as such
This works perfectly fine.
Now what if I try to create a custom method for my id field such as
now
this.id
isundefined
.The reason is that my
Post
model where I do my data fetching is a class that looks like thisSo I'm assuming somewhere in the context setting of the type the this gets mumbled up? Not sure what do to about that.
Beta Was this translation helpful? Give feedback.
All reactions