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?

4

2 Answers

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

this works, but I guess it is just a hack..

query TrackUsersQuery($orderBy: TrackUserOrderByInput!, $where: TrackUserWhereInput, $first: Int, $skip: Int) { trackUsers(where: $where, orderBy: $orderBy, first: $first, skip: $skip) { id createdAt user { id name } } } variables = { where: { user: { name_contains: '' } } } 

UPDATE:

For Prisma2, here you have the possibilities:

For products that have no invoice, you can use the following:

const data = await prisma.product.findMany({ where: { invoices: { none: { id: undefined, }, }, }, }) 

And for Invoices that do not have a product associated:

const data = await prisma.invoice.findMany({ where: { productId: null, }, }) 

more details here:

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like