0.0.8 • Published 4 years ago
nexus-plugin-prisma-select v0.0.8
nexus-plugin-prisma-select
Contents
Installation
npm install nexus-plugin-prisma-select
Example Usage
It's a 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
server.ts
import { use } from 'nexus'
import { prismaSelect } from 'nexus-plugin-prisma-select'
use(prismaSelect())
This plugin is take info
and convert it to Prisma select object and add to resolve context
Use
import { schema } from 'nexus'
schema.extendType({
type: 'Query',
definition(t) {
t.field('findOneUser', {
type: 'User',
nullable: true,
args: {
where: schema.arg({
type: 'UserWhereUniqueInput',
nullable: false,
}),
},
resolve(_, { where }, { prisma, select }) {
return prisma.user.findOne({
where,
...select,
})
},
})
},
})
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
}
}
}