Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prisma get data based on computed field

I need to get data depends on computed field For example

const resolvers = {
  Query: {
    users: (parent, args, ctx, info) => {
      const fragment = `fragment EnsureFullName on User { firstName lastName }`
      return ctx.db.query.users({}, addFragmentToInfo(info, fragment))
    },
  },
  User: {
    fullName: parent => `${parent.firstName} ${parent.lastName}`,
  },
}

I need to get all data where fullname = 'any value',

How can I do that ?

like image 284
Ghyath Darwish Avatar asked Nov 15 '22 18:11

Ghyath Darwish


1 Answers

You need to filter manually after fetching from the database or use use a where condition to check if firstName and lastName:

const users = await prisma.users({ where: { firstName: 'any', lastName: 'value' } });
like image 157
realAlexBarge Avatar answered Dec 06 '22 17:12

realAlexBarge