Skip to content

Commit

Permalink
Merge branch 'master' into fix-exports
Browse files Browse the repository at this point in the history
  • Loading branch information
timleslie authored Feb 26, 2020
2 parents fa0c6ef + 27b4b68 commit c32ca8f
Show file tree
Hide file tree
Showing 9 changed files with 207 additions and 112 deletions.
5 changes: 5 additions & 0 deletions .changeset/spotty-carpets-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystonejs/keystone': minor
---

Added support for the new GraphQL Provider Framework (#2418).
5 changes: 5 additions & 0 deletions .changeset/strange-carrots-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystonejs/keystone': patch
---

Added a VersionProvider to generate the `appVersion` graphQL query.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</div>
<br>

[![Build Status](https://img.shields.io/circleci/project/github/keystonejs/keystone/master.svg)](https://circleci.com/gh/emotion-js/emotion)
[![Build Status](https://img.shields.io/circleci/project/github/keystonejs/keystone/master.svg)](https://circleci.com/gh/keystonejs/keystone)
[![slack](https://keystone-community.now.sh//badge.svg)](https://keystone-community.now.sh/)
[![Supported by Thinkmill](https://thinkmill.github.io/badge/heart.svg)](http://thinkmill.com.au/?utm_source=github&utm_medium=badge&utm_campaign=react-select)

Expand Down
205 changes: 111 additions & 94 deletions docs/guides/initial-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This guide will show you how to create a User list and add initial data to it us
_Note_: In a previous chapter the code was split up over separate files, while this is preferred in a real code base, in this part everything is put in one file for clarity reasons.

This chapter will use a different User schema than previous chapters and instead of a Todo list, there will be a Post list. It is best to start from a fresh project and start from an empty database (delete data from previous chapters). Also, make sure to have all of the following packages installed:

```
yarn add @keystonejs/keystone
yarn add @keystonejs/adapter-mongoose
Expand Down Expand Up @@ -67,31 +68,35 @@ _Hint_: A similar same setup can be achieved by running the KeystoneJS CLI `yarn

`createItems` requires an object where keys are list keys, and values are arrays of items to insert.
For example:

```
keystone.createItems({
User: [
{ name: 'John Duck', email: '[email protected]', password: 'dolphins' },
{ name: 'John Duck', email: '[email protected]', password: 'dolphins' },
{ name: 'Barry', email: '[email protected]', password: 'dolphins' }
],
});
```

_Note_: The format of the data must match the schema setup with calls to `keystone.createList()`. As an example in our schema the email has `isUnique: true`, therefor it would not be possible for the above code to have the same email for each user that should be generated.

Example on how to `seed` the data upon database connection:

```javascript
const keystone = new Keystone({
name: 'New Project',
adapter: new MongooseAdapter(),
onConnect: async keystone => {
await keystone.createItems({
User: [
{ name: 'John Duck', email: '[email protected]', password: 'dolphins' },
{ name: 'Barry', email: '[email protected]', password: 'dolphins' }
],
});
}
name: 'New Project',
adapter: new MongooseAdapter(),
onConnect: async keystone => {
await keystone.createItems({
User: [
{ name: 'John Duck', email: '[email protected]', password: 'dolphins' },
{ name: 'Barry', email: '[email protected]', password: 'dolphins' },
],
});
},
});
```

Start the application and visit the AdminUI, two users are available on startup.

_Note_: In this example the same two users would be generated upon _every_ startup. Since email should be unique this will cause a duplicate error to show up. To avoid this, clear the database before starting KeystoneJS.
Expand All @@ -103,26 +108,29 @@ It is possible to create relationships upon insertion by using the KeystoneJS qu
#### Single Relationships

Add the `Relationship` field to the imports:

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

Create a list with a relationship to another list:
Create a list with a relationship to another list:

```javascript
keystone.createList('Post', {
fields: {
title: {
type: Text,
},
author: {
type: Relationship,
ref: 'User'
},
fields: {
title: {
type: Text,
},
author: {
type: Relationship,
ref: 'User',
},
},
});
```

Example on how to seed an item with a relationship:

```javascript
Post: [
{
Expand All @@ -133,24 +141,25 @@ Post: [
```

The full example:

```javascript
const keystone = new Keystone({
name: 'New Project',
adapter: new MongooseAdapter(),
onConnect: async keystone => {
await keystone.createItems({
User: [
{ name: 'John Duck', email: '[email protected]', password: 'dolphins' },
{ name: 'Barry', email: '[email protected]', password: 'dolphins' }
],
Post: [
{
title: 'Hello World',
author: { where: { name: 'John Duck' } },
},
],
});
}
name: 'New Project',
adapter: new MongooseAdapter(),
onConnect: async keystone => {
await keystone.createItems({
User: [
{ name: 'John Duck', email: '[email protected]', password: 'dolphins' },
{ name: 'Barry', email: '[email protected]', password: 'dolphins' },
],
Post: [
{
title: 'Hello World',
author: { where: { name: 'John Duck' } },
},
],
});
},
});
```

Expand Down Expand Up @@ -178,14 +187,15 @@ keystone.createList('User', {
password: {
type: Password,
},
posts: {
type: Relationship,
ref: 'Post',
many: true,
posts: {
type: Relationship,
ref: 'Post',
many: true,
},
},
});
```

There are two ways to write the query for `to-many` relationships:

1. _Single Relation syntax_ uses the same query as a Single Relationship, but
Expand All @@ -196,73 +206,80 @@ There are two ways to write the query for `to-many` relationships:
**Single Relation syntax** example

To get all posts where the `title` field contains the word `React`:

```javascript
posts: { where: { title_contains: 'React' } }
posts: {
where: {
title_contains: 'React';
}
}
```

In action:

```javascript
const keystone = new Keystone({
name: 'New Project',
adapter: new MongooseAdapter(),
onConnect: async keystone => {
await keystone.createItems({
User: [
{
name: 'John Duck',
email: '[email protected]',
password: 'dolphins',
posts: { where: { title_contains: 'React' } },
},
{
name: 'Barry',
email: '[email protected]',
password: 'dolphins',
isAdmin: true,
}
],
Post: [
{ title: 'Hello Everyone' },
{ title: 'Talking about React' },
{ title: 'React is the Best' },
{ title: 'KeystoneJS Rocks' },
],
});
}
name: 'New Project',
adapter: new MongooseAdapter(),
onConnect: async keystone => {
await keystone.createItems({
User: [
{
name: 'John Duck',
email: '[email protected]',
password: 'dolphins',
posts: { where: { title_contains: 'React' } },
},
{
name: 'Barry',
email: '[email protected]',
password: 'dolphins',
isAdmin: true,
},
],
Post: [
{ title: 'Hello Everyone' },
{ title: 'Talking about React' },
{ title: 'React is the Best' },
{ title: 'KeystoneJS Rocks' },
],
});
},
});
```

Clear the database, start the KeystoneJS application and visit the AdminUI. Take a look at the user `John Duck`, he has two posts associated with him (there were two posts with the word `React` in the `title`).

**Array Relation syntax** example

```javascript
const keystone = new Keystone({
name: 'New Project',
adapter: new MongooseAdapter(),
onConnect: async keystone => {
await keystone.createItems({
User: [
{
name: 'John Duck',
email: '[email protected]',
password: 'dolphins',
posts: { where: { title_contains: 'React' } },
},
{
name: 'Barry',
email: '[email protected]',
password: 'dolphins',
isAdmin: true,
}
],
Post: [
{ title: 'Hello Everyone' },
{ title: 'Talking about React' },
{ title: 'React is the Best' },
{ title: 'KeystoneJS Rocks' },
],
});
}
name: 'New Project',
adapter: new MongooseAdapter(),
onConnect: async keystone => {
await keystone.createItems({
User: [
{
name: 'John Duck',
email: '[email protected]',
password: 'dolphins',
posts: { where: { title_contains: 'React' } },
},
{
name: 'Barry',
email: '[email protected]',
password: 'dolphins',
isAdmin: true,
},
],
Post: [
{ title: 'Hello Everyone' },
{ title: 'Talking about React' },
{ title: 'React is the Best' },
{ title: 'KeystoneJS Rocks' },
],
});
},
});
```

Expand All @@ -271,7 +288,7 @@ any items, an Error will be thrown._

Clear the database, start the KeystoneJS application and visit the AdminUI. Take a look at both users, they each now have two posts associated with them. `John Duck` has the posts that contain `React` in the title. `Barry` has the posts that matched any of the queries in the array.

_Note_: When looking at the posts, there are *no* associated users! To have both the user associated with the post as well is called `back reference`, this will be handled in a later chapter.
_Note_: When looking at the posts, there are _no_ associated users! To have both the user associated with the post as well is called `back reference`, this will be handled in a later chapter.

---

Expand Down
3 changes: 2 additions & 1 deletion docs/guides/performance.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ keystone.createList('Foo', {

// ---- Schema dumping ----
if (typeof process.env.DUMP_SCHEMA === 'string') {
keystone.dumpSchema(process.env.DUMP_SCHEMA);
const schemaName = 'public'; //this is the default keystonejs schema name
keystone.dumpSchema(process.env.DUMP_SCHEMA, schemaName);
console.log(`Schema dumped to: ${path.resolve(process.env.DUMP_SCHEMA)}`);
process.exit(0);
}
Expand Down
4 changes: 4 additions & 0 deletions packages/fields/src/types/Relationship/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Use the `create` nested mutation to create and append an item to a to-many
relationship:

<!-- prettier-ignore -->

```graphql
# Replace all posts of a given User
mutation replaceAllPosts {
Expand All @@ -93,6 +94,7 @@ Use the `connect` nested mutation to append an existing item to a to-many
relationship:

<!-- prettier-ignore -->

```graphql
# Replace the company of a given User
mutation replaceAllPosts {
Expand All @@ -119,6 +121,7 @@ the value of a to-single relationship (it's not necessary to use `disconnectAll`
as is the case for [to-many relationships](#overriding-a-to-many-relationship)):

<!-- prettier-ignore -->

```graphql
# Replace the company of a given User
mutation replaceAllPosts {
Expand All @@ -145,6 +148,7 @@ To completely replace the related items in a to-many list, you can perform a
mutation (thanks to the [order of execution](#order-of-execution)):

<!-- prettier-ignore -->

```graphql
# Replace all posts related to a given User
mutation replaceAllPosts {
Expand Down
Loading

0 comments on commit c32ca8f

Please sign in to comment.