Hi! Is it possible to filter a nested field on an ...
# prisma-whats-new
b
Hi! Is it possible to filter a nested field on an authenticated query, (i.e., based on that user’s ID)? For example, I have an authenticated query `userQuery.js`:
Copy code
export const CURRENT_USER_QUERY = gql`
  query currentUserQuery {
    user {
      ...UserFragment,
    }
  }
  ${USER_FRAGMENT}
`;
And here is the
USER_FRAGMENT
portion:
Copy code
const USER_FRAGMENT = gql`
  fragment UserFragment on User {
    id
    username
    friends {
      id
      username
      chatGroups(filter: { users_some: { id: *_[CURRENT USER QUERY ID]_* }}) {
        id
        users {
          id
          username
        }
      }
    }
  }
`;

export default USER_FRAGMENT;
Since a
friend
can belong to many chat groups I only want to return the chat groups that contain the current user as well as the friend (using the
users_some
filter). I don’t want to have to pass a userId variable to the query since it’s authenticated. Is this possible? Thanks in advance!
m
You can achieve this by using GraphQL Server. Check out the basic example here: http://github.com/graphcool/graphql-server-example
b
@matic My project is using the legacy console. Is it possible without having to migrate my project?
m
You can store your
userId
on the client side and include it in the queries, but that’s just as far as it gets right now, hope it helps you in any way 🙂
b
@nilan, any advice/suggestions? Since it's an authenticated (
user
) query, I don't pass any parameters into the query itself, so looking for a way to dynamically use the authenticated user's id to filter on the subfield
chatGroups
. Or must I upgrade from the legacy console and construct my own resolver? Thanks!