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

Remove queryLimits.maxResults, add maximumTake #7963

Merged
merged 15 commits into from
Oct 10, 2022
5 changes: 5 additions & 0 deletions .changeset/less-carry-on.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-6/core': major
---

Removes `context.totalResults` and `context.maxTotalResults`
5 changes: 5 additions & 0 deletions .changeset/take-your-baggage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-6/core': minor
---

Adds `[list].graphql.maxTake`, a list configuration option to enforce the maximum `take` value in findMany queries for that list
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ coverage
**/.next
**/.keystone
**/__generated__
docs/public/assets/
docs/
.keystone/tests
prisma-utils/src/generated
nexus-typegen.ts
Expand Down
3 changes: 0 additions & 3 deletions docs/pages/docs/config/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,6 @@ Options:

- `debug` (default: `process.env.NODE_ENV !== 'production'`): If `true`, stacktraces from both Apollo errors and Keystone errors will be included in the errors returned from the GraphQL API.
These can be filtered out with `apolloConfig.formatError` if you need to process them, but do not want them returned over the GraphQL API.
- `queryLimits` (default: `undefined`): Allows you to limit the total number of results returned from a query to your GraphQL API.
Copy link
Member Author

Choose a reason for hiding this comment

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

This was removed many moons ago

See also the per-list `graphql.queryLimits` option in the [Lists API](./lists).
- `path` (default: `'/api/graphql'`): The path of the GraphQL API endpoint.
- `playground` (default: `process.env.NODE_ENV !== 'production'`)
- `true` - Add `ApolloServerPluginLandingPageGraphQLPlayground` to the Apollo Server plugins
Expand All @@ -399,7 +397,6 @@ Options:
export default config({
graphql: {
debug: process.env.NODE_ENV !== 'production',
queryLimits: { maxTotalResults: 100 },
path: '/api/graphql',
apolloConfig: {
debug: true,
Expand Down
33 changes: 29 additions & 4 deletions docs/pages/docs/config/lists.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Options:
- `initialSort` (default: `undefined`): Sets the field and direction to be used to initially sort the data in the list view.
Option `field` is the name of the field to sort by, and `direction` is either `'ASC'` or `'DESC'` for ascending and descending sorting respectively.
If undefined then data will be unsorted.
- `pageSize` (default: `50`): Sets the number of items to show per page in the list view.
- `pageSize` (default: lower of `50` or [`graphql.maxTake`](#graphql)): Sets the number of items to show per page in the list view.
- `label`: The label used to identify the list in navigation etc.
- `singular`: The singular form of the list key. It is used in sentences like `Are you sure you want to delete this {singular}?`
- `plural`: The plural form of the list key. It is used in sentences like `Are you sure you want to delete these {plural}?`
Expand Down Expand Up @@ -165,14 +165,16 @@ Options:
- `description` (default: `undefined`): Sets the description of the associated GraphQL type in the generated GraphQL API documentation.
Overrides the list-level `description` config option.
- `plural`: (default: Pluralised list key, e.g. `'Users'`): Overrides the name used in multiple mutations and queries (e.g. `users()`, `updateUsers()`, etc).
- `queryLimits` (default: `undefined`): Allows you to limit the number of results returned from a query to this list in the GraphQL API.
See also the global `graphql.queryLimits` option in the [System Configuration API](./config).
{% if $nextRelease %}
- `maxTake` (default: `undefined`): Allows you to specify the maximum `take` number for query operations on this list in the GraphQL API.
{% /if %}
- `cacheHint` (default: `undefined`): Allows you to specify the [dynamic cache control hints](https://www.apollographql.com/docs/apollo-server/performance/caching/#in-your-resolvers-dynamic) used for queries to this list.
- `omit` (default: `undefined`): Allows you to configure which parts of the CRUD API are autogenerated for your GraphQL API.
This option accepts either `true`, or an array of the values `query`, `create`, `update`, or `delete`.
If you specify `true` then the entire list, including its output type, will be omitted from the GraphQL API.
If you provide an array of `query`, `create`, `update`, or `delete` options, the corresponding operations will be omitted from the GraphQL API.

{% if $nextRelease %}
```typescript
import { CacheScope } from 'apollo-cache-control';
import { config, list } from '@keystone-6/core';
Expand All @@ -184,7 +186,7 @@ export default config({
description: '...',
itemQueryName: '...',
listQueryName: '...',
queryLimits: { maxResults: 100 },
maxTake: 100,
cacheHint: { maxAge: 60, scope: CacheScope.Private },
omit: ['query', 'create', 'update', 'delete'],
},
Expand All @@ -195,6 +197,29 @@ export default config({
/* ... */
});
```
{% else /%}
```typescript
import { CacheScope } from 'apollo-cache-control';
import { config, list } from '@keystone-6/core';

export default config({
lists: {
SomeListName: list({
graphql: {
description: '...',
itemQueryName: '...',
listQueryName: '...',
cacheHint: { maxAge: 60, scope: CacheScope.Private },
omit: ['query', 'create', 'update', 'delete'],
},
/* ... */
}),
/* ... */
},
/* ... */
});
```
{% /if %}

## db

Expand Down
12 changes: 0 additions & 12 deletions docs/pages/docs/context/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ context = {
getDataFromStream,
},

// Internal state
totalResults,
maxTotalResults,

// Deprecated
gqlNames,
};
Expand Down Expand Up @@ -142,14 +138,6 @@ type ImageData = {

`async images.getDataFromStream(stream)`: Given a readable data stream, returns an `ImageData` object. The `mode` will be taken from `config.images.mode`, and `id` will be a `uuid` value. The other values will be inferred from the data stream itself. The contents of the stream will be written to the filesystem at `config.images.local.storagePath`.

### Internal state

These properties are used internally by Keystone and generally do not need to be directly accessed.

`totalResults`: The cumulative total number of results returned by the current request. See [`config.graphql.queryLimits`](../config/config#graphql).

`maxTotalResults`: The maximum number of results which can be returned before a query limit error is triggered. See [`config.graphql.queryLimits`](../config/config#graphql).

### Deprecated

The following properties are deprecated and should not be used.
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/docs/graphql/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ The following error codes can be returned from the Keystone GraphQL API.
- `KS_ACCESS_DENIED`: The operation is not allowed because either an [Access Control](../config/access-control) rule prevents it, or the item does not exist.
- `KS_FILTER_DENIED`: The filter or ordering operation is not allowed because of [`isFilterable` or `isOrderable`](../fields/overview#common-configuration) rules.
- `KS_VALIDATION_FAILURE`: The operation is not allowed because of a [validation](../guides/hooks#validating-inputs) rule.
- `KS_LIMITS_EXCEEDED`: The user has exceeded their [query limits](../config/lists#graphql).
- `KS_LIMITS_EXCEEDED`: The user has exceeded some query limits. E.g, a `take` input [that is too high](../config/lists#graphql).
- `KS_EXTENSION_ERROR`: An error was thrown while excuting a system extension function, such as a hook or an access control function.
- `KS_ACCESS_RETURN_ERROR`: An invalid value was returned from an access control function.
- `KS_RESOLVER_ERROR`: An error occured while resolving the input for a field.
Expand Down
36 changes: 36 additions & 0 deletions examples/limits/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
## Base Project - Limits

This project demonstrates usage of different limits you can add to your GraphQL schema in Keystone.

## Instructions

To run this project, clone the Keystone repository locally, run `yarn` at the root of this repository, then navigate to this directory and run:

```shell
yarn dev
```

This will start the Admin UI at [localhost:3000](http://localhost:3000).
You can use the Admin UI to create items in your database.

You can also access a GraphQL Playground at [localhost:3000/api/graphql](http://localhost:3000/api/graphql), which allows you to directly run GraphQL queries and mutations.

Congratulations, you're now up and running with Keystone! 🚀

### Optional: add sample data

This example includes sample data. To add it to your database:

1. Ensure you’ve initialised your project with `yarn dev` at least once.
2. Run `yarn seed-data`. This will populate your database with sample content.
3. Run `yarn dev` again to startup Admin UI with sample data in place.

## Try it out in CodeSandbox 🧪

You can play with this example online in a web browser using the free [codesandbox.io](https://codesandbox.io/) service. To launch this example, open the URL <https://githubbox.com/keystonejs/keystone/tree/main/examples/blog>. You can also fork this sandbox to make your own changes.

## Next steps

Experiment with the code in this example to see how Keystone works, familiarise yourself with the Admin UI, and learn about the GraphQL Playground.

When you’ve got the hang of this base project, try a [feature project](../) to learn Keystone’s advanced features and take your knowledge to the next level.
10 changes: 10 additions & 0 deletions examples/limits/keystone.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { config } from '@keystone-6/core';
import { lists } from './schema';

export default config({
db: {
provider: 'sqlite',
url: process.env.DATABASE_URL || 'file:./keystone-example.db',
},
lists,
});
20 changes: 20 additions & 0 deletions examples/limits/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@keystone-6/example-limits",
"version": "0.0.1",
"private": true,
"license": "MIT",
"scripts": {
"dev": "keystone dev",
"start": "keystone start",
"build": "keystone build",
"seed-data": "tsx seed-data.ts"
},
"dependencies": {
"@keystone-6/core": "^2.2.0"
},
"devDependencies": {
"tsx": "^3.9.0",
"typescript": "~4.7.4"
},
"repository": "https://github.com/keystonejs/keystone/tree/main/examples/limits"
}
7 changes: 7 additions & 0 deletions examples/limits/sandbox.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"template": "node",
"container": {
"startScript": "keystone dev",
"node": "14"
}
}
Loading