Skip to content

Commit

Permalink
Merge pull request keystonejs#2007 from keystonejs/molomby/doc-fixes
Browse files Browse the repository at this point in the history
Minor doc fixes
  • Loading branch information
molomby authored Nov 27, 2019
2 parents 5a5905d + 6ab0513 commit 9002b1e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 55 deletions.
95 changes: 41 additions & 54 deletions docs/api/hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Any differences are called out in the documentation below.

## Usage

```javascript
```js
keystone.createList('User', {
fields: {
name: {
Expand Down Expand Up @@ -53,13 +53,13 @@ _Note_: `resolveInput` is not executed for deleted items.

<!-- prettier-ignore -->

```javascript
```js
const resolveInput = ({
resolvedData,
existingItem,
originalInput,
context,
list
actions,
}) => resolvedData;
```

Expand All @@ -71,14 +71,14 @@ Executed after `resolveInput`. Should throw if `resolvedData` is invalid.

<!-- prettier-ignore -->

```javascript
```js
const validateInput = ({
resolvedData,
existingItem,
originalInput,
addFieldValidationError,
context,
list,
actions,
}) => {
/* throw any errors here */
};
Expand All @@ -90,6 +90,22 @@ _Note_: `validateInput` is not executed for deleted items. See: [`validateDelete

Executed after `validateInput`. `beforeChange` is not used to manipulate data but can be used to preform actions before data is saved.

#### Usage

<!-- prettier-ignore -->

```js
const beforeChange = ({
resolvedData,
existingItem,
context,
originalInput,
actions,
}) => {
/* side effects here */
};
```

_Note_: `beforeChange` is not executed for deleted items. See: [`beforeDelete`](#before-delete)

### `afterChange`
Expand All @@ -100,13 +116,13 @@ Executed once the mutation has been completed and all transactions finalised.

<!-- prettier-ignore -->

```javascript
```js
const afterChange = ({
updatedItem,
existingItem,
originalInput,
context,
list
actions,
}) => {
/* side effects here */
};
Expand All @@ -122,12 +138,12 @@ Executed after access control checks. Should throw if delete operation is invali

<!-- prettier-ignore -->

```javascript
```js
const validateDelete = ({
existingItem,
addFieldValidationError,
context,
list,
actions,
}) => {
/* throw any errors here */
};
Expand All @@ -141,11 +157,11 @@ Executed after `validateDelete`.

<!-- prettier-ignore -->

```javascript
```js
const beforeDelete = ({
existingItem,
context,
list,
actions,
}) => {
/* throw any errors here */
};
Expand All @@ -159,75 +175,46 @@ Executed once the delete mutation has been completed and all transactions finali

<!-- prettier-ignore -->

```javascript
```js
const afterDelete = ({
existingItem,
context,
list,
actions,
}) => {
/* side effects here */
};
```

---

## Hooks function properties
## Hook Function Arguments

| Parameter | Type | Description |
| Argument | Type | Description |
| ------------------------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------ |
| `resolvedData` | `Object` | An object containing data received by the graphQL mutation and defaults values. |
| `existingItem` | `any` | The current stored value. (`undefined` for create) |
| `originalInput` | `Object` | An object containing arguments passed to the field in the graphQL query. |
| `context` | `Apollo Context` | The [Apollo `context` object](https://www.apollographql.com/docs/apollo-server/essentials/data.html#context) for this request. |
| `list` | `Object` | An Object providing access to List functions. [List properties](#List-properties). |
| `addFieldValidationError` | `Function` | Used to set a field validation error. Accepts a `String`. |
| `actions` | `Object` | An Object providing access to List functions, see [`actions` Argument](#actions-argument). |

### List properties

The `list` property contain an object providing access to List functions:
### `actions` Argument

```javascript
{
/**
* @param args Object The same arguments as the *WhereUniqueInput graphql
* type
* @param context Object The Apollo context object for this request
* @param options.skipAccessControl Boolean By default access control _of
* the user making the initial request_ is still tested. Disable all
* Access Control checks with this flag
*
* @return Promise<Object> The found item
*/
query: (args, context, options) => Promise<Object>,

/**
* @param args Object The same arguments as the *WhereInput graphql type
* @param context Object The Apollo context object for this request
* @param options.skipAccessControl Boolean By default access control _of
* the user making the initial request_ is still tested. Disable all
* Access Control checks with this flag
*
* @return Promise<[Object]|[]> The found item. May reject with Access
* Control errors.
*/
queryMany: (args, context, options) => Promise<Object|null>,
The `actions` argument is an object containing a query helper:

```js
{
/**
* @param args Object The same arguments as the *WhereInput graphql type
* @param context Object The Apollo context object for this request
* @param queryString String A graphQL query string
* @param options.skipAccessControl Boolean By default access control _of
* the user making the initial request_ is still tested. Disable all
* Access Control checks with this flag
* @param options.variables Object The variables passed to the graphql
* query for the given queryString.
*
* @return Promise<Object> Meta data about the found items. Currently
* contains only a single key: `count`.
*/
queryManyMeta: (args, context, options) => Promise<Object>,

/**
* @param key String The string name of a Keystone list
* @return Object The programatic API of the requested list.
* @return Promise<Object> The graphql query response
*/
getList: (key) => Object,
query: (queryString, options, options) => Promise({ errors, data }),
}
```
3 changes: 2 additions & 1 deletion docs/guides/initial-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ This guide will show you how to create a User list and add initial data to it us
First let's create a User list and add a `PasswordAuthStrategy`. Our `index.js` might look like this:

```javascript
const { Keystone, PasswordAuthStrategy } = require('@keystonejs/keystone');
const { Keystone } = require('@keystonejs/keystone');
const { PasswordAuthStrategy } = require('@keystonejs/auth-password');
const { Text, Checkbox, Password } = require('@keystonejs/fields');
const { GraphQLApp } = require('@keystonejs/app-graphql');
const { AdminUIApp } = require('@keystonejs/app-admin-ui');
Expand Down

0 comments on commit 9002b1e

Please sign in to comment.