Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement suggestion #2200

Merged
merged 2 commits into from
Jan 8, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 26 additions & 25 deletions docs/guides/new-project.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ cd new-project
yarn init
```

Let's start with minimal setup. We will need two packages here:
Let's start with the minimal setup. We will need two packages here:
`@keystonejs/keystone` which is KeystoneJS' core and `@keystonejs/adapter-mongoose` which allows our app to connect to MongoDB.

Do
Expand All @@ -30,7 +30,7 @@ yarn add @keystonejs/keystone @keystonejs/adapter-mongoose

## First Steps

After installation we can start coding. Main entry point of a KeystoneJS app is the `index.js` file in the root folder. Create it and add the following:
After installation we can start coding. The main entry point of a KeystoneJS app is the `index.js` file in the root folder. Create it and add the following:

```javascript
// import necessary modules
Expand All @@ -46,15 +46,15 @@ const keystone = new Keystone({

You can specify any suitable name for your application. Note that we created an instance of the [Mongoose Adapter](/packages/adapter-mongoose/README.md) and passed it to KeystoneJS' constructor.

Now we can export our instance and make it available for running. Add following to the end of `index.js`:
Now we can export our instance and make it available to run. Add the following to the end of `index.js`:

```javascript
module.exports = {
keystone,
};
```

That's it. But now our app does nothing, just starting and connecting to database. If you run application now it will display something like this:
That's it. But now our app does nothing, it is able to start and connect to a database. If you run the application now, it will display something like this:

```
TypeError: Router.use() requires a middleware function
Expand All @@ -64,19 +64,19 @@ Let's create some routes! For this we will enable a powerful KeystoneJS feature

## Setting up the GraphQL Interface

As in the previous step install necessary the package.
As in the previous step, install the necessary package.

```
yarn add @keystonejs/app-graphql
```

Import it...
Import it in index.js:

```javascript
const { GraphQLApp } = require('@keystonejs/app-graphql');
```

And add a new array export named `apps` with a new instance of `GraphQLApp`, like so.
And add a new array export named `apps` with a new instance of `GraphQLApp`, like so:

```javascript
module.exports = {
Expand All @@ -89,7 +89,18 @@ In order to be able to start an app we need to add at least one List. A List is

## Adding first List

In `index.js` add following before `module.exports`:
To type the fields of the list, a package has to be installed:
```
yarn add @keystonejs/fields
```

In this example the type `Text` is used, require this in index.js:
```javascript
const { Text } = require('@keystonejs/fields');
```


In `index.js` add the following above `module.exports` and below `const keystone = new Keystone({...`:

```
keystone.createList('Todo', {
Expand All @@ -99,44 +110,34 @@ keystone.createList('Todo', {
});
```

This code snippet creates a List named 'Todos'. The second argument is a config object. For now it have only one key (`fields`) which is used to define the schema for newly created model.
This code snippet creates a List named 'Todos'. The second argument is a config object. For now it has only one key (`fields`) which is used to define the schema for the newly created model.

In our example, the `Todo` list has a single field called `name` of type `Text`. Note the type is _not_ a string; it must be imported like so:

```
yarn add @keystonejs/fields
```

and

```javascript
const { Text } = require('@keystonejs/fields');
```
In our example, the `Todo` list has a single field called `name` of type `Text`. Note the type is _not_ a string, it is a type that has been imported through the package `@keystonejs/fields`.

That's it!

## Starting application
## Starting the application

Add following to `package.json`:
Add the following to `package.json`:

```json
"scripts": {
"start:dev": "keystone"
}
```

Now ensure that `mongod` is running and execute our start script:
Now ensure that `mongod` is running and execute the start script:

```
yarn start:dev
```

You should see something like this
You should see something like this:

```
✔ Keystone instance is ready 🚀
🔗 GraphQL Playground: http://localhost:3000/admin/graphiql
🔗 GraphQL API: http://localhost:3000/admin/api
```

Now it's the time to check those routes in browser to ensure that everything works as expected. Then proceed to second step - [Adding Lists](/docs/guides/add-lists.md)
Now it's time to check those routes in browser to ensure that everything works as expected. Then proceed to second step - [Adding Lists](/docs/guides/add-lists.md)