npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

prisma-nestjs-graphql-filter

v1.3.3

Published

This package helps you to reduce boilerplate if you want to create Prisma filter input in Graphql

Downloads

191

Readme

Prisma nestjs graphql filter

This package helps you to reduce boilerplate if you want to create Prisma filter input in Graphql. WhereInput decorator accepts an array of arguments, so you can add all fields with any type as you need.

This package is compatible with all Graphql input types and all classes with InputType decorator. Also you can declare your field input type as array (check the examples below).

Is not necessary add native Input decorator when you use WhereInput or OrderByInput decorators.

Before installation

You must install class-transformer package before install if you want to use DecimalFilter

Circular dependency

WhereInput and OrderByInput may not work when you nest with each other, due to circular dependency issues. You can use those decorators if you add nested fields with Field decorator inside class.

Installation

NPM

npm -i prisma-nestjs-graphql-filter

Yarn

yarn add prisma-nestjs-graphql-filter

How to use WhereInput

@WhereInput({ type: String, fields: ['hello', 'world'] })
class ExampleInput {}

Graphql SDL result

input ExampleInput {
  hello: String
  world: String
  AND: [ExampleInput]
  OR: [ExampleInput]
  NOT: [ExampleInput]
}

How to use with relation list

@WhereInput({ type: ListRelationInput(OtherClass), fields: ['relationField'] })
class ExampleInput {}

Graphql SDL result

input ExampleInput {
  relationField: OtherClassListRelationWhereInput
  AND: [ExampleInput]
  OR: [ExampleInput]
  NOT: [ExampleInput]
}

input OtherClassListRelationWhereInput {
  every: OtherClass
  some: OtherClass
  none: OtherClass
}

NOTE: This decorator always concat word 'ListRelationWhereInput' to class name and delete words: 'Input' and 'Where' if those are present in original input name.

Field type as array

@WhereInput(
	{ type: [String], fields: ['hello', 'world'] },
	{ type: [ListRelationInput(OtherInputClass)], fields: ['relationArray'] }
)
class ExampleInputArray {}

Graphql SDL result

input ExampleInputArray {
  hello: [String]
  world: [String]
  relationField: [StringListRelationWhereInput]
}

How to use OrderByInput

@OrderByInput({ type: SortOrder, fields: ['hello', 'world'] })
class ExampleInput {}

Graphql SDL result

input ExampleInput {
  hello: SortOrder //asc | desc
  world: SortOrder //asc | desc
}

How to add nested fields

@OrderByInput({ type: SortOrder, fields: ['hello'] })
class NestedOrderBy {}

@OrderByInput({ type: NestedOrderBy, fields: ['nestedField'] })
class ExampleInput {}

Graphql SDL result

input ExampleInput {
  nestedField: NestedOrderBy
}

input NestedOrderBy {
  hello: SortOrder
}

Static typing

Because all fields injected with WhereInput or OrderByInput are not declared by the decorator explicitly, Typescript can't recognizes the class fields. To avoid this and helps IDE to hinting, you can extend CastToAbstract with prisma where type.

For example:

class ExampleInputArray extends CastToAbstract<Prisma.HelloWorldWhereInput>() {}

Prisma filters and extra types

There are many prisma filter types and extra types availables that you can use as:

  • AffectedRows
  • BoolFilter
  • BoolWithAggregatesFilter
  • DateTimeFilter
  • DateTimeWithAggregatesFilter
  • DecimalFilter
  • DecimalWithAggregatesFilter
  • FloatFilter
  • FloatWithAggregatesFilter
  • IntFilter
  • IntWithAggregatesFilter
  • QueryMode
  • SortOrder
  • StringFilter
  • StringWithAggregatesFilter
  • TransactionIsolationLevel