Where clause on query of a mutation

prisma

#1

Getting into Prisma and like the separation, but I now have a requirement that I am not sure how to fix (if possible)

Say I have the following (yoga) API Schema (only showing relevant things)

type Mutation {
  login(email: String!, password: String!): AuthPayload!
}

type AuthPayload {
  token: String!
  user: User!
}

type User {
  id: ID!
  email: String!
  name: String!
  events: [Event!]!,
}

type Event {
  id: ID!
  name: String!,
  deleted: Boolean
}

I want to filter out deleted events when using a query within the login mutation without needing to specify the filter or where clause (which does not exist in the API Schema, only on the prisma schema)

mutation {
   login(email: "email@email", password: "password") {
      id,
      events {     <- do not want deleted events
        id, name
     }
  }
}

If I create a query resolver I can have that resolver return the non-deleted events, but the query result from a mutation does not go through the API schema query resolvers, just straight to the prisma DB schema.

Thanks


#2

I understand you want to be efficient. If I prefer to separate login from the fetching of data. That way you can keep you auth and business logic in different components.

Having said that you could pass a filter on events but you would have to handle it in your resolver.

mutation {
   login(email: "email@email", password: "password") {
      id,
      events  (filter: { deleted: false }) { 
        id, name
     }
  }
}

#3

Hey @Lance, we had a similar conversation in one of the other threads. I think that you’ll find the best answers there - feel free to continue the thread with any questions you find relevant!

Hope it helps you :slightly_smiling_face: