0.0.3 • Published 4 years ago
prisma-select v0.0.3
Prisma select
It's small tool to convert info: GraphQLResolveInfo
to select object accepted by prisma client
this will give you the best performance because you will just query exactly what you want
npm i prisma-select
Example
import getPrismaSelect from 'prisma-select';
// nexus
t.field('findOneUser', {
type: 'User',
nullable: true,
args: {
where: arg({
type: 'UserWhereUniqueInput',
nullable: false,
}),
},
resolve(_parent, { where }, { prisma }, info) {
return prisma.user.findOne({
where,
...getPrismaSelect(info),
});
},
});
// normal resolver
const resolvers = {
Query: {
user(_parent, { where }, { prisma }, info) {
return prisma.user.findOne({
where,
...getPrismaSelect(info),
});
},
},
};
Example query
query {
findOneUser(where: { id: 1 }) {
id
email
name
posts(
where: { title: { contains: "a" } }
orderBy: { createdAt: asc }
first: 10
skip: 5
) {
id
title
comments(where: { contain: { contains: "a" } }) {
id
contain
}
}
}
}
convert to
{
select: {
id: true,
email: true,
name: true,
posts: {
select: {
id: true,
title: true,
comments: {
select: { id: true, contain: true },
where: { contain: { contains: 'a' } }
}
},
where: { title: { contains: 'a' } },
orderBy: { createdAt: 'asc' },
first: 10,
skip: 5
}
}
}