diff --git a/.changeset/silent-berries-swim.md b/.changeset/silent-berries-swim.md new file mode 100644 index 00000000000..cbdfaa56412 --- /dev/null +++ b/.changeset/silent-berries-swim.md @@ -0,0 +1,6 @@ +--- +'@keystonejs/keystone': major +--- + +Removed the method `keystone.executeQuery()`, which has been superseded by `keystone.executeGraphQL()`. +See [the docs](/docs/discussions/server-side-graphql.md) for more details on how to use `keystone.executeGraphQL()`. diff --git a/packages/keystone/README.md b/packages/keystone/README.md index beb55e34f76..8cdebd97826 100644 --- a/packages/keystone/README.md +++ b/packages/keystone/README.md @@ -127,7 +127,6 @@ const keystone = new Keystone({ | `createItems` | Add items to a `Keystone` list. | | `createList` | Add a list to the `Keystone` schema. | | `disconnect` | Disconnect from all adapters. | -| `executeQuery` | (Deprecated) Run GraphQL queries and mutations directly against a `Keystone` instance. | | `extendGraphQLSchema` | Extend keystones generated schema with custom types, queries, and mutations. | | `prepare` | Manually prepare `Keystone` middlewares. | | `createContext` | Create a `context` object that can be used with `executeGraphQL()`. | @@ -238,54 +237,6 @@ keystone.createList('Posts', {...}); Disconnect all adapters. -### `executeQuery(queryString, config)` - -WARNING: This method is now deprecated and will be removed in a future release. Use `keystone.executeGraphQL` instead. - -Use this method to execute queries or mutations directly against a `Keystone` instance. - -**Note:** When querying or mutating via `keystone.executeQuery`, there are differences to keep in mind: - -- No access control checks are run (everything is set to `() => true`) -- The `context.req` object is set to `{}` (you can override this if necessary, - see options below) -- Attempting to authenticate will throw errors (due to `req` being mocked) - -Returns a Promise representing the result of the given query or mutation. - -```javascript allowCopy=false showLanguage=false -keystone.executeQuery('query-string', {...}); -``` - -#### queryString - -A GraphQL query string. For example: - -```graphql -query { - allTodos { - id - name - } -} -``` - -Can also be a mutation: - -```graphql -mutation newTodo($name: String) { - createTodo(name: $name) { - id - } -} -``` - -#### Config - -| Option | Type | Default | Description | -| ----------- | -------- | ------- | ------------------------------------------------------------------------------------------------------------------------- | -| `context` | `Object` | `{}` | Override the default `context` object passed to the GraphQL engine. Useful for adding a `req` or setting the `schemaName` | -| `variables` | `Object` | `{}` | The variables passed to the graphql query for the given queryString. | ### `extendGraphQLSchema(config)` diff --git a/packages/keystone/lib/Keystone/index.js b/packages/keystone/lib/Keystone/index.js index bc9d259f071..4763bea84c6 100644 --- a/packages/keystone/lib/Keystone/index.js +++ b/packages/keystone/lib/Keystone/index.js @@ -100,15 +100,6 @@ module.exports = class Keystone { if (this.queryLimits.maxTotalResults < 1) { throw new Error("queryLimits.maxTotalResults can't be < 1"); } - - // Placeholder until keystone.prepare() is run during which this function - // will be replaced with one that can actually make queries (assuming the - // graphql app is setup, which is checked for elsewhere). - this.executeQuery = () => { - throw new Error( - 'Attempted to execute keystone.query() before keystone.connect() has completed.' - ); - }; } _executeOperation({ @@ -521,22 +512,6 @@ module.exports = class Keystone { const rels = this._consolidateRelationships(); await resolveAllKeys(mapKeys(adapters, adapter => adapter.connect({ name, rels }))); - // Now that the middlewares are done, and we're connected to the database, - // it's safe to assume all the schemas are registered, so we can setup our - // query helper This enables god-mode queries with no access control checks - const _executeQuery = this._buildQueryHelper( - this.getGraphQlContext({ - skipAccessControl: true, - // This is for backwards compatibility with single-schema Keystone - schemaName: this._schemaNames.length === 1 ? this._schemaNames[0] : undefined, - }) - ); - this.executeQuery = (...args) => { - console.warn(`keystone.executeQuery() is deprecated and will be removed in a future release. -Please use keystone.executeGraphQL instead. See https://www.keystonejs.com/discussions/server-side-graphql for details.`); - return _executeQuery(...args); - }; - if (this.eventHandlers.onConnect) { return this.eventHandlers.onConnect(this); }