Search code examples
graphqlapolloprisma

Querying NOT NULL GraphQL with Prisma


Schema:

type TrackUser {
  id: ID! @unique
  createdAt: DateTime!
  user: User #note there is no `!`
}
type User {
  id: ID! @unique
  name: String! @unique
}

I want to get Alls TrackUser where User is not null. What would be the query?


Solution

  • This would be a possible query:

    query c {
      trackUsers(where: { NOT: [{ user: null }] }) {
        name
      }
    }
    

    Here you can see how it looks in the Playground. I added a name to Trackuser in the datamodel in order to be able to create it from that side without a user.

    enter image description here