Skip to content

Commit 09454c2

Browse files
author
hirsch
committed
Merge branch 'release/3.2.0'
2 parents 428f0e9 + 2ac7994 commit 09454c2

38 files changed

+358
-654
lines changed

.env.example

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ CONTROLLERS=src/api/controllers/**/*Controller.ts
5151
MIDDLEWARES=src/api/middlewares/**/*Middleware.ts
5252
INTERCEPTORS=src/api/interceptors/**/*Interceptor.ts
5353
SUBSCRIBERS=src/api/subscribers/**/*Subscriber.ts
54-
QUERIES=src/api/queries/**/*Query.ts
55-
MUTATIONS=src/api/mutations/**/*Mutation.ts
54+
RESOLVERS=src/api/resolvers/**/*Resolver.ts
5655

5756
#
5857
# GraphQL

.env.test

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ CONTROLLERS=src/api/controllers/**/*Controller.ts
3333
MIDDLEWARES=src/api/middlewares/**/*Middleware.ts
3434
INTERCEPTORS=src/api/interceptors/**/*Interceptor.ts
3535
SUBSCRIBERS=src/api/subscribers/**/*Subscriber.ts
36-
QUERIES=src/api/queries/**/*Query.ts
37-
MUTATIONS=src/api/mutations/**/*Mutation.ts
36+
RESOLVERS=src/api/resolvers/**/*Resolver.ts
3837

3938
#
4039
# GraphQL

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ yarn-error.log
1515
.DS_Store
1616
Thumbs.db
1717
.tmp/
18+
src/api/schema.gql
1819

1920
# Typing #
2021
typings/

README.md

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Try it!! We are happy to hear your feedback or any kind of new features.
5555
- **Fast Database Building** with simple migration from [TypeORM](https://github.com/typeorm/typeorm).
5656
- **Easy Data Seeding** with our own factories.
5757
- **GraphQL** provides as a awesome query language for our api [GraphQL](http://graphql.org/).
58+
- **TypeGraphQL** thanks to [TypeGraphQL](https://19majkel94.github.io/type-graphql/) we have a some cool decorators to simplify the usage of GraphQL.
5859
- **DataLoaders** helps with performance thanks to caching and batching [DataLoaders](https://github.com/facebook/dataloader).
5960

6061
![divider](./w3tec-divider.png)
@@ -69,6 +70,8 @@ Try it!! We are happy to hear your feedback or any kind of new features.
6970
- [Logging](#-logging)
7071
- [Event Dispatching](#-event-dispatching)
7172
- [Seeding](#-seeding)
73+
- [GraphQL](#-graph-q-l)
74+
- [Docker](#-docker)
7275
- [Further Documentations](#-further-documentation)
7376
- [Related Projects](#-related-projects)
7477
- [License](#-license)
@@ -209,9 +212,9 @@ The swagger and the monitor route can be altered in the `.env` file.
209212
| **src/api/services/** | Service layer |
210213
| **src/api/subscribers/** | Event subscribers |
211214
| **src/api/validators/** | Custom validators, which can be used in the request classes |
212-
| **src/api/queries/** | GraphQL queries |
213-
| **src/api/mutations/** | GraphQL mutations |
214-
| **src/api/types/** | GraphQL types |
215+
| **src/api/resolvers/** | GraphQL resolvers (query, mutation & field-resolver) |
216+
| **src/api/types/** | GraphQL types ,input-types and scalar types |
217+
| **src/api/** schema.gql | Generated GraphQL schema |
215218
| **src/api/** swagger.json | Swagger documentation |
216219
| **src/auth/** | Authentication checkers and services |
217220
| **src/core/** | The core features like logger and env variables |
@@ -392,7 +395,56 @@ yarn start db.seed
392395
393396
![divider](./w3tec-divider.png)
394397
395-
## ❯ Run in Docker container
398+
## ❯ GraphQL
399+
400+
For the GraphQL part we used the library [TypeGraphQL](https://19majkel94.github.io/type-graphql/) to build awesome GraphQL API's.
401+
402+
The context(shown below) of the GraphQL is builded in the **graphqlLoader.ts** file. Inside of this loader we create a scoped container for each incoming request.
403+
404+
```typescript
405+
export interface Context {
406+
requestId: number;
407+
request: express.Request;
408+
response: express.Response;
409+
container: ContainerInstance;
410+
}
411+
```
412+
413+
### DataLoader
414+
415+
For the usage of the DataLoaders we created a annotation, which automatically creates and registers a new DataLoader to the scoped container.
416+
417+
Here is an example of the **PetResolver**.
418+
419+
```typescript
420+
import DataLoader from 'dataloader';
421+
import { DLoader } from '../../decorators/DLoader';
422+
...
423+
constructor(
424+
private petService: PetService,
425+
@Logger(__filename) private log: LoggerInterface,
426+
@DLoader(UserModel) private userLoader: DataLoader<string, UserModel>
427+
) { }
428+
...
429+
```
430+
431+
Or you could use the repository too.
432+
433+
```typescript
434+
@DLoader(UserRepository) private userLoader: DataLoader<string, UserModel>
435+
```
436+
437+
Or even use a custom method of your given repository.
438+
439+
```typescript
440+
@DLoader(PetRepository, {
441+
method: 'findByUserIds',
442+
key: 'userId',
443+
multiple: true,
444+
}) private petLoader: DataLoader<string, PetModel>
445+
```
446+
447+
## ❯ Docker
396448
397449
### Install Docker
398450

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "express-typescript-boilerplate",
3-
"version": "3.1.0",
3+
"version": "3.2.0",
44
"description": "A delightful way to building a Node.js RESTful API Services with beautiful code written in TypeScript",
55
"main": "src/app.ts",
66
"scripts": {
@@ -40,7 +40,7 @@
4040
"dependencies": {
4141
"bcrypt": "3.0.1",
4242
"chalk": "^2.4.1",
43-
"class-validator": "0.9.1",
43+
"class-validator": "^0.9.1",
4444
"commander": "^2.19.0",
4545
"compression": "^1.7.1",
4646
"copyfiles": "^2.1.0",
@@ -71,6 +71,7 @@
7171
"swagger-ui-express": "4.0.1",
7272
"ts-node": "7.0.1",
7373
"tslint": "^5.8.0",
74+
"type-graphql": "^0.15.0",
7475
"typedi": "0.8.0",
7576
"typeorm": "^0.2.5",
7677
"typeorm-seeding": "^1.0.0-beta.6",

src/api/Context.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import express from 'express';
2+
import { ContainerInstance } from 'typedi';
3+
4+
export interface Context {
5+
requestId: number;
6+
request: express.Request;
7+
response: express.Response;
8+
container: ContainerInstance;
9+
}

src/api/models/Pet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class Pet {
2121
name: 'user_id',
2222
nullable: true,
2323
})
24-
public userId: number;
24+
public userId: string;
2525

2626
@ManyToOne(type => User, user => user.pets)
2727
@JoinColumn({ name: 'user_id' })

src/api/mutations/CreatePetMutation.ts

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/api/queries/GetPetsQuery.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/api/queries/GetUsersQuery.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)