Optional/nullable elements in query result


I’m trying to integrate Prisma with our stack and have just realised that GraphQL API allows null elements as queries’ results. E.g.:

type Query {
  users(where: UserWhereInput, orderBy: UserOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [User]!

I’m trying to wrap my head around it. Why is the type not [User!], are there any possible errors returning with non-empty data?

Are there any non-error cases that might result in nulls within output data (like [X, Y, null, Z])?

What’s the go to approach to keep typescript compiler happy (aside from turning off strict null checks)? If (!error) { const users = data.users as User[]; ... }?


This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.