0.4.5 • Published 5 years ago

@jakelowen/sqorn-graphql-filters v0.4.5

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

A small helper module to make rich postgres queries from graphql queries using Sqorn

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/sqorn-graphql-filters";

export default async (root, args, context, info) => {
  const dbHandle = sq.from("users)
  return getManyHOR(dbHandle)(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
    }
  }
}
0.4.5

5 years ago

0.4.4

5 years ago

0.4.3

5 years ago

0.4.2

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago