Skip to content

Commit

Permalink
feat: filter now allows for OR, AND and NOT
Browse files Browse the repository at this point in the history
feat: filter passes now also raw filter queries

you can now pass anything to filters.
This is usefull for AutocompleteInput and AutocompleteArrayInput's filterToQuery option

as with the previous release it will deal with some simple cases more gracefully,
e.g.

{
    field: "value"
}

will check if the field is a string filter and will use a contain with some muliple cases

but if you do

{
    field: {
        equals: "value
    }
}

it will use this filter as-is
  • Loading branch information
macrozone committed May 1, 2020
1 parent 5caa8c1 commit 2dd6e35
Show file tree
Hide file tree
Showing 10 changed files with 436 additions and 187 deletions.
9 changes: 5 additions & 4 deletions packages/dataprovider/generated/nexus-prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,15 @@ interface NexusPrismaInputs {
ordering: 'id'
}
users: {
filtering: 'id' | 'email' | 'roles' | 'firstName' | 'lastName' | 'gender' | 'yearOfBirth' | 'AND' | 'OR' | 'NOT'
ordering: 'id' | 'email' | 'firstName' | 'lastName' | 'gender' | 'yearOfBirth'
filtering: 'id' | 'email' | 'roles' | 'firstName' | 'lastName' | 'gender' | 'yearOfBirth' | 'wantsNewsletter' | 'AND' | 'OR' | 'NOT'
ordering: 'id' | 'email' | 'firstName' | 'lastName' | 'gender' | 'yearOfBirth' | 'wantsNewsletter'
}

},
UserRole: {
users: {
filtering: 'id' | 'email' | 'roles' | 'firstName' | 'lastName' | 'gender' | 'yearOfBirth' | 'AND' | 'OR' | 'NOT'
ordering: 'id' | 'email' | 'firstName' | 'lastName' | 'gender' | 'yearOfBirth'
filtering: 'id' | 'email' | 'roles' | 'firstName' | 'lastName' | 'gender' | 'yearOfBirth' | 'wantsNewsletter' | 'AND' | 'OR' | 'NOT'
ordering: 'id' | 'email' | 'firstName' | 'lastName' | 'gender' | 'yearOfBirth' | 'wantsNewsletter'
}

}, User: {
Expand Down Expand Up @@ -314,6 +314,7 @@ interface NexusPrismaTypes {
lastName: 'String'
gender: 'Gender'
yearOfBirth: 'Int'
wantsNewsletter: 'Boolean'

}
}
Expand Down
18 changes: 17 additions & 1 deletion packages/dataprovider/generated/nexus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ declare global {
}

