Skip to content

Commit

Permalink
Docs/Fields: include imports in usecase examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed Mar 26, 2020
1 parent 7293932 commit 3ad0565
Show file tree
Hide file tree
Showing 16 changed files with 37 additions and 5 deletions.
2 changes: 2 additions & 0 deletions packages/fields-authed-relationship/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Great for setting fields like `Post.author` or `Product.owner`, etc.
### Basic

```js
const { AuthedRelationship } = require('@keystonejs/fields-authed-relationship');

keystone.createList('User', {
fields: {
name: { type: String },
Expand Down
2 changes: 1 addition & 1 deletion packages/fields-auto-increment/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Specifically:

```js
const { Keystone } = require('@keystonejs/keystone');
const { AutoIncrement } = require('@keystonejs/fields-auto-increment');
const { AutoIncrement, Text } = require('@keystonejs/fields-auto-increment');

const keystone = new Keystone({...});

Expand Down
2 changes: 2 additions & 0 deletions packages/fields-datetime-utc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ This package is not part of the core fields, and needs to be installed separatel
## Usage

```js
const { DateTimeUtc } = require('@keystonejs/fields-datetime-utc');

keystone.createList('User', {
fields: {
lastOnline: { type: DateTimeUtc },
Expand Down
2 changes: 2 additions & 0 deletions packages/fields/src/types/Checkbox/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ The `Checkbox` field type stores a single Boolean value.
## Usage

```js
const { Checkbox, Text } = require('@keystonejs/fields');

keystone.createList('Products', {
fields: {
name: { type: Text },
Expand Down
2 changes: 2 additions & 0 deletions packages/fields/src/types/CloudinaryImage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const cloudinaryAdapter = new CloudinaryAdapter({
Then when creating your list, use the field as so:

```js
const { CloudinaryImage } = require('@keystonejs/fields');

keystone.createList('Item', {
fields: {
image: { type: CloudinaryImage, adapter: cloudinaryAdapter },
Expand Down
2 changes: 2 additions & 0 deletions packages/fields/src/types/Color/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ title: Color
## Usage

```js
const { Color } = require('@keystonejs/fields');

keystone.createList('Product', {
fields: {
heroColor: { type: Color },
Expand Down
2 changes: 2 additions & 0 deletions packages/fields/src/types/Decimal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ See the [Storage section](#storage) for specifics.
## Usage

```js
const { DateTime, Decimal, Text } = require('@keystonejs/fields');

keystone.createList('Payment', {
fields: {
timestamp: { type: DateTime },
Expand Down
2 changes: 2 additions & 0 deletions packages/fields/src/types/Float/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ title: Float
## Usage

```js
const { Float, DateTime } = require('@keystonejs/fields');

keystone.createList('SensorReading', {
fields: {
loggedAt: { type: DateTime },
Expand Down
2 changes: 2 additions & 0 deletions packages/fields/src/types/Integer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ title: Integer
## Usage

```js
const { Integer, Text } = require('@keystonejs/fields');

keystone.createList('Review', {
fields: {
comments: { type: Text },
Expand Down
2 changes: 1 addition & 1 deletion packages/fields/src/types/OEmbed/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ to parse the resource directly.

```js
const { Keystone } = require('@keystonejs/keystone');
const { OEmbed } = require('@keystonejs/fields');
const { OEmbed, Text } = require('@keystonejs/fields');
const { IframelyOEmbedAdapter } = require('@keystonejs/oembed-adapters');

const keystone = new Keystone({...});
Expand Down
2 changes: 2 additions & 0 deletions packages/fields/src/types/Password/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ to be verified without knowledge of the original value.
## Usage

```js
const { Password, Text } = require('@keystonejs/fields');

keystone.createList('User', {
fields: {
email: { type: Text },
Expand Down
2 changes: 2 additions & 0 deletions packages/fields/src/types/Relationship/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ title: Relationship
## Usage

```javascript
const { Relationship, Text } = require('@keystonejs/fields');

keystone.createList('User', {
fields: {
name: { type: Text },
Expand Down
2 changes: 2 additions & 0 deletions packages/fields/src/types/Select/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ title: Select
## Usage

```js
const { Select } = require('@keystonejs/fields');

keystone.createList('Orders', {
fields: {
status: { type: Select, options: 'pending, processed' },
Expand Down
2 changes: 2 additions & 0 deletions packages/fields/src/types/Text/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ title: Text
## Usage

```js
const { Text } = require('@keystonejs/fields');

keystone.createList('Product', {
fields: {
description: { type: Text },
Expand Down
2 changes: 2 additions & 0 deletions packages/fields/src/types/Uuid/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ The encoding used for storage differs by DB adapter, see the [Storage section](#
## Usage

```js
const { Uuid, Text } = require('@keystonejs/fields');

keystone.createList('Products', {
fields: {
name: { type: Text },
Expand Down
12 changes: 9 additions & 3 deletions packages/fields/src/types/Virtual/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ title: Virtual
If the resolver is a function that returns a string you don't need to define a return type.

```js
const { Virtual, Text } = require('@keystonejs/fields');

keystone.createList('Example', {
fields: {
firstName: { type: Text },
Expand All @@ -27,6 +29,8 @@ keystone.createList('Example', {
If the return type is not a string define a `graphQLReturnType`.

```js
const { Virtual } = require('@keystonejs/fields');

keystone.createList('Example', {
fields: {
fortyTwo: {
Expand All @@ -41,6 +45,8 @@ keystone.createList('Example', {
For more complex types you can define a `graphQLReturnFragment` as well as `extendGraphQLTypes`. Resolver functions can be `async` so you can even fetch data from the file system or an external API:

```js
const { Virtual } = require('@keystonejs/fields');

keystone.createList('Example', {
fields: {
movies: {
Expand All @@ -66,9 +72,9 @@ keystone.createList('Example', {
| Option | Type | Default | Description |
| ----------------------- | ---------- | ---------- | ----------------------------------------------------------- |
| `resolver` | `Function` | (required) | |
| `graphQLReturnType` | `String` | 'String' | A GraphQL Type String |
| `graphQLReturnFragment` | `String` | '' | A GraphQL Fragment String -required for nested return types |
| `extendGraphQLTypes` | `Array` | \[] | An array of custom GraphQL type definitions |
| `graphQLReturnType` | `String` | `String` | A GraphQL Type String |
| `graphQLReturnFragment` | `String` | `''` | A GraphQL Fragment String -required for nested return types |
| `extendGraphQLTypes` | `Array` | `[]` | An array of custom GraphQL type definitions |

> **Note**: Related fields within a virtual field resolver will not return related items.
Expand Down

0 comments on commit 3ad0565

Please sign in to comment.