Giter VIP home page Giter VIP logo

prisma-nestjs-graphql-filter's Introduction

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)

Before installation

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

Installation

NPM

npm -i prisma-nestjs-graphql-filter

Yarn

yarn add prisma-nestjs-graphql-filter

How to use

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

NOTE: InputType is not necessary

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 {}

NOTE: InputType is not necessary

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 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]
}

Static typing

Because all fields injected with WhereInput 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

prisma-nestjs-graphql-filter's People

Contributors

miltonmejia avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.