Skip to content

Commit 5a78466

Browse files
author
hirsch88
committed
Merge branch 'release/3.0.0-rc.1'
2 parents 8ad2e00 + 55addd0 commit 5a78466

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1723
-329
lines changed

.env.example

+7
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ DB_DATABASE="my_database"
3030
DB_SYNCHRONIZE=false
3131
DB_LOGGING=false
3232

33+
#
34+
# GraphQL
35+
#
36+
GRAPHQL_ENABLED=true
37+
GRAPHQL_ROUTE="/graphql"
38+
GRAPHQL_EDITOR=true
39+
3340
#
3441
# Swagger
3542
#

.env.test

+8-7
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,16 @@ AUTH_ROUTE="http://localhost:3333/tokeninfo"
2121
#
2222
# DATABASE
2323
#
24-
DB_TYPE="mysql"
25-
DB_HOST="localhost"
26-
DB_PORT=3306
27-
DB_USERNAME="root"
28-
DB_PASSWORD=""
29-
DB_DATABASE="my_database"
30-
DB_SYNCHRONIZE=false
24+
DB_TYPE="sqlite"
25+
DB_DATABASE="./mydb.sql"
3126
DB_LOGGING=false
3227

28+
#
29+
# GraphQL
30+
#
31+
GRAPHQL_ENABLED=true
32+
GRAPHQL_ROUTE="/graphql"
33+
3334
#
3435
# Swagger
3536
#

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ typings/
2121
# Dist #
2222
dist/
2323
ormconfig.json
24+
tsconfig.build.json
2425

2526
# IDE #
2627
.idea/
@@ -34,3 +35,4 @@ test/**/*.js
3435
test/**/*.js.map
3536
coverage/
3637
!test/preprocessor.js
38+
mydb.sql

.vscode/settings.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
{
22
"typescript.tsdk": "./node_modules/typescript/lib",
3-
"cSpell.enabled": true
3+
"cSpell.enabled": true,
4+
"files.exclude": {
5+
"tsconfig.build.json": true,
6+
"ormconfig.json": true
7+
}
48
}

README.md

