@tsed/typegraphql 6.102.0 → 6.102.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.mocharc.js +2 -2
- package/package.json +4 -4
- package/readme.md +22 -20
- package/tsconfig.compile.esm.json +1 -12
package/.mocharc.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/typegraphql",
|
|
3
|
-
"version": "6.102.
|
|
3
|
+
"version": "6.102.4",
|
|
4
4
|
"description": "TypeGraphQL package for Ts.ED framework, based on Apollo-server-core and Type-graphql",
|
|
5
5
|
"private": false,
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -20,12 +20,12 @@
|
|
|
20
20
|
"test": "cross-env NODE_ENV=test nyc mocha"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@tsed/apollo": "6.102.
|
|
23
|
+
"@tsed/apollo": "6.102.4",
|
|
24
24
|
"tslib": "2.2.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@tsed/common": "6.102.
|
|
28
|
-
"@tsed/core": "6.102.
|
|
27
|
+
"@tsed/common": "6.102.4",
|
|
28
|
+
"@tsed/core": "6.102.4",
|
|
29
29
|
"@types/graphql": "^14.5.0",
|
|
30
30
|
"class-validator": "~0.13.1",
|
|
31
31
|
"graphql-passport": "0.6.3",
|
package/readme.md
CHANGED
|
@@ -39,6 +39,7 @@ for the decorators.
|
|
|
39
39
|
## Installation
|
|
40
40
|
|
|
41
41
|
To begin, install the TypeGraphQL module for TS.ED:
|
|
42
|
+
|
|
42
43
|
```bash
|
|
43
44
|
npm install --save @tsed/typegraphql type-graphql graphql@15
|
|
44
45
|
npm install --save apollo-datasource apollo-datasource-rest apollo-server-express
|
|
@@ -49,12 +50,12 @@ Now, we can configure the Ts.ED server by importing `@tsed/typegraphql` in your
|
|
|
49
50
|
|
|
50
51
|
```typescript
|
|
51
52
|
import {Configuration} from "@tsed/common";
|
|
52
|
-
import "@tsed/typegraphql";
|
|
53
|
+
import "@tsed/typegraphql";
|
|
53
54
|
|
|
54
55
|
@Configuration({
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
resolvers:[]
|
|
56
|
+
graphql: {
|
|
57
|
+
server1: {
|
|
58
|
+
resolvers: []
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
61
|
})
|
|
@@ -73,12 +74,12 @@ import {ApolloServer} from "apollo-server-express";
|
|
|
73
74
|
@Service()
|
|
74
75
|
export class UsersService implements AfterRoutesInit {
|
|
75
76
|
private server: ApolloServer;
|
|
76
|
-
|
|
77
|
+
|
|
77
78
|
@Inject()
|
|
78
|
-
typeGraphQLService: TypeGraphQLService
|
|
79
|
-
|
|
79
|
+
typeGraphQLService: TypeGraphQLService;
|
|
80
|
+
|
|
80
81
|
$afterRoutesInit() {
|
|
81
|
-
|
|
82
|
+
this.server = this.typeGraphQLService.get("server1");
|
|
82
83
|
}
|
|
83
84
|
}
|
|
84
85
|
```
|
|
@@ -86,6 +87,7 @@ export class UsersService implements AfterRoutesInit {
|
|
|
86
87
|
For more information about ApolloServer look his documentation [here](https://www.apollographql.com/docs/apollo-server/api/apollo-server.html);
|
|
87
88
|
|
|
88
89
|
## Type-graphql
|
|
90
|
+
|
|
89
91
|
### Types
|
|
90
92
|
|
|
91
93
|
We want to get equivalent of this type described in SDL:
|
|
@@ -115,35 +117,36 @@ class Recipe {
|
|
|
115
117
|
Then we decorate the class and it properties with decorators:
|
|
116
118
|
|
|
117
119
|
```typescript
|
|
118
|
-
import {ObjectType, ID, Field} from "type-graphql"
|
|
120
|
+
import {ObjectType, ID, Field} from "type-graphql";
|
|
119
121
|
|
|
120
122
|
@ObjectType()
|
|
121
123
|
export class Recipe {
|
|
122
|
-
@Field(type => ID)
|
|
124
|
+
@Field((type) => ID)
|
|
123
125
|
id: string;
|
|
124
126
|
|
|
125
127
|
@Field()
|
|
126
128
|
title: string;
|
|
127
129
|
|
|
128
|
-
@Field({
|
|
130
|
+
@Field({nullable: true})
|
|
129
131
|
description?: string;
|
|
130
132
|
|
|
131
133
|
@Field()
|
|
132
134
|
creationDate: Date;
|
|
133
135
|
|
|
134
|
-
@Field(type => [String])
|
|
136
|
+
@Field((type) => [String])
|
|
135
137
|
ingredients: string[];
|
|
136
138
|
}
|
|
137
139
|
```
|
|
140
|
+
|
|
138
141
|
The detailed rules when to use nullable, array and others are described in [fields and types docs](https://19majkel94.github.io/type-graphql/docs/types-and-fields.html).
|
|
139
142
|
|
|
140
|
-
###
|
|
143
|
+
### Resolvers
|
|
141
144
|
|
|
142
145
|
After that we want to create typical crud queries and mutation. To do that we create the resolver (controller) class that will have injected RecipeService in constructor:
|
|
143
146
|
|
|
144
147
|
```typescript
|
|
145
148
|
import {Resolver, Query, Arg, Args, Mutation, Authorized, Ctx} from "type-graphql";
|
|
146
|
-
import {ResolverService} from "@tsed/typegraphql"
|
|
149
|
+
import {ResolverService} from "@tsed/typegraphql";
|
|
147
150
|
import {Recipe} from "../types/Recipe";
|
|
148
151
|
import {RecipeService} from "../services/RecipeService";
|
|
149
152
|
import {RecipeNotFoundError} from "../errors/RecipeNotFoundError";
|
|
@@ -152,7 +155,7 @@ import {RecipeNotFoundError} from "../errors/RecipeNotFoundError";
|
|
|
152
155
|
export class RecipeResolver {
|
|
153
156
|
constructor(private recipeService: RecipeService) {}
|
|
154
157
|
|
|
155
|
-
@Query(returns => Recipe)
|
|
158
|
+
@Query((returns) => Recipe)
|
|
156
159
|
async recipe(@Arg("id") id: string) {
|
|
157
160
|
const recipe = await this.recipeService.findById(id);
|
|
158
161
|
if (recipe === undefined) {
|
|
@@ -161,26 +164,25 @@ export class RecipeResolver {
|
|
|
161
164
|
return recipe;
|
|
162
165
|
}
|
|
163
166
|
|
|
164
|
-
@Query(returns => [Recipe])
|
|
165
|
-
recipes(@Args() {
|
|
166
|
-
return this.recipeService.findAll({
|
|
167
|
+
@Query((returns) => [Recipe])
|
|
168
|
+
recipes(@Args() {skip, take}: RecipesArgs) {
|
|
169
|
+
return this.recipeService.findAll({skip, take});
|
|
167
170
|
}
|
|
168
171
|
}
|
|
169
172
|
```
|
|
170
173
|
|
|
171
174
|
## Contributors
|
|
175
|
+
|
|
172
176
|
Please read [contributing guidelines here](https://tsed.io/CONTRIBUTING.html)
|
|
173
177
|
|
|
174
178
|
<a href="https://github.com/tsedio/ts-express-decorators/graphs/contributors"><img src="https://opencollective.com/tsed/contributors.svg?width=890" /></a>
|
|
175
179
|
|
|
176
|
-
|
|
177
180
|
## Backers
|
|
178
181
|
|
|
179
182
|
Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/tsed#backer)]
|
|
180
183
|
|
|
181
184
|
<a href="https://opencollective.com/tsed#backers" target="_blank"><img src="https://opencollective.com/tsed/backers.svg?width=890"></a>
|
|
182
185
|
|
|
183
|
-
|
|
184
186
|
## Sponsors
|
|
185
187
|
|
|
186
188
|
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/tsed#sponsor)]
|
|
@@ -8,16 +8,5 @@
|
|
|
8
8
|
"declaration": true,
|
|
9
9
|
"declarationDir": "./lib/types"
|
|
10
10
|
},
|
|
11
|
-
"exclude": [
|
|
12
|
-
"node_modules",
|
|
13
|
-
"test",
|
|
14
|
-
"lib",
|
|
15
|
-
"benchmark",
|
|
16
|
-
"coverage",
|
|
17
|
-
"spec",
|
|
18
|
-
"**/*.benchmark.ts",
|
|
19
|
-
"**/*.spec.ts",
|
|
20
|
-
"keys",
|
|
21
|
-
"jest.config.js"
|
|
22
|
-
]
|
|
11
|
+
"exclude": ["node_modules", "test", "lib", "benchmark", "coverage", "spec", "**/*.benchmark.ts", "**/*.spec.ts", "keys", "jest.config.js"]
|
|
23
12
|
}
|