Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add isFilterable and isOrderable config options #6416

Merged
merged 4 commits into from
Aug 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions docs/pages/docs/apis/fields.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ All options are optional.

Options:

- `isFilterable` (default: `false`): If `true`, the GraphQL API and Admin UI will support filtering by this field.
- `isOrderable` (default: `false`): If `true`, the GraphQL API and Admin UI will support ordering by this field.
- `access`: Defines the [Access Control](../guides/access-control) rules for the field.
See the [Access Control API](./access-control) for full details on the available access control options.
- `hooks`: The `hooks` option defines [hook](../guides/hooks) functions for the field.
Expand All @@ -89,15 +91,15 @@ Options:
- `read` (default: `true`): If `true`, this field will exist on the lists output type.
- `create` (default: `true`): If `true`, this field will exist on the input type for create operations.
- `update` (default: `true`): If `true`, this field will exist on the input type for update operations.
- `filter` (default: `false`): If `true`, this field will exist on the `WhereInput` type used for filtering.
- `orderBy` (default: `false`): If `true`, this field will exist on the `OrderBy` type used for ordering queries.

```typescript
export default config({
lists: createSchema({
ListName: list({
fields: {
fieldName: text({
isFilterable: true,
isOrderable: true,
access: { /* ... */ },
hooks: { /* ... */ },
label: '...',
Expand All @@ -119,8 +121,7 @@ export default config({
read: true,
create: true,
update: true,
filter: false,
orderBy: false,

},
}
}),
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/docs/apis/filters.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Each field type provides its own set of filters which can be used with [queries]
This page lists all the filters available for each field type.
For more details on how to use filters in queries please consult to the [GraphQL Queries - Filters](../guides/filters) guide.

?> Filters are disabled by default as a security precaution. To enable the filters on a field, set the config option `{ graphql: { isEnabled: { filter: true } } }`.
?> Filters are disabled by default as a security precaution. To enable the filters on a field, set the config option `{ isFilterable: true }`.

## Scalar types

Expand Down
2 changes: 1 addition & 1 deletion docs/pages/docs/apis/graphql.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { text } from '@keystone-next/keystone/fields';

export default config({
lists: createSchema({
User: list({ fields: { name: text({ graphql: { isEnabled: { filter: true, orderBy: true }}}) } }),
User: list({ fields: { name: text({ isOrderable: true }) } }),
}),
/* ... */
});
Expand Down
7 changes: 7 additions & 0 deletions docs/pages/docs/apis/schema.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export default config({
graphql: { /* ... */ },
db: { /* ... */ },
description: '...',
defaultIsFilterable: true,
defaultIsOrderable: true,
}),
/* ... */
}),
Expand All @@ -30,6 +32,11 @@ export default config({

This document will explain the configuration options which can be used with the `list()` function.

Options:

- `defaultIsFilterable`: If `true`, all fields will be filterable by default. They can override this by setting the field level `isFilterable` option to `false`.
- `defaultIsOrderable`: If `true`, all fields will be orderable by default. They can override this by setting the field level `isOrderable` option to `false`.

## fields

The `fields` option defines the names, types, and configuration of the fields in the list.
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/docs/guides/filters.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This guide will show you how to use filters to get data you need.

!> The filter references in this guide are based on the schema defined in the [Task Manager](https://github.com/keystonejs/keystone/tree/master/examples/task-manager) example project.

?> Filters are disabled by default as a security precaution. To enable the filters on a field, set the config option `{ graphql: { isEnabled: { filter: true } } }`.
?> Filters are disabled by default as a security precaution. To enable the filters on a field, set the config option `{ isFilterable: true }`.

## Scalar Filters

Expand Down
6 changes: 1 addition & 5 deletions examples-staging/auth/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ export const lists = createSchema({
// The user's name
name: text({ isRequired: true }),
// The user's email address, used as the identity field for auth
email: text({
isRequired: true,
isUnique: true,
graphql: { isEnabled: { filter: true } },
}),
email: text({ isRequired: true, isUnique: true, isFilterable: true }),
// The user's password, used as the secret field for auth
password: password({
access: {
Expand Down
2 changes: 1 addition & 1 deletion examples-staging/basic/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const lists = createSchema({
/** The user's first and last name. */
name: text({ isRequired: true }),
/** Email is used to log into the system. */
email: text({ isRequired: true, isUnique: true, graphql: { isEnabled: { filter: true } } }),
email: text({ isRequired: true, isUnique: true, isFilterable: true }),
/** Avatar upload for the users profile, stored locally */
avatar: image(),
attachment: file(),
Expand Down
4 changes: 2 additions & 2 deletions examples-staging/ecommerce/schemas/CartItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const CartItem = list({
defaultValue: 1,
isRequired: true,
}),
product: relationship({ ref: 'Product', graphql: { isEnabled: { filter: true } } }),
user: relationship({ ref: 'User.cart', graphql: { isEnabled: { filter: true } } }),
product: relationship({ ref: 'Product', isFilterable: true }),
user: relationship({ ref: 'User.cart', isFilterable: true }),
},
});
2 changes: 1 addition & 1 deletion examples-staging/ecommerce/schemas/OrderItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const OrderItem = list({
delete: () => false,
},
fields: {
name: text({ isRequired: true, graphql: { isEnabled: { orderBy: true } } }),
name: text({ isRequired: true, isOrderable: true }),
description: text({
ui: {
displayMode: 'textarea',
Expand Down
2 changes: 1 addition & 1 deletion examples-staging/ecommerce/schemas/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const User = list({
},
fields: {
name: text({ isRequired: true }),
email: text({ isRequired: true, isUnique: true, graphql: { isEnabled: { filter: true } } }),
email: text({ isRequired: true, isUnique: true, isFilterable: true }),
password: password(),
cart: relationship({
ref: 'CartItem.user',
Expand Down
2 changes: 1 addition & 1 deletion examples-staging/graphql-api-endpoint/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const lists = createSchema({
},
fields: {
name: text({ isRequired: true }),
email: text({ isRequired: true, isUnique: true, graphql: { isEnabled: { filter: true } } }),
email: text({ isRequired: true, isUnique: true, isFilterable: true }),
password: password(),
posts: relationship({ ref: 'Post.author', many: true }),
},
Expand Down
2 changes: 1 addition & 1 deletion examples-staging/roles/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const lists = createSchema({
/* The name of the user */
name: text({ isRequired: true }),
/* The email of the user, used to sign in */
email: text({ isRequired: true, isUnique: true, graphql: { isEnabled: { filter: true } } }),
email: text({ isRequired: true, isUnique: true, isFilterable: true }),
/* The password of the user */
password: password({
isRequired: true,
Expand Down
2 changes: 1 addition & 1 deletion examples/blog/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { select, relationship, text, timestamp } from '@keystone-next/keystone/f
export const lists = createSchema({
Post: list({
fields: {
title: text({ isRequired: true, graphql: { isEnabled: { filter: true } } }),
title: text({ isRequired: true, isFilterable: true }),
status: select({
dataType: 'enum',
options: [
Expand Down
6 changes: 4 additions & 2 deletions examples/custom-admin-ui-logo/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ export const lists = createSchema({
assignedTo: relationship({ ref: 'Person.tasks', many: false }),
finishBy: timestamp(),
},
graphql: { isEnabled: { filter: true, orderBy: true } },
defaultIsFilterable: true,
defaultIsOrderable: true,
}),
Person: list({
fields: {
name: text({ isRequired: true }),
tasks: relationship({ ref: 'Task.assignedTo', many: true }),
},
graphql: { isEnabled: { filter: true, orderBy: true } },
defaultIsFilterable: true,
defaultIsOrderable: true,
}),
});
6 changes: 4 additions & 2 deletions examples/custom-admin-ui-navigation/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ export const lists = createSchema({
assignedTo: relationship({ ref: 'Person.tasks', many: false }),
finishBy: timestamp(),
},
graphql: { isEnabled: { filter: true, orderBy: true } },
defaultIsFilterable: true,
defaultIsOrderable: true,
}),
Person: list({
fields: {
name: text({ isRequired: true }),
tasks: relationship({ ref: 'Task.assignedTo', many: true }),
},
graphql: { isEnabled: { filter: true, orderBy: true } },
defaultIsFilterable: true,
defaultIsOrderable: true,
}),
});
6 changes: 4 additions & 2 deletions examples/custom-admin-ui-pages/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ export const lists = createSchema({
assignedTo: relationship({ ref: 'Person.tasks', many: false }),
finishBy: timestamp(),
},
graphql: { isEnabled: { filter: true, orderBy: true } },
defaultIsFilterable: true,
defaultIsOrderable: true,
Comment on lines +21 to +22
Copy link
Member

Choose a reason for hiding this comment

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

It feels weird to be implicitly saying "yeah, just make all the filters enabled, it's fine" but ok then (I'm not saying you should change it)

}),
Person: list({
fields: {
name: text({ isRequired: true }),
tasks: relationship({ ref: 'Task.assignedTo', many: true }),
},
graphql: { isEnabled: { filter: true, orderBy: true } },
defaultIsFilterable: true,
defaultIsOrderable: true,
}),
});
6 changes: 4 additions & 2 deletions examples/custom-field-view/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ export const lists = createSchema({
},
}),
},
graphql: { isEnabled: { filter: true, orderBy: true } },
defaultIsFilterable: true,
defaultIsOrderable: true,
}),
Person: list({
fields: {
name: text({ isRequired: true }),
tasks: relationship({ ref: 'Task.assignedTo', many: true }),
},
graphql: { isEnabled: { filter: true, orderBy: true } },
defaultIsFilterable: true,
defaultIsOrderable: true,
}),
});
6 changes: 4 additions & 2 deletions examples/default-values/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ export const lists = createSchema({
new Date(new Date().setUTCDate(new Date().getUTCDate() + 7)).toUTCString(),
}),
},
graphql: { isEnabled: { filter: true, orderBy: true } },
defaultIsFilterable: true,
defaultIsOrderable: true,
}),
Person: list({
fields: {
name: text({ isRequired: true }),
tasks: relationship({ ref: 'Task.assignedTo', many: true }),
},
graphql: { isEnabled: { filter: true, orderBy: true } },
defaultIsFilterable: true,
defaultIsOrderable: true,
}),
});
6 changes: 4 additions & 2 deletions examples/task-manager/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ export const lists = createSchema({
assignedTo: relationship({ ref: 'Person.tasks', many: false }),
finishBy: timestamp(),
},
graphql: { isEnabled: { filter: true, orderBy: true } },
defaultIsFilterable: true,
defaultIsOrderable: true,
}),
Person: list({
fields: {
name: text({ isRequired: true }),
tasks: relationship({ ref: 'Task.assignedTo', many: true }),
},
graphql: { isEnabled: { filter: true, orderBy: true } },
defaultIsFilterable: true,
defaultIsOrderable: true,
}),
});
8 changes: 5 additions & 3 deletions examples/testing/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@ export const lists = createSchema({
return !!(session?.itemId && session.itemId === task.assignedTo?.id);
},
},
graphql: { isEnabled: { filter: true, orderBy: true } },
defaultIsFilterable: true,
defaultIsOrderable: true,
}),
Person: list({
fields: {
name: text({ isRequired: true }),
email: text({ isRequired: true, isUnique: true, graphql: { isEnabled: { filter: true } } }),
email: text({ isRequired: true, isUnique: true }),
password: password({ isRequired: true }),
tasks: relationship({ ref: 'Task.assignedTo', many: true }),
},
graphql: { isEnabled: { filter: true, orderBy: true } },
defaultIsFilterable: true,
defaultIsOrderable: true,
}),
});
8 changes: 5 additions & 3 deletions examples/with-auth/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,23 @@ export const lists = createSchema({
assignedTo: relationship({ ref: 'Person.tasks', many: false }),
finishBy: timestamp(),
},
graphql: { isEnabled: { filter: true, orderBy: true } },
defaultIsFilterable: true,
defaultIsOrderable: true,
}),
Person: list({
fields: {
name: text({ isRequired: true }),
// Added an email and password pair to be used with authentication
// The email address is going to be used as the identity field, so it's
// important that we set isRequired, isUnique, and isEnabled: filter.
email: text({ isRequired: true, isUnique: true, graphql: { isEnabled: { filter: true } } }),
email: text({ isRequired: true, isUnique: true, isFilterable: true }),
// The password field stores a hash of the supplied password, and
// we want to ensure that all people have a password set, so we use
// the isRequired flag.
password: password({ isRequired: true }),
tasks: relationship({ ref: 'Task.assignedTo', many: true }),
},
graphql: { isEnabled: { filter: true, orderBy: true } },
defaultIsFilterable: true,
defaultIsOrderable: true,
}),
});
2 changes: 1 addition & 1 deletion packages/auth/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const getSchemaExtension =
throw new Error(
`createAuth was called with an identityField of ${identityField} on the list ${listKey} ` +
`but that field doesn't allow being searched uniquely with a String or ID. ` +
`You should likely add \`isUnique: true\, graphql: { isEnabled: { filter: true } }\` ` +
`You should likely add \`isUnique: true\, isFilterable: true\` ` +
`to the field at ${listKey}.${identityField}`
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ export const skipUpdateTest = true;