+24-10
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
[Jest](https://facebook.github.io/jest/),
1919
[Swagger](http://swagger.io/),
2020
[validatejs](https://validatejs.org/),
21+
[GraphQL](http://graphql.org/),
22+
[DataLoaders](https://github.com/facebook/dataloader),
2123
by [w3tech](https://github.com/w3tecch)
2224

2325
## Why
@@ -40,15 +42,13 @@ Try it!! We are happy to hear your feedback or any kind of new features.
4042
- **API Documentation** thanks to [swagger](http://swagger.io/).
4143
- **API Monitoring** thanks to [express-status-monitor](https://github.com/RafalWilinski/express-status-monitor).
4244
- **Integrated Testing Tool** thanks to [Jest](https://facebook.github.io/jest).
45+
- **E2E API Testing** thanks to [supertest](https://github.com/visionmedia/supertest).
4346
- **Basic Security Features** thanks to [Helmet](https://helmetjs.github.io/).
4447
- **Easy event dispatching** thanks to [event-dispatch](https://github.com/pleerock/event-dispatch).
4548
- **Fast Database Building** with simple migration from [TypeORM](https://github.com/typeorm/typeorm).
4649
- **Easy Data Seeding** with our own factories.
47-
48-
### Comming soon
49-
50-
- **Custom Commands** are also available in our setup and really easy to use or even extend.
51-
- **Scaffolding Commands** will speed up your development tremendously as you should focus on business code and not scaffolding.
50+
- **GraphQL** provides as a awesome query language for our api [GraphQL](http://graphql.org/).
51+
- **DataLoaders** helps with performance thanks to caching and batching [DataLoaders](https://github.com/facebook/dataloader).
5252

5353
# Table of Contents
5454

@@ -96,7 +96,7 @@ Create a new database with the name you have in your `.env`-file.
9696
Then setup your application environment.
9797

9898
```bash
99-
npm start setup
99+
npm run setup
100100
```
101101

102102
> This installs all dependencies with yarn. After that it migrates the database and seeds some test data into it. So after that your development environment is ready to use.
@@ -128,7 +128,8 @@ All script are defined in the package.json file, but the most important ones are
128128
### Tests
129129

130130
- Run the unit tests using `npm start test` (There is also a vscode task for this called `test`).
131-
- Run the e2e tests using `npm start test:e2e` and don't forget to start your application and your [Auth0 Mock Server](https://github.com/hirsch88/auth0-mock-server).
131+
- Run the integration tests using `npm start test:integration`.
132+
- Run the e2e tests using `npm start test:e2e`.
132133

133134
### Running in dev mode
134135

@@ -165,9 +166,11 @@ The swagger and the monitor route can be altered in the `.env` file.
165166
| Route | Description |
166167
| -------------- | ----------- |
167168
| **/api** | Shows us the name, description and the version of the package.json |
169+
| **/graphql** | Route to the graphql editor or your query/mutations requests |
168170
| **/swagger** | This is the Swagger UI with our API documentation |
169171
| **/monitor** | Shows a small monitor page for the server |
170172
| **/api/users** | Example entity endpoint |
173+
| **/api/pets** | Example entity endpoint |
171174

172175
## Project Structure
173176

@@ -187,6 +190,9 @@ The swagger and the monitor route can be altered in the `.env` file.
187190
| **src/api/services/** | Service layer |
188191
| **src/api/subscribers/** | Event subscribers |
189192
| **src/api/validators/** | Custom validators, which can be used in the request classes |
193+
| **src/api/queries/** | GraphQL queries |
194+
| **src/api/mutations/** | GraphQL mutations |
195+
| **src/api/types/** | GraphQL types |
190196
| **src/api/** swagger.json | Swagger documentation |
191197
| **src/auth/** | Authentication checkers and services |
192198
| **src/core/** | The core features like logger and env variables |
@@ -199,9 +205,12 @@ The swagger and the monitor route can be altered in the `.env` file.
199205
| **src/types/** *.d.ts | Custom type definitions and files that aren't on DefinitelyTyped |
200206
| **test** | Tests |
201207
| **test/e2e/** *.test.ts | End-2-End tests (like e2e) |
208+
| **test/integration/** *.test.ts | Integration test with SQLite3 |
202209
| **test/unit/** *.test.ts | Unit tests |
203210
| .env.example | Environment configurations |
211+
| .env.test | Test environment configurations |
204212
| ormconfig.json | TypeORM configuration for the database. Used by seeds and the migration. (generated file) |
213+
| mydb.sql | SQLite database for integration tests. Ignored by git and only available after integration tests |
205214

206215
## Logging
207216

@@ -316,7 +325,7 @@ export class CreateUsers implements SeedsInterface {
316325
public async seed(factory: FactoryInterface): Promise<any> {
317326
await factory
318327
.get(User)
319-
.create(10);
328+
.createMany(10);
320329
}
321330

322331
}
@@ -330,7 +339,7 @@ export class CreateUsers implements SeedsInterface {
330339
public async seed(factory: FactoryInterface): Promise<any> {
331340
await factory
332341
.get(User, 'admin')
333-
.create(1);
342+
.create();
334343
}
335344

336345
}
@@ -344,7 +353,7 @@ await factory.get(User)
344353
.each(async (user: User) => {
345354

346355
const pets: Pet[] = await factory.get(Pet)
347-
.create(2);
356+
.createMany(2);
348357

349358
const petIds = pets.map((pet: Pet) => pet.Id);
350359
await user.pets().attach(petIds);
@@ -377,7 +386,12 @@ npm start db.seed
377386
| [Helmet](https://helmetjs.github.io/) | Helmet helps you secure your Express apps by setting various HTTP headers. It’s not a silver bullet, but it can help! |
378387
| [Auth0 API Documentation](https://auth0.com/docs/api/management/v2) | Authentification service |
379388
| [Jest](http://facebook.github.io/jest/) | Delightful JavaScript Testing Library for unit and e2e tests |
389+
| [supertest](https://github.com/visionmedia/supertest) | Super-agent driven library for testing node.js HTTP servers using a fluent API |
390+
| [nock](https://github.com/node-nock/nock) | HTTP mocking and expectations library |
380391
| [swagger Documentation](http://swagger.io/) | API Tool to describe and document your api. |
392+
| [SQLite Documentation](https://www.sitepoint.com/getting-started-sqlite3-basic-commands/) | Getting Started with SQLite3 – Basic Commands. |
393+
| [GraphQL Documentation](http://graphql.org/graphql-js/) | A query language for your API. |
394+
| [DataLoader Documentation](https://github.com/facebook/dataloader) | DataLoader is a generic utility to be used as part of your application's data fetching layer to provide a consistent API over various backends and reduce requests to those backends via batching and caching. |
381395
382396
## Related Projects
383397
File renamed without changes.

src/lib/ormconfig.ts renamed to commands/ormconfig.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import * as dotenv from 'dotenv';
22
dotenv.config();
33

44
import * as path from 'path';
5+
import * as Chalk from 'chalk';
56
import * as jsonfile from 'jsonfile';
6-
import { env } from '../core/env';
7+
import { env } from '../src/core/env';
78

89

910
const content = {
@@ -23,8 +24,13 @@ const content = {
2324
const filePath = path.join(process.cwd(), 'ormconfig.json');
2425
jsonfile.writeFile(filePath, content, { spaces: 2 }, (err) => {
2526
if (err === null) {
26-
console.log('Successfully generated ormconfig.json form the .env file');
27+
const chalk = Chalk.default;
28+
console.log('👍 ',
29+
chalk.gray.underline('generated:'),
30+
chalk.blue.bold('ormconfig.json')
31+
);
2732
} else {
2833
console.error('Failed to generate the ormconfig.json', err);
34+
process.exit(1);
2935
}
3036
});

commands/tsconfig.ts

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import * as path from 'path';
2+
import * as Chalk from 'chalk';
3+
import * as jsonfile from 'jsonfile';
4+
import * as tsconfig from '../tsconfig.json';
5+
6+
7+
const content: any = tsconfig;
8+
content.include = [
9+
'src/**/*',
10+
];
11+
12+
const filePath = path.join(process.cwd(), 'tsconfig.build.json');
13+
jsonfile.writeFile(filePath, content, { spaces: 2 }, (err) => {
14+
if (err === null) {
15+
const chalk = Chalk.default;
16+
console.log('👍 ',
17+
chalk.gray.underline('generated:'),
18+
chalk.blue.bold('tsconfig.build.json')
19+
);
20+
} else {
21+
console.error('Failed to generate the otsconfig.build.json', err);
22+
process.exit(1);
23+
}
24+
});

0 commit comments

Comments
 (0)