# graphql-prisma-select-fields

> Helper library to convert GraphQL document fields to Prisma's select argument

Latest version **1.0.1** (published 2022-06-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install graphql-prisma-select-fields
pnpm add graphql-prisma-select-fields
yarn add graphql-prisma-select-fields
bun add graphql-prisma-select-fields
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2022-06-20 |
| First published | 2022-06-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Fatih Kilic |
| Maintainers | fklc |

## Links

- npm: https://www.npmjs.com/package/graphql-prisma-select-fields
- npm.io page: https://npm.io/package/graphql-prisma-select-fields

## Dependencies (1)

- [graphql](https://npm.io/package/graphql.md) ^16.5.0

## Recent versions

- 1.0.1 (latest) — 2022-06-20

## 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.

---
_Source: https://npm.io/package/graphql-prisma-select-fields · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
