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?
Prisma is an ORM that is used inside of GraphQL resolvers to query a database. It works perfectly with all your favorite tools and libraries from the GraphQL ecosystem. You can use it with SDL-first and code-first GraphQL schemas and with any server library such as Apollo Server, Express, NestJS or Mercurius.
Connect the Prisma client to the GraphQL server js file: const { PrismaClient } = require('@prisma/client'); Create an instance of PrismaClient and pass it to the GraphQL server constructor through the context key. The context key contains custom data being passed through your resolver chain.
In JavaScript functions without an explicit return statement implicitly return undefined . So our function creates a Promise and then immediately returns undefined , causing GraphQL to return null for the field.
GraphQL is a data query language and runtime designed and used at Facebook to request and deliver data to mobile and web apps since 2012. What is Prisma? Prisma makes working with databases easy. Prisma is a powerful database tool used for data access, migrations and visual data management.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With