prisma-parse-selected-fields
TypeScript icon, indicating that this package has built-in type declarations

1.1.10 • Public • Published

Prisma Parse Selected Fields Build Status

Prisma Parse Selected Fields supports parsing selected fields of AST in GraphQL server and Prisma ORM.

Interfaces:

interface ParseFieldsOptions {
   includeFields: string[]
   excludeFields: string[]
}
interface Options {
   parseFieldsOptions?: ParseFieldsOptions
   graphQLParseFieldsOptions?: GraphQLParseFieldsOptions
}

Functions:

/**
 * @method convertSelectedFields Convert AST object to select object in Prisma.
 * @param selectFields any
 * @returns any
 */
function convertSelectedFields(selectFields: any): any
/**
 * @method deleteFields Delete specified fields in the object
 * @param obj any
 * @param parseFieldsOptions ParseFieldsOptions
 * @returns any
 */
function deleteFields(obj: any, parseFieldsOptions?: ParseFieldsOptions): any
/**
 * @method parseSelectedFields Convert AST of info object to select object in Prisma.
 * @param info GraphQLResolveInfo
 * @param options Options | undefined
 * @returns any
 */
function parseSelectedFields(info: GraphQLResolveInfo, options?: Options): any

Example:

// ES6
...
import { GraphQLResolveInfo as Info } from 'graphql'
import { parseSelectedFields } from "prisma-parse-selected-fields";

async function resolver(root: any, args: any, { prisma }: any, info: Info): Promise<prisma.User> {
   const select = parseSelectedFields(info)

   return await prisma.user.findMany({
      ....
      where: {...},
      select: select,
      ...
   })
}

Package Sidebar

Install

npm i prisma-parse-selected-fields

Weekly Downloads

1

Version

1.1.10

License

MIT

Unpacked Size

41.6 kB

Total Files

49

Last publish

Collaborators

  • nqnghia285