https://github.com/fklc/graphql-prisma-select-fields
Helper library to convert GraphQL document fields to Prisma's select argument
https://github.com/fklc/graphql-prisma-select-fields
Last synced: 25 days ago
JSON representation
Helper library to convert GraphQL document fields to Prisma's select argument
- Host: GitHub
- URL: https://github.com/fklc/graphql-prisma-select-fields
- Owner: FKLC
- License: mit
- Created: 2022-06-19T02:55:05.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-06-19T02:59:22.000Z (about 4 years ago)
- Last Synced: 2025-02-27T00:27:07.516Z (over 1 year ago)
- Language: JavaScript
- Size: 1000 Bytes
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# graphql-prisma-select-fields
This is a small helper library that helps you not over-fetch while using GraphQL with Prisma.
### Example
```js
import gqlSelectConverter from 'graphql-prisma-select-fields'
const app = fastify()
app.register(mercurius, {
...,
})
app.ready().then(() => {
app.graphql.addHook('preExecution', async (schema, document, context) => {
context['selectFields'] = gqlSelectConverter(document)
...
})
})
// Models
export const ModelQuery = extendType({
type: 'Query',
definition(t) {
t.nonNull.list.field('models', {
type: Model,
resolve(source, args, ctx) {
return ctx.prisma.account.findMany(ctx.selectFields.Model)
}
})
},
})
```
Note that this is a really small library. You can customize it as you wish to fit to your codebase.