@aleleba/create-node-ts-graphql-server 1.3.0 → 1.4.0
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/README.md +1 -0
- package/package.json +4 -1
- package/schema.gql +28 -0
- package/src/GraphQL/resolvers/test.resolver.ts +18 -0
- package/src/GraphQL/schema/index.ts +8 -15
- package/src/GraphQL/schema/test.schema.ts +36 -0
- package/src/GraphQL/server.ts +3 -3
- package/src/controllers/controllerGraphQL/index.ts +2 -6
- package/src/index.ts +1 -0
- package/src/models/index.ts +3 -1
- package/src/tests/server/index.test.ts +21 -10
- package/tsconfig.json +4 -2
- package/src/GraphQL/resolvers/index.ts +0 -23
- package/src/GraphQL/schema/Test.gql +0 -13
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aleleba/create-node-ts-graphql-server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Node with Typescript and GraphQL Server",
|
|
5
5
|
"bin": "./bin/cli.js",
|
|
6
6
|
"main": "index.js",
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@graphql-tools/schema": "^9.0.16",
|
|
37
37
|
"body-parser": "^1.20.2",
|
|
38
|
+
"class-validator": "^0.14.0",
|
|
38
39
|
"cookie-parser": "^1.4.6",
|
|
39
40
|
"cors": "^2.8.5",
|
|
40
41
|
"dotenv": "^16.0.3",
|
|
@@ -45,6 +46,8 @@
|
|
|
45
46
|
"graphql-subscriptions": "^2.0.0",
|
|
46
47
|
"graphql-tools": "^8.3.18",
|
|
47
48
|
"graphql-ws": "^5.12.0",
|
|
49
|
+
"reflect-metadata": "^0.1.13",
|
|
50
|
+
"type-graphql": "^2.0.0-beta.1",
|
|
48
51
|
"web-push": "^3.5.0",
|
|
49
52
|
"ws": "^8.12.1"
|
|
50
53
|
},
|
package/schema.gql
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# -----------------------------------------------
|
|
2
|
+
# !!! THIS FILE WAS GENERATED BY TYPE-GRAPHQL !!!
|
|
3
|
+
# !!! DO NOT MODIFY THIS FILE BY YOURSELF !!!
|
|
4
|
+
# -----------------------------------------------
|
|
5
|
+
|
|
6
|
+
type Mutation {
|
|
7
|
+
testMutation: TestMutation!
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
type Query {
|
|
11
|
+
test: Test!
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
type Test {
|
|
15
|
+
text: Text!
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
type TestMutation {
|
|
19
|
+
textMutation(text: String!): TextMutation!
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
type Text {
|
|
23
|
+
text: String!
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
type TextMutation {
|
|
27
|
+
text: String!
|
|
28
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import { Query, Resolver, Mutation, Arg } from 'type-graphql';
|
|
4
|
+
import { Test, TestMutation } from '@GraphQL/schema/test.schema';
|
|
5
|
+
|
|
6
|
+
@Resolver(() => Test)
|
|
7
|
+
export class TestResolver {
|
|
8
|
+
@Query(() => Test)
|
|
9
|
+
async test() {
|
|
10
|
+
return {};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
@Mutation(() => TestMutation)
|
|
14
|
+
async testMutation() {
|
|
15
|
+
return {};
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
import resolvers from'@GraphQL/resolvers';
|
|
3
|
-
import Test from '@GraphQL/schema/Test.gql';
|
|
1
|
+
'use strict'
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
type Query {
|
|
8
|
-
test: Test
|
|
9
|
-
}
|
|
10
|
-
type Mutation {
|
|
11
|
-
testMutation: TestMutation
|
|
12
|
-
}
|
|
13
|
-
`;
|
|
3
|
+
import { buildSchemaSync } from "type-graphql"
|
|
4
|
+
import { TestResolver } from "@GraphQL/resolvers/test.resolver";
|
|
14
5
|
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
6
|
+
const schema = buildSchemaSync({
|
|
7
|
+
resolvers: [TestResolver],
|
|
8
|
+
emitSchemaFile: true,
|
|
9
|
+
})
|
|
10
|
+
export default schema
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import { Field, ObjectType, Arg } from "type-graphql";
|
|
4
|
+
import { getTest, addText } from '@controllerGraphQL';
|
|
5
|
+
|
|
6
|
+
@ObjectType()
|
|
7
|
+
export class Test {
|
|
8
|
+
@Field(() => Text)
|
|
9
|
+
async text(){
|
|
10
|
+
return {
|
|
11
|
+
text: await getTest({})
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@ObjectType()
|
|
17
|
+
export class Text {
|
|
18
|
+
@Field()
|
|
19
|
+
text?: string
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@ObjectType()
|
|
23
|
+
export class TestMutation {
|
|
24
|
+
@Field(type => TextMutation)
|
|
25
|
+
async textMutation(@Arg('text') text?: string){
|
|
26
|
+
return {
|
|
27
|
+
text: await addText({text})
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@ObjectType()
|
|
33
|
+
export class TextMutation {
|
|
34
|
+
@Field()
|
|
35
|
+
text?: string
|
|
36
|
+
}
|
package/src/GraphQL/server.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
+
|
|
2
3
|
import express from 'express'; //express
|
|
3
4
|
import { graphqlHTTP } from 'express-graphql';
|
|
4
5
|
import { config } from '@config';
|
|
5
|
-
import schema from '@GraphQL/schema';
|
|
6
|
+
import schema from '@src/GraphQL/schema';
|
|
7
|
+
|
|
6
8
|
|
|
7
9
|
const server = express.Router();//Router de Express
|
|
8
10
|
|
|
@@ -17,8 +19,6 @@ server.use(
|
|
|
17
19
|
}),
|
|
18
20
|
);
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
|
|
22
22
|
// DO NOT DO app.listen() unless we're testing this directly
|
|
23
23
|
if (require.main === module) {
|
|
24
24
|
const app = express();
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
import { getTestModel, addTextModel } from '@models';
|
|
4
|
+
import { TextMutation } from '@src/GraphQL/schema/test.schema';
|
|
4
5
|
|
|
5
6
|
// eslint-disable-next-line
|
|
6
7
|
export const getTest = async ({}) => {
|
|
@@ -8,11 +9,6 @@ export const getTest = async ({}) => {
|
|
|
8
9
|
};
|
|
9
10
|
|
|
10
11
|
// eslint-disable-next-line
|
|
11
|
-
export const addText = async ({
|
|
12
|
-
rootValue: any
|
|
13
|
-
args: { text: string }
|
|
14
|
-
context: any
|
|
15
|
-
}) => {
|
|
16
|
-
const text = args.text;
|
|
12
|
+
export const addText = async ({ text }: TextMutation) => {
|
|
17
13
|
return addTextModel({ text });
|
|
18
14
|
};
|
package/src/index.ts
CHANGED
package/src/models/index.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
import { TextMutation } from "@GraphQL/schema/test.schema";
|
|
4
|
+
|
|
3
5
|
export const getTestModel = async () => {
|
|
4
6
|
return 'This is the text response for Test Query from a model';
|
|
5
7
|
};
|
|
6
8
|
|
|
7
|
-
export const addTextModel = async ({ text }:
|
|
9
|
+
export const addTextModel = async ({ text }: TextMutation) => {
|
|
8
10
|
return `Simulate to insert some text: ${text} from a model`;
|
|
9
11
|
};
|
|
@@ -2,17 +2,21 @@ import server from '@src';
|
|
|
2
2
|
import supertest from 'supertest';
|
|
3
3
|
describe('global server tests', () => {
|
|
4
4
|
let request: supertest.SuperTest<supertest.Test>;
|
|
5
|
-
beforeEach(() => {
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
beforeEach( async () => {
|
|
6
|
+
request = await supertest(server);
|
|
7
|
+
});
|
|
8
|
+
|
|
8
9
|
it('should return Test data from test Query', async () => {
|
|
9
10
|
const bodyResponse = {
|
|
10
11
|
data: {
|
|
11
|
-
test: {
|
|
12
|
+
test: {
|
|
13
|
+
text: {
|
|
14
|
+
text: "This is the text response for Test Query from a model"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
12
17
|
}
|
|
13
18
|
}
|
|
14
|
-
|
|
15
|
-
const response = await request.get('/graphql?query=%7B%0A%20%20test%7B%0A%20%20%20%20test%0A%20%20%7D%0A%7D%0A')
|
|
19
|
+
const response = await request.get('/graphql?query=%7B%0A%20%20test%7B%0A%20%20%20%20text%7B%0A%20%20%20%20%20%20text%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A%0A')
|
|
16
20
|
.set('Accept', 'application/json')
|
|
17
21
|
expect(response.status).toEqual(200);
|
|
18
22
|
expect(response.body).toEqual(bodyResponse);
|
|
@@ -21,14 +25,21 @@ describe('global server tests', () => {
|
|
|
21
25
|
it('should return Test data from test Mutation', async () => {
|
|
22
26
|
const bodyResponse = {
|
|
23
27
|
data: {
|
|
24
|
-
|
|
25
|
-
|
|
28
|
+
testMutation: {
|
|
29
|
+
textMutation: {
|
|
30
|
+
text: "Simulate to insert some text: testing text from a model"
|
|
26
31
|
}
|
|
32
|
+
}
|
|
27
33
|
}
|
|
28
34
|
}
|
|
29
|
-
|
|
30
35
|
const response = await request.post('/graphql')
|
|
31
|
-
.send({
|
|
36
|
+
.send({'query': `mutation{
|
|
37
|
+
testMutation{
|
|
38
|
+
textMutation(text: "testing text"){
|
|
39
|
+
text
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}`})
|
|
32
43
|
.set('Accept', 'application/json')
|
|
33
44
|
expect(response.status).toEqual(200);
|
|
34
45
|
expect(response.body).toEqual(bodyResponse);
|
package/tsconfig.json
CHANGED
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
"compilerOptions": {
|
|
3
3
|
"module": "commonjs",
|
|
4
4
|
"esModuleInterop": true,
|
|
5
|
-
"target": "
|
|
5
|
+
"target": "es2018",
|
|
6
6
|
"moduleResolution": "node",
|
|
7
7
|
"sourceMap": true,
|
|
8
8
|
"typeRoots" : ["./src/@types", "./node_modules/@types"],
|
|
9
9
|
"strict": true,
|
|
10
10
|
"forceConsistentCasingInFileNames": true,
|
|
11
|
+
"emitDecoratorMetadata": true,
|
|
12
|
+
"experimentalDecorators": true,
|
|
11
13
|
"baseUrl": ".",
|
|
12
14
|
"paths": {
|
|
13
15
|
"@src/*": ["src/*"],
|
|
@@ -26,5 +28,5 @@
|
|
|
26
28
|
"@config": ["config"]
|
|
27
29
|
}
|
|
28
30
|
},
|
|
29
|
-
"lib": ["
|
|
31
|
+
"lib": ["es2018", "esnext.asynciterable"]
|
|
30
32
|
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
import { getTest, addText } from '@controllerGraphQL';
|
|
4
|
-
|
|
5
|
-
// A map of functions which return data for the schema.
|
|
6
|
-
const resolvers = {
|
|
7
|
-
Query: {
|
|
8
|
-
// eslint-disable-next-line
|
|
9
|
-
test: (rootValue: any, args: any, context: any) => ({}),
|
|
10
|
-
},
|
|
11
|
-
Mutation: {
|
|
12
|
-
// eslint-disable-next-line
|
|
13
|
-
testMutation: (rootValue: any, args: any, context: any) => ({}),
|
|
14
|
-
},
|
|
15
|
-
Test: {
|
|
16
|
-
test: (rootValue: any, args: any, context: any) => getTest({rootValue, args, context})
|
|
17
|
-
},
|
|
18
|
-
TestMutation: {
|
|
19
|
-
testMutation: (rootValue: any, args: any, context: any) => addText({rootValue, args, context})
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export default resolvers;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
module.exports = `
|
|
2
|
-
|
|
3
|
-
"""Test Query"""
|
|
4
|
-
type Test {
|
|
5
|
-
test: String
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
"""Esta es la Data de LogIn, Si los datos no son correctos devuelve el usuario Null y la conexion en False"""
|
|
9
|
-
type TestMutation {
|
|
10
|
-
testMutation(text: String): String
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
`
|