Hello! I have a schema with `type Offer` that is i...
# random
f
Hello! I have a schema with
type Offer
that is in a one-many relation with
Event
. I try to write a query that gives me all the offers that have no `Event`s and I thought this is an obvious use case, but for the life of me I cannot find a solution other than selecting every
Offer
and filtering on the client. I found this (https://www.prisma.io/forum/t/filtering-out-data-based-on-whether-relations-exists/215), but based on my current prisma knowledge I have no idea what
filter
is, in Playground it is not a valid syntax. How can this be done?
i
Hi there! If you click on the green Schema button on the right (in Playground) you can explore various auto-generated types for your types. In the link you posted they use
PositionFilter
(which will be different on your schema). You can find it there in the Schema explorer and see exactly what fields it would accept. Never did a query like yours, but probably I will have to do it one day, so I'm following this thread 🙂
actually I just managed to do it (I have type
Hotel
linked to
Users
who own it):
Copy code
{
  allHotels(filter:{
    owner: null
  }){
    id, title
    owner {
      id
    }
  }
}
filter{ownernull} did the job for me
and my schema is something like this:
Copy code
type Hotel @model {
  id: ID! @isUnique
  title: String!
...
  owner: User @relation(name: "HotelOwners")
}
doing it the other way around... querying Users that don't own a single hotel... this was tricky, but I think this did the trick:
Copy code
{
  allUsers(filter:{
    hotels_every: {
      id:"-1"
    }
  }){
    id, email,
    hotels{
      id
    }
  }
}
more info here: https://github.com/prisma/prisma/issues/1163 https://github.com/prisma/prisma/issues/110
f
I am SO missing something 😕 What is this
filter:
? For all the types i have a query (e.g. for
type Offer
there is a query
offers
that accepts following parameters
Copy code
where: OfferWhereInput
orderBy: OfferOrderByInput
skip: Int
after: String
before: String
first: Int
last: Int
The
OfferWhereInput
has the usual
id, id_not...
and for the fields and for relations
events_some
,
events_none
and
events_every
. I don’t see any filter anywhere 😕. Actually the “-1” using
events_every
worked well, thanks! And when I was about to continue happily coding I realised I need the exact opposite 🤦 I need every
Offer
that has at least one
Event
, BUT for that
events_some: { id_not: null }
did the trick fast parrot Thanks for your help!
i
about
filter
, I think you can read it here: https://www.graph.cool/docs/reference/graphql-api/query-api-nia9nushae search for "Fetch certain nodes of a specific type"
your query might be
allOffers
, you could check in the green Schema button on the right in the Playground
f
Ok, now I see. You are using Graphcool, I am using Prisma. I never used Graphcool, thats why this
filter
and
allOffers
is not familiar at all. In Prisma it is simply the plural form of the type name (so I guess Graphcool’s
allOffers
is Prisma’s
offers
and
filter
is
where
)
i
hmmmm, yeah, that might be the reason