Hey!
Say I have many Users
, and each User
has many Posts
.
The schema is as follows:
type User {
name: String!
posts: [Post!] @relation
...
}
input UserFilterInput {
name: String
}
enum PostType {
TEXT
IMAGE
}
type Post {
type: PostType!
author: User! @relation
...
}
input PostFilterInput {
type: PostType
}
type Query {
findUsersCustom(filter: UserFilterInput!): [User!] @resolver(name: "findUsersCustom", paginated: true)
findPostsCustom(filter: PostFilterInput!): [Post!] @resolver(name: "findPostsCustom", paginated: true)
}
Now, with my custom UDF findPostsCustom
, I can query posts filtered by type like so:
query FindPostsCustom($filters: PostFilterInput!, $size: Int!, $cursor: String) {
findPostsCustom(filters: $filters, _size: $size, _cursor: $cursor) {
...
}
}
This is great, however, what I would really like to do, is apply the same UDF as a resolver for posts in the findUsersCustom
query – which would allow me to do something like so:
query FindUsersCustom($userFilters: UserFilterInput!, $userSize: Int!, $userCursor: String, $postFilters: PostFilterInput!, $postSize: Int!, $postCursor: String) {
findUsersCustom(filters: $userFilters, _size: $userSize, _cursor: $userCursor) {
after
data {
posts (filters: $postFilters, _size: $postSize, _cursor: $postCursor) {
...
}
}
}
}
Is this possible at all?
If this isn’t possible, what’s the best way to achieve this?
Is the only option to simply seperate the queries like so?
(1) Fetch filtered users
(2) Then, for each user, fetch filtered posts
Thanks!
** Update **
After reading this post, looks as though the feature I’m after is being considered, but not yet implemented