type-graphql-query
TypeScript icon, indicating that this package has built-in type declarations

0.5.8 • Public • Published

type-graphql-query

Powerful filter decorator supporting and/or operations for type-graphql.

Usage

For fields that support filter, use @FilterableField instead of @Field.

import { ObjectType, Int } from "type-graphql";
import { FilterableField } from "type-graphql-query";

@ObjectType("Example")
export class ExampleModel {

  @FilterableField()
  myField: string;

  @FilterableField(type => Int)
  numberField: number;

  @FilterableField()
  dateField: Date;
}

Then in resolver, use @FilterArg.

import { Resolver, Query } from "type-graphql";
import { FilterArg } from "type-graphql-query";
import { ExampleModel } from "./models";

@Resolver()
export class ExamplesResolver {
  @Query(returns => String)
  exampleQuery(
    @FilterArg(ExampleModel) filter: any,
  ) {
    // perform operation based on filter argument
    return "hello"
  }
}

A recursive filter would be generated in GraphQL schema. Only a few of comparisons are shown here. The comparison operations are borrowed from nestjs-query. Please refer to nestjs-query doc for a full list of comparison.

input ExampleFilter {
  myField: StringFieldComparison
  numberField: IntFieldComparison
  dateField: DateFieldComparison
  and: [ExampleFilter!]!
  or: [ExampleFilter!]!
}

input StringFieldComparison {
  eq: String
  in: [String!]
  like: String
  notIn: [String!]
  notLike: String
}

type Query {
  exampleQuery(filter: ExampleFilter!): String!
}

Readme

Keywords

none

Package Sidebar

Install

npm i type-graphql-query

Weekly Downloads

1

Version

0.5.8

License

Apache-2.0

Unpacked Size

311 kB

Total Files

238

Last publish

Collaborators

  • kmbilly