Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 880
Alan Avatar asked Jan 22 '19 17:01

Alan


People also ask

Does Prisma use GraphQL?

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.

How does Prisma connect to GraphQL?

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.

Does GraphQL return null or undefined?

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.

What is the difference between Prisma and GraphQL?

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.


1 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

like image 145
Matthias Oertel Avatar answered Sep 19 '22 20:09

Matthias Oertel