import type { QueryResolvers, IdentityRelationResolvers } from 'types/graphql'

import { db } from 'src/lib/db'

export const identities: QueryResolvers['identities'] = () => {
  return db.identity.findMany()
}

export const identity: QueryResolvers['identity'] = ({ id }) => {
  return db.identity.findUnique({
    where: { id },
  })
}

export const Identity: IdentityRelationResolvers = {
  user: (_obj, { root }) => {
    return db.identity.findUnique({ where: { id: root?.id } }).user()
  },
}
