Skip to content

Commit

Permalink
Remove keystone.executeQuery (#3172)
Browse files Browse the repository at this point in the history
  • Loading branch information
timleslie authored Jul 2, 2020
1 parent 56e1798 commit 81b4df3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 74 deletions.
6 changes: 6 additions & 0 deletions .changeset/silent-berries-swim.md
Original file line number Diff line number Diff line change
@@ -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()`.
49 changes: 0 additions & 49 deletions packages/keystone/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()`. |
Expand Down Expand Up @@ -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)`

Expand Down
25 changes: 0 additions & 25 deletions packages/keystone/lib/Keystone/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 81b4df3

Please sign in to comment.