2.4.1 • Published 5 years ago

@jakelowen/knex-graphql-filters v2.4.1

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

A small helper module to make rich postgres queries from graphql queries.

comes with typedefs StringWhere, BooleanWhere, DateTimeWhere and others.

Use like:

type Query {
  users(input: UsersInput): UsersResults!
}

input UsersInput {
  where: UsersWhere
  limit: Int
  offset: Int
  sort: UserSort
}

input UsersWhere {
  OR: [UsersWhere]
  AND: [UsersWhere]
  id: StringWhere
  name: StringWhere
  email: StringWhere
  active: BooleanWhere
  createdAt: DateTimeWhere
  updatedAt: DateTimeWhere
}

input UserSort {
  id: SortDirection
  name: SortDirection
  email: SortDirection
  createdAt: SortDirection
  updatedAt: SortDirection
}

type UsersResults {
  hasMore: Boolean!
  totalCount: Int!
  items: [User]!
}

enum SortDirection {
  ASC
  DESC
}

comes with Higher order Resolvers to quickly compose resolvers

import { getManyHOR } from "@jakelowen/knex-graphql-filters";

export default async (root, args, context, info) => {
  // "users" is table name.
  return getManyHOR("users")(root, args, context, info);
};

This will automatically enable very reach prisma style queries

query {
  users(
    input: {
      where: {
        OR: [
            { name: { starts_with: "Bil" } },
            { name: { starts_with: "Joe" } }
        ],
        createdAt: { gte: "2019-02-18 12:28:56.399868-06" }
      }
    }
  ) {
    hasMore
    totalCount
    items {
      id
      name
      email
      active
      createdAt
    }
  }
}
2.4.1

5 years ago

2.4.0

5 years ago

2.3.0

5 years ago

2.2.0

5 years ago

2.1.0

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.0.0

5 years ago