Skip to content

Commit

Permalink
Remove filters export from @keystone-6/core/types (#7919)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmatown committed Sep 27, 2022
1 parent 2a7bc60 commit 51ab286
Show file tree
Hide file tree
Showing 24 changed files with 24 additions and 224 deletions.
5 changes: 5 additions & 0 deletions .changeset/silent-dolphins-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-6/core': major
---

Removes `filters` export from `@keystone-6/core/types`
8 changes: 0 additions & 8 deletions docs/pages/docs/guides/custom-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {
CommonFieldConfig,
fieldType,
orderDirectionEnum,
filters,
} from '@keystone-6/core/types';
import { graphql } from '@keystone-6/core';

Expand All @@ -53,7 +52,6 @@ export const myInt =
})({
...config,
input: {
where: { arg: graphql.arg({ type: filters[meta.provider].Int.optional }), resolve: filters.resolveCommon },
create: { arg: graphql.arg({ type: graphql.Int }) },
update: { arg: graphql.arg({ type: graphql.Int }) },
orderBy: { arg: graphql.arg({ type: orderDirectionEnum }) },
Expand All @@ -74,7 +72,6 @@ The `input` object defines the GraphQL inputs for the field type.

```ts
input: {
where: { arg: graphql.arg({ type: filters[meta.provider].Int.optional }), resolve: filters.resolveCommon },
create: { arg: graphql.arg({ type: graphql.Int }) },
update: { arg: graphql.arg({ type: graphql.Int }) },
orderBy: { arg: graphql.arg({ type: orderDirectionEnum }) },
Expand All @@ -85,7 +82,6 @@ You can also provide resolvers to transform the value coming from GraphQL into t

```ts
input: {
where: { arg: graphql.arg({ type: filters[meta.provider].Int.optional }), resolve: filters.resolveCommon },
create: { arg: graphql.arg({ type: graphql.Int }), resolve: (val, context) => val },
update: { arg: graphql.arg({ type: graphql.Int }), resolve: (val, context) => val },
orderBy: { arg: graphql.arg({ type: orderDirectionEnum }), resolve: (val, context) => val },
Expand Down Expand Up @@ -139,10 +135,6 @@ export const controller = (config: FieldControllerConfig): FieldController<strin
return typeof value === 'number' ? value + '' : '';
},
serialize: value => ({ [config.path]: value === '' ? null : parseInt(value, 10) }),
filter: {
// the filters section is omitted for brevity
// see what this looks like for the integer field at https://github.com/keystonejs/keystone/blob/e0d1b2068de2ea3b6770c58af91221b01e6a20cf/packages-next/fields/src/types/integer/views/index.tsx#L60-L128
}
};
};
```
Expand Down
5 changes: 0 additions & 5 deletions examples/custom-field/1-text-field/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
FieldTypeFunc,
CommonFieldConfig,
orderDirectionEnum,
filters,
} from '@keystone-6/core/types';
import { graphql } from '@keystone-6/core';

Expand All @@ -26,10 +25,6 @@ export function text<ListTypeInfo extends BaseListTypeInfo>({
})({
...config,
input: {
where: {
arg: graphql.arg({ type: filters[meta.provider].String.optional }),
resolve: filters.resolveCommon,
},
create: {
arg: graphql.arg({ type: graphql.String }),
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down
69 changes: 0 additions & 69 deletions examples/custom-field/1-text-field/views.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,74 +61,5 @@ export const controller = (
return typeof value === 'string' ? value : null;
},
serialize: value => ({ [config.path]: value }),
filter: {
Filter(props) {
return (
<TextInput
type="text"
onChange={event => {
props.onChange(event.target.value);
}}
value={props.value}
autoFocus={props.autoFocus}
/>
);
},

graphql: ({ type, value }) => {
const key = type === 'is' ? config.path : `${config.path}_${type}`;
const valueWithoutWhitespace = value.replace(/\s/g, '');

return {
[key]: ['in', 'not_in'].includes(type)
? valueWithoutWhitespace.split(',').map(i => parseInt(i))
: parseInt(valueWithoutWhitespace),
};
},
Label({ label, value, type }) {
let renderedValue = value;
if (['in', 'not_in'].includes(type)) {
renderedValue = value
.split(',')
.map(value => value.trim())
.join(', ');
}
return `${label.toLowerCase()}: ${renderedValue}`;
},
types: {
is: {
label: 'Is exactly',
initialValue: '',
},
not: {
label: 'Is not exactly',
initialValue: '',
},
gt: {
label: 'Is greater than',
initialValue: '',
},
lt: {
label: 'Is less than',
initialValue: '',
},
gte: {
label: 'Is greater than or equal to',
initialValue: '',
},
lte: {
label: 'Is less than or equal to',
initialValue: '',
},
in: {
label: 'Is one of',
initialValue: '',
},
not_in: {
label: 'Is not one of',
initialValue: '',
},
},
},
};
};
5 changes: 0 additions & 5 deletions examples/custom-field/2-stars-field/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
FieldTypeFunc,
CommonFieldConfig,
orderDirectionEnum,
filters,
} from '@keystone-6/core/types';
import { graphql } from '@keystone-6/core';

Expand Down Expand Up @@ -49,10 +48,6 @@ export const stars =
},
// all of these inputs are optional if they don't make sense for a particular field type
input: {
where: {
arg: graphql.arg({ type: filters[meta.provider].Int.optional }),
resolve: filters.resolveCommon,
},
create: {
arg: graphql.arg({ type: graphql.Int }),
// this field type doesn't need to do anything special
Expand Down
71 changes: 1 addition & 70 deletions examples/custom-field/2-stars-field/views.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { FieldContainer, FieldDescription, FieldLabel, TextInput } from '@keystone-ui/fields';
import { FieldContainer, FieldDescription, FieldLabel } from '@keystone-ui/fields';
import { CellLink, CellContainer } from '@keystone-6/core/admin-ui/components';

import {
Expand Down Expand Up @@ -57,74 +57,5 @@ export const controller = (
return typeof value === 'number' ? value : null;
},
serialize: value => ({ [config.path]: value }),
filter: {
Filter(props) {
return (
<TextInput
type="number"
onChange={event => {
props.onChange(event.target.value.replace(/[^\d,\s-]/g, ''));
}}
value={props.value}
autoFocus={props.autoFocus}
/>
);
},

graphql: ({ type, value }) => {
const key = type === 'is' ? config.path : `${config.path}_${type}`;
const valueWithoutWhitespace = value.replace(/\s/g, '');

return {
[key]: ['in', 'not_in'].includes(type)
? valueWithoutWhitespace.split(',').map(i => parseInt(i))
: parseInt(valueWithoutWhitespace),
};
},
Label({ label, value, type }) {
let renderedValue = value;
if (['in', 'not_in'].includes(type)) {
renderedValue = value
.split(',')
.map(value => value.trim())
.join(', ');
}
return `${label.toLowerCase()}: ${renderedValue}`;
},
types: {
is: {
label: 'Is exactly',
initialValue: '',
},
not: {
label: 'Is not exactly',
initialValue: '',
},
gt: {
label: 'Is greater than',
initialValue: '',
},
lt: {
label: 'Is less than',
initialValue: '',
},
gte: {
label: 'Is greater than or equal to',
initialValue: '',
},
lte: {
label: 'Is less than or equal to',
initialValue: '',
},
in: {
label: 'Is one of',
initialValue: '',
},
not_in: {
label: 'Is not one of',
initialValue: '',
},
},
},
};
};
41 changes: 0 additions & 41 deletions examples/custom-field/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ input PostWhereInput {
OR: [PostWhereInput!]
NOT: [PostWhereInput!]
id: IDFilter
content: StringNullableFilter
rating: IntNullableFilter
pair: PairFilter
}

Expand All @@ -33,45 +31,6 @@ input IDFilter {
not: IDFilter
}

input StringNullableFilter {
equals: String
in: [String!]
notIn: [String!]
lt: String
lte: String
gt: String
gte: String
contains: String
startsWith: String
endsWith: String
not: NestedStringNullableFilter
}

input NestedStringNullableFilter {
equals: String
in: [String!]
notIn: [String!]
lt: String
lte: String
gt: String
gte: String
contains: String
startsWith: String
endsWith: String
not: NestedStringNullableFilter
}

input IntNullableFilter {
equals: Int
in: [Int!]
notIn: [Int!]
lt: Int
lte: Int
gt: Int
gte: Int
not: IntNullableFilter
}

input PairFilter {
equals: String
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { graphql } from '../schema';
import { graphql } from '../../types/schema';

// yes, these two types have the fields but they're semantically different types
// (even though, yes, having EnumFilter by defined as EnumNullableFilter<Enum>, would be the same type but names would show up differently in editors for example)
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/fields/filters/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * as filters from './internal';
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Do not manually modify this file, it is automatically generated by the package at /prisma-utils in this repo.
// Update the script if you need this file to be different

import { graphql } from '../../schema';
import { graphql } from '../../../types/schema';

type StringNullableFilterType = graphql.InputObjectType<{
// can be null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Do not manually modify this file, it is automatically generated by the package at /prisma-utils in this repo.
// Update the script if you need this file to be different

import { graphql } from '../../schema';
import { graphql } from '../../../types/schema';

import { QueryMode } from '../../next-fields';
import { QueryMode } from '../../../types/next-fields';

type StringNullableFilterType = graphql.InputObjectType<{
// can be null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Do not manually modify this file, it is automatically generated by the package at /prisma-utils in this repo.
// Update the script if you need this file to be different

import { graphql } from '../../schema';
import { graphql } from '../../../types/schema';

type StringNullableFilterType = graphql.InputObjectType<{
// can be null
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/fields/types/bigInt/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import {
FieldTypeFunc,
CommonFieldConfig,
orderDirectionEnum,
filters,
} from '../../../types';
import { graphql } from '../../..';
import {
assertCreateIsNonNullAllowed,
assertReadIsNonNullAllowed,
getResolvedIsNullable,
} from '../../non-null-graphql';
import { filters } from '../../filters';

export type BigIntFieldConfig<ListTypeInfo extends BaseListTypeInfo> =
CommonFieldConfig<ListTypeInfo> & {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/fields/types/calendarDay/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import {
FieldTypeFunc,
CommonFieldConfig,
orderDirectionEnum,
filters,
} from '../../../types';
import { graphql } from '../../..';
import {
assertCreateIsNonNullAllowed,
assertReadIsNonNullAllowed,
getResolvedIsNullable,
} from '../../non-null-graphql';
import { filters } from '../../filters';
import { CalendarDayFieldMeta } from './views';

export type CalendarDayFieldConfig<ListTypeInfo extends BaseListTypeInfo> =
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/fields/types/checkbox/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import {
fieldType,
FieldTypeFunc,
orderDirectionEnum,
filters,
} from '../../../types';
import { graphql } from '../../..';
import { assertCreateIsNonNullAllowed, assertReadIsNonNullAllowed } from '../../non-null-graphql';
import { filters } from '../../filters';

export type CheckboxFieldConfig<ListTypeInfo extends BaseListTypeInfo> =
CommonFieldConfig<ListTypeInfo> & {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/fields/types/decimal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
CommonFieldConfig,
orderDirectionEnum,
Decimal,
filters,
FieldData,
} from '../../../types';
import { graphql } from '../../..';
Expand All @@ -15,6 +14,7 @@ import {
assertReadIsNonNullAllowed,
getResolvedIsNullable,
} from '../../non-null-graphql';
import { filters } from '../../filters';

export type DecimalFieldConfig<ListTypeInfo extends BaseListTypeInfo> =
CommonFieldConfig<ListTypeInfo> & {
Expand Down
Loading

1 comment on commit 51ab286

@vercel
Copy link

@vercel vercel bot commented on 51ab286 Sep 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.