export interface NexusGenInputs {
BooleanFilter: { // input type
equals?: boolean | null; // Boolean
not?: boolean | null; // Boolean
}
NullableIntFilter: { // input type
equals?: number | null; // Int
gt?: number | null; // Int
Expand Down Expand Up @@ -75,6 +79,7 @@ export interface NexusGenInputs {
id?: string | null; // String
lastName?: string | null; // String
roles?: NexusGenInputs['UserRoleCreateManyWithoutUsersInput'] | null; // UserRoleCreateManyWithoutUsersInput
wantsNewsletter: boolean; // Boolean!
yearOfBirth?: number | null; // Int
}
UserCreateManyWithoutRolesInput: { // input type
Expand All @@ -87,6 +92,7 @@ export interface NexusGenInputs {
gender?: NexusGenEnums['Gender'] | null; // Gender
id?: string | null; // String
lastName?: string | null; // String
wantsNewsletter: boolean; // Boolean!
yearOfBirth?: number | null; // Int
}
UserFilter: { // input type
Expand All @@ -100,6 +106,7 @@ export interface NexusGenInputs {
gender?: NexusGenEnums['OrderByArg'] | null; // OrderByArg
id?: NexusGenEnums['OrderByArg'] | null; // OrderByArg
lastName?: NexusGenEnums['OrderByArg'] | null; // OrderByArg
wantsNewsletter?: NexusGenEnums['OrderByArg'] | null; // OrderByArg
yearOfBirth?: NexusGenEnums['OrderByArg'] | null; // OrderByArg
}
UserRoleCreateInput: { // input type
Expand Down Expand Up @@ -185,6 +192,7 @@ export interface NexusGenInputs {
NOT?: NexusGenInputs['UserScalarWhereInput'][] | null; // [UserScalarWhereInput!]
OR?: NexusGenInputs['UserScalarWhereInput'][] | null; // [UserScalarWhereInput!]
roles?: NexusGenInputs['UserRoleFilter'] | null; // UserRoleFilter
wantsNewsletter?: NexusGenInputs['BooleanFilter'] | null; // BooleanFilter
yearOfBirth?: NexusGenInputs['NullableIntFilter'] | null; // NullableIntFilter
}
UserUpdateInput: { // input type
Expand All @@ -194,6 +202,7 @@ export interface NexusGenInputs {
id?: string | null; // String
lastName?: string | null; // String
roles?: NexusGenInputs['UserRoleUpdateManyWithoutUsersInput'] | null; // UserRoleUpdateManyWithoutUsersInput
wantsNewsletter?: boolean | null; // Boolean
yearOfBirth?: number | null; // Int
}
UserUpdateManyDataInput: { // input type
Expand All @@ -202,6 +211,7 @@ export interface NexusGenInputs {
gender?: NexusGenEnums['Gender'] | null; // Gender
id?: string | null; // String
lastName?: string | null; // String
wantsNewsletter?: boolean | null; // Boolean
yearOfBirth?: number | null; // Int
}
UserUpdateManyMutationInput: { // input type
Expand All @@ -210,6 +220,7 @@ export interface NexusGenInputs {
gender?: NexusGenEnums['Gender'] | null; // Gender
id?: string | null; // String
lastName?: string | null; // String
wantsNewsletter?: boolean | null; // Boolean
yearOfBirth?: number | null; // Int
}
UserUpdateManyWithWhereNestedInput: { // input type
Expand Down Expand Up @@ -237,6 +248,7 @@ export interface NexusGenInputs {
gender?: NexusGenEnums['Gender'] | null; // Gender
id?: string | null; // String
lastName?: string | null; // String
wantsNewsletter?: boolean | null; // Boolean
yearOfBirth?: number | null; // Int
}
UserUpsertWithWhereUniqueWithoutRolesInput: { // input type
Expand All @@ -254,6 +266,7 @@ export interface NexusGenInputs {
NOT?: NexusGenInputs['UserWhereInput'][] | null; // [UserWhereInput!]
OR?: NexusGenInputs['UserWhereInput'][] | null; // [UserWhereInput!]
roles?: NexusGenInputs['UserRoleFilter'] | null; // UserRoleFilter
wantsNewsletter?: NexusGenInputs['BooleanFilter'] | null; // BooleanFilter
yearOfBirth?: NexusGenInputs['NullableIntFilter'] | null; // NullableIntFilter
}
UserWhereUniqueInput: { // input type
Expand All @@ -280,6 +293,7 @@ export interface NexusGenRootTypes {
id: string; // String!
lastName?: string | null; // String
logs: string[]; // [String!]!
wantsNewsletter: boolean; // Boolean!
yearOfBirth?: number | null; // Int
}
UserRole: { // root type
Expand All @@ -294,6 +308,7 @@ export interface NexusGenRootTypes {
}

export interface NexusGenAllTypes extends NexusGenRootTypes {
BooleanFilter: NexusGenInputs['BooleanFilter'];
NullableIntFilter: NexusGenInputs['NullableIntFilter'];
NullableStringFilter: NexusGenInputs['NullableStringFilter'];
StringFilter: NexusGenInputs['StringFilter'];
Expand Down Expand Up @@ -368,6 +383,7 @@ export interface NexusGenFieldTypes {
lastName: string | null; // String
logs: string[]; // [String!]!
roles: NexusGenRootTypes['UserRole'][]; // [UserRole!]!
wantsNewsletter: boolean; // Boolean!
yearOfBirth: number | null; // Int
}
UserRole: { // field return type
Expand Down Expand Up @@ -471,7 +487,7 @@ export interface NexusGenInheritedFields {}

export type NexusGenObjectNames = "BatchPayload" | "Mutation" | "Query" | "User" | "UserRole";

export type NexusGenInputNames = "NullableIntFilter" | "NullableStringFilter" | "StringFilter" | "UUIDFilter" | "UserCreateInput" | "UserCreateManyWithoutRolesInput" | "UserCreateWithoutRolesInput" | "UserFilter" | "UserOrderByInput" | "UserRoleCreateInput" | "UserRoleCreateManyWithoutUsersInput" | "UserRoleCreateWithoutUsersInput" | "UserRoleFilter" | "UserRoleOrderByInput" | "UserRoleScalarWhereInput" | "UserRoleUpdateInput" | "UserRoleUpdateManyDataInput" | "UserRoleUpdateManyMutationInput" | "UserRoleUpdateManyWithWhereNestedInput" | "UserRoleUpdateManyWithoutUsersInput" | "UserRoleUpdateWithWhereUniqueWithoutUsersInput" | "UserRoleUpdateWithoutUsersDataInput" | "UserRoleUpsertWithWhereUniqueWithoutUsersInput" | "UserRoleWhereInput" | "UserRoleWhereUniqueInput" | "UserScalarWhereInput" | "UserUpdateInput" | "UserUpdateManyDataInput" | "UserUpdateManyMutationInput" | "UserUpdateManyWithWhereNestedInput" | "UserUpdateManyWithoutRolesInput" | "UserUpdateWithWhereUniqueWithoutRolesInput" | "UserUpdateWithoutRolesDataInput" | "UserUpsertWithWhereUniqueWithoutRolesInput" | "UserWhereInput" | "UserWhereUniqueInput";
export type NexusGenInputNames = "BooleanFilter" | "NullableIntFilter" | "NullableStringFilter" | "StringFilter" | "UUIDFilter" | "UserCreateInput" | "UserCreateManyWithoutRolesInput" | "UserCreateWithoutRolesInput" | "UserFilter" | "UserOrderByInput" | "UserRoleCreateInput" | "UserRoleCreateManyWithoutUsersInput" | "UserRoleCreateWithoutUsersInput" | "UserRoleFilter" | "UserRoleOrderByInput" | "UserRoleScalarWhereInput" | "UserRoleUpdateInput" | "UserRoleUpdateManyDataInput" | "UserRoleUpdateManyMutationInput" | "UserRoleUpdateManyWithWhereNestedInput" | "UserRoleUpdateManyWithoutUsersInput" | "UserRoleUpdateWithWhereUniqueWithoutUsersInput" | "UserRoleUpdateWithoutUsersDataInput" | "UserRoleUpsertWithWhereUniqueWithoutUsersInput" | "UserRoleWhereInput" | "UserRoleWhereUniqueInput" | "UserScalarWhereInput" | "UserUpdateInput" | "UserUpdateManyDataInput" | "UserUpdateManyMutationInput" | "UserUpdateManyWithWhereNestedInput" | "UserUpdateManyWithoutRolesInput" | "UserUpdateWithWhereUniqueWithoutRolesInput" | "UserUpdateWithoutRolesDataInput" | "UserUpsertWithWhereUniqueWithoutRolesInput" | "UserWhereInput" | "UserWhereUniqueInput";

export type NexusGenEnumNames = "Gender" | "OrderByArg";

Expand Down
15 changes: 15 additions & 0 deletions packages/dataprovider/generated/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ type BatchPayload {
count: Int!
}

input BooleanFilter {
equals: Boolean
not: Boolean
}

enum Gender {
FEMALE
MALE
Expand Down Expand Up @@ -88,6 +93,7 @@ type User {
lastName: String
logs(from: String!, to: String!): [String!]!
roles(after: UserRoleWhereUniqueInput, before: UserRoleWhereUniqueInput, first: Int, last: Int, skip: Int, where: UserRoleWhereInput): [UserRole!]!
wantsNewsletter: Boolean!
yearOfBirth: Int
}

Expand All @@ -98,6 +104,7 @@ input UserCreateInput {
id: String
lastName: String
roles: UserRoleCreateManyWithoutUsersInput
wantsNewsletter: Boolean!
yearOfBirth: Int
}

Expand All @@ -112,6 +119,7 @@ input UserCreateWithoutRolesInput {
gender: Gender
id: String
lastName: String
wantsNewsletter: Boolean!
yearOfBirth: Int
}

Expand All @@ -127,6 +135,7 @@ input UserOrderByInput {
gender: OrderByArg
id: OrderByArg
lastName: OrderByArg
wantsNewsletter: OrderByArg
yearOfBirth: OrderByArg
}

Expand Down Expand Up @@ -233,6 +242,7 @@ input UserScalarWhereInput {
NOT: [UserScalarWhereInput!]
OR: [UserScalarWhereInput!]
roles: UserRoleFilter
wantsNewsletter: BooleanFilter
yearOfBirth: NullableIntFilter
}

Expand All @@ -243,6 +253,7 @@ input UserUpdateInput {
id: String
lastName: String
roles: UserRoleUpdateManyWithoutUsersInput
wantsNewsletter: Boolean
yearOfBirth: Int
}

Expand All @@ -252,6 +263,7 @@ input UserUpdateManyDataInput {
gender: Gender
id: String
lastName: String
wantsNewsletter: Boolean
yearOfBirth: Int
}

Expand All @@ -261,6 +273,7 @@ input UserUpdateManyMutationInput {
gender: Gender
id: String
lastName: String
wantsNewsletter: Boolean
yearOfBirth: Int
}

Expand All @@ -287,6 +300,7 @@ input UserUpdateWithoutRolesDataInput {
gender: Gender
id: String
lastName: String
wantsNewsletter: Boolean
yearOfBirth: Int
}

Expand All @@ -311,6 +325,7 @@ input UserWhereInput {
NOT: [UserWhereInput!]
OR: [UserWhereInput!]
roles: UserRoleFilter
wantsNewsletter: BooleanFilter
yearOfBirth: NullableIntFilter
}

Expand Down
6 changes: 6 additions & 0 deletions packages/dataprovider/src/buildGqlQuery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ describe("buildGqlQuery", () => {
id
}
gender
wantsNewsletter
}
total: usersCount
}
Expand Down Expand Up @@ -243,6 +244,7 @@ describe("buildGqlQuery", () => {
id
}
gender
wantsNewsletter
}
total: usersCount
}
Expand Down Expand Up @@ -270,6 +272,7 @@ describe("buildGqlQuery", () => {
id
}
gender
wantsNewsletter
}
total: usersCount
}
Expand Down Expand Up @@ -298,6 +301,7 @@ describe("buildGqlQuery", () => {
id
}
gender
wantsNewsletter
}
}
`,
Expand Down Expand Up @@ -327,6 +331,7 @@ describe("buildGqlQuery", () => {
id
}
gender
wantsNewsletter
}
}
`,
Expand All @@ -353,6 +358,7 @@ describe("buildGqlQuery", () => {
id
}
gender
wantsNewsletter
}
}
`,
Expand Down
Loading

0 comments on commit 2dd6e35

Please sign in to comment.