export const unSupportedAdapterList = ['sqlite'];

export const getTestFields = () => ({
orderNumber: autoIncrement({ graphql: { isEnabled: { filter: true } } }),
});
export const getTestFields = () => ({ orderNumber: autoIncrement({ isFilterable: true }) });

export const initItems = () => {
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const supportsUnique = false;
export const fieldName = 'enabled';

export const getTestFields = () => ({
enabled: checkbox({ graphql: { isEnabled: { filter: true } } }),
enabled: checkbox({ isFilterable: true }),
});

export const initItems = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ export const supportsUnique = true;
export const fieldName = 'price';
export const unSupportedAdapterList = ['sqlite'];

export const getTestFields = () => ({
price: decimal({ scale: 2, graphql: { isEnabled: { filter: true } } }),
});
export const getTestFields = () => ({ price: decimal({ scale: 2, isFilterable: true }) });

export const initItems = () => {
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ export const exampleValue2 = () => 6.283;
export const supportsUnique = true;
export const fieldName = 'testField';

export const getTestFields = () => ({
testField: float({ graphql: { isEnabled: { filter: true } } }),
});
export const getTestFields = () => ({ testField: float({ isFilterable: true }) });

export const initItems = () => {
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ export const exampleValue2 = () => 38;
export const supportsUnique = true;
export const fieldName = 'testField';

export const getTestFields = () => ({
testField: integer({ graphql: { isEnabled: { filter: true } } }),
});
export const getTestFields = () => ({ testField: integer({ isFilterable: true }) });

export const initItems = () => {
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const supportsUnique = true;
export const fieldConfig = (matrixValue: MatrixValue) => {
if (matrixValue === 'enum' || matrixValue === 'string') {
return {
graphql: { isEnabled: { filter: true } },
isFilterable: true as const,
dataType: matrixValue,
options:
matrixValue === 'enum'
Expand All @@ -34,7 +34,7 @@ export const fieldConfig = (matrixValue: MatrixValue) => {
};
}
return {
graphql: { isEnabled: { filter: true } },
isFilterable: true as const,
dataType: matrixValue,
options: [
{ label: 'One', value: 1 },
Expand Down
Loading