Hi, I'm a bit confused by the sample code in the prefetching section of the docs:
#[Type]
class PostType {
/**
* @param Post $post
* @param mixed $prefetchedUsers
* @return User
*/
#[Field(prefetchMethod: "prefetchUsers")]
public function getUser(Post $post, $prefetchedUsers): User
{
// This method will receive the $prefetchedUsers as second argument. This is the return value of the "prefetchUsers" method below.
// Using this prefetched list, it should be easy to map it to the post
}
/**
* @param Post[] $posts
* @return mixed
*/
public function prefetchUsers(iterable $posts)
{
// This function is called only once per GraphQL request
// with the list of posts. You can fetch the list of users
// associated with this posts in a single request,
// for instance using a "IN" query in SQL or a multi-fetch
// in your cache back-end.
}
}
The class is PostType but all the type annotations are for Post. Is this a mistake and the types are supposed to match up? Or else what is Post?
Hi, I'm a bit confused by the sample code in the prefetching section of the docs:
The class is PostType but all the type annotations are for Post. Is this a mistake and the types are supposed to match up? Or else what is Post?