I'm trying to write a Query `filterUser`, that giv...
# orm-help
s
I'm trying to write a Query
filterUser
, that given the name of a friend, say alice, returns all users that are friends with alice. to achieve this, I need to be able to filter users based on the name of the friends-relation, but afaics the prisma client currently (?) doesn't allow this. do I need to implement the filter in the resolver myself, or am I missing something here?
h
Can you share your datamodel so that I can help you 🙂
s
my datamodel for this is basically:
Copy code
type User {
  id: ID! @unique
  name: String!
  friends: [User!]!
}
now I'd like to define a query like:
Copy code
type Query {
  usersFriendsWith(name: String!): [User!]!
}
such that given a name, I get every user, that's friends with that user
well,
name
should be
@unique
in this example too, I guess
I'm currently investigating adding another field, in order to have a two-way relation, which should make this possible
h
Yes @unqiue makes field available in
UniqueInput
s
this example is a bit contrived to be honest though. in reality I have a more complicated datamodel that doesn't have self-relations, but the idea should be the same
Copy code
type Bla {
  foos: [Foo!]!
}

type Foo {
  text: String!
}

type Query {
  findBlasWithFooTextContaining(search: String!): [Bla!]!
}
so, in order to define the query, I basically need to add a field
parentBla
to
Foo
, so that I can first filter
foos()
, and then somehow map
parentBla
over the result?