@aleleba/create-node-ts-graphql-server 1.2.10 → 1.3.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 -1
- package/jest.config.js +9 -0
- package/package.json +12 -5
- package/src/GraphQL/resolvers/index.ts +5 -5
- package/src/GraphQL/schema/index.ts +2 -2
- package/src/GraphQL/server.ts +5 -4
- package/src/controllers/controllerGraphQL/index.ts +7 -3
- package/src/index.ts +7 -7
- package/src/models/index.ts +1 -1
- package/src/tests/server/index.test.ts +4 -4
- package/tsconfig.json +19 -0
- package/webpack.config.dev.ts +4 -8
- package/webpack.config.ts +4 -8
package/README.md
CHANGED
package/jest.config.js
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
|
+
const { pathsToModuleNameMapper } = require('ts-jest');
|
|
2
|
+
const { compilerOptions } = require('./tsconfig');
|
|
3
|
+
|
|
4
|
+
const aliases = pathsToModuleNameMapper(compilerOptions.paths, {
|
|
5
|
+
prefix: '<rootDir>'
|
|
6
|
+
});
|
|
7
|
+
|
|
1
8
|
module.exports = {
|
|
2
9
|
testEnvironment: 'node',
|
|
3
10
|
transform: {
|
|
4
11
|
"^.+\\.ts$": "ts-jest"
|
|
12
|
+
},moduleNameMapper: {
|
|
13
|
+
...aliases,
|
|
5
14
|
},
|
|
6
15
|
};
|
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.3.0",
|
|
4
4
|
"description": "Node with Typescript and GraphQL Server",
|
|
5
5
|
"bin": "./bin/cli.js",
|
|
6
6
|
"main": "index.js",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"graphql-playground-middleware-express": "^1.7.23",
|
|
45
45
|
"graphql-subscriptions": "^2.0.0",
|
|
46
46
|
"graphql-tools": "^8.3.18",
|
|
47
|
-
"graphql-ws": "^5.
|
|
47
|
+
"graphql-ws": "^5.12.0",
|
|
48
48
|
"web-push": "^3.5.0",
|
|
49
49
|
"ws": "^8.12.1"
|
|
50
50
|
},
|
|
@@ -53,10 +53,16 @@
|
|
|
53
53
|
"@babel/preset-env": "^7.20.2",
|
|
54
54
|
"@babel/preset-typescript": "^7.21.0",
|
|
55
55
|
"@babel/register": "^7.21.0",
|
|
56
|
+
"@types/body-parser": "^1.19.2",
|
|
57
|
+
"@types/cookie-parser": "^1.4.3",
|
|
58
|
+
"@types/cors": "^2.8.13",
|
|
59
|
+
"@types/express": "^4.17.17",
|
|
56
60
|
"@types/jest": "^29.4.0",
|
|
57
|
-
"@types/node": "^18.14.
|
|
61
|
+
"@types/node": "^18.14.6",
|
|
62
|
+
"@types/supertest": "^2.0.12",
|
|
58
63
|
"@types/webpack": "^5.28.0",
|
|
59
64
|
"@types/webpack-node-externals": "^3.0.0",
|
|
65
|
+
"@types/ws": "^8.5.4",
|
|
60
66
|
"@typescript-eslint/eslint-plugin": "^5.54.0",
|
|
61
67
|
"@typescript-eslint/parser": "^5.54.0",
|
|
62
68
|
"babel-loader": "^9.1.2",
|
|
@@ -64,8 +70,9 @@
|
|
|
64
70
|
"compression-webpack-plugin": "^10.0.0",
|
|
65
71
|
"eslint": "^8.35.0",
|
|
66
72
|
"eslint-webpack-plugin": "^4.0.0",
|
|
67
|
-
"jest": "^29.
|
|
68
|
-
"nodemon": "^2.0.
|
|
73
|
+
"jest": "^29.5.0",
|
|
74
|
+
"nodemon": "^2.0.21",
|
|
75
|
+
"resolve-ts-aliases": "^1.0.1",
|
|
69
76
|
"supertest": "^6.3.3",
|
|
70
77
|
"ts-jest": "^29.0.5",
|
|
71
78
|
"ts-loader": "^9.4.2",
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
import { getTest, addText } from '
|
|
3
|
+
import { getTest, addText } from '@controllerGraphQL';
|
|
4
4
|
|
|
5
5
|
// A map of functions which return data for the schema.
|
|
6
6
|
const resolvers = {
|
|
7
7
|
Query: {
|
|
8
8
|
// eslint-disable-next-line
|
|
9
|
-
test: (rootValue, args, context) => ({}),
|
|
9
|
+
test: (rootValue: any, args: any, context: any) => ({}),
|
|
10
10
|
},
|
|
11
11
|
Mutation: {
|
|
12
12
|
// eslint-disable-next-line
|
|
13
|
-
testMutation: (rootValue, args, context) => ({}),
|
|
13
|
+
testMutation: (rootValue: any, args: any, context: any) => ({}),
|
|
14
14
|
},
|
|
15
15
|
Test: {
|
|
16
|
-
test: (rootValue, args, context) => getTest({rootValue, args, context})
|
|
16
|
+
test: (rootValue: any, args: any, context: any) => getTest({rootValue, args, context})
|
|
17
17
|
},
|
|
18
18
|
TestMutation: {
|
|
19
|
-
testMutation: (rootValue, args, context) => addText({rootValue, args, context})
|
|
19
|
+
testMutation: (rootValue: any, args: any, context: any) => addText({rootValue, args, context})
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
22
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { makeExecutableSchema } from '@graphql-tools/schema';
|
|
2
|
-
import resolvers from'
|
|
3
|
-
import Test from '
|
|
2
|
+
import resolvers from'@GraphQL/resolvers';
|
|
3
|
+
import Test from '@GraphQL/schema/Test.gql';
|
|
4
4
|
|
|
5
5
|
// The GraphQL schema
|
|
6
6
|
const rootTypes = `
|
package/src/GraphQL/server.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
import express from 'express'; //express
|
|
3
3
|
import { graphqlHTTP } from 'express-graphql';
|
|
4
|
-
import { config } from '
|
|
5
|
-
import schema from '
|
|
4
|
+
import { config } from '@config';
|
|
5
|
+
import schema from '@GraphQL/schema';
|
|
6
6
|
|
|
7
7
|
const server = express.Router();//Router de Express
|
|
8
8
|
|
|
@@ -21,8 +21,9 @@ server.use(
|
|
|
21
21
|
|
|
22
22
|
// DO NOT DO app.listen() unless we're testing this directly
|
|
23
23
|
if (require.main === module) {
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
const app = express();
|
|
25
|
+
app.listen((process.env.PORT || 4000), () => {
|
|
26
|
+
console.log(`Iniciando Express en el puerto 4000`); /*${app.get('port')}*/
|
|
26
27
|
});
|
|
27
28
|
}
|
|
28
29
|
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
import { getTestModel, addTextModel } from '
|
|
3
|
+
import { getTestModel, addTextModel } from '@models';
|
|
4
4
|
|
|
5
5
|
// eslint-disable-next-line
|
|
6
|
-
export const getTest = async ({
|
|
6
|
+
export const getTest = async ({}) => {
|
|
7
7
|
return getTestModel();
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
// eslint-disable-next-line
|
|
11
|
-
export const addText = async ({
|
|
11
|
+
export const addText = async ({args}: {
|
|
12
|
+
rootValue: any
|
|
13
|
+
args: { text: string }
|
|
14
|
+
context: any
|
|
15
|
+
}) => {
|
|
12
16
|
const text = args.text;
|
|
13
17
|
return addTextModel({ text });
|
|
14
18
|
};
|
package/src/index.ts
CHANGED
|
@@ -6,17 +6,17 @@ import cors from 'cors';
|
|
|
6
6
|
import cookieParser from 'cookie-parser';
|
|
7
7
|
import { useServer } from 'graphql-ws/lib/use/ws';
|
|
8
8
|
import { execute, subscribe } from 'graphql';
|
|
9
|
-
import GraphQLserver from '
|
|
9
|
+
import GraphQLserver from '@GraphQL/server';// Server of GraphQL,
|
|
10
10
|
import expressPlayground from 'graphql-playground-middleware-express';
|
|
11
|
-
import schema from '
|
|
12
|
-
import { config } from '
|
|
13
|
-
import apiRouter from '
|
|
11
|
+
import schema from '@GraphQL/schema';
|
|
12
|
+
import { config } from '@config';
|
|
13
|
+
import apiRouter from '@routes';
|
|
14
14
|
|
|
15
15
|
const app = express(), //creating app
|
|
16
16
|
whitelist = config.WHITELIST_URLS,
|
|
17
17
|
corsOptions = {
|
|
18
|
-
origin: function (origin, callback) {
|
|
19
|
-
if (whitelist.indexOf(origin) !== -1 || !origin) {
|
|
18
|
+
origin: function (origin: string | undefined, callback: (arg0: Error | null, arg1?: boolean) => void) {
|
|
19
|
+
if (whitelist.indexOf(origin as string) !== -1 || !origin) {
|
|
20
20
|
callback(null, true);
|
|
21
21
|
} else {
|
|
22
22
|
callback(new Error('Not allowed by CORS'));
|
|
@@ -29,7 +29,7 @@ const app = express(), //creating app
|
|
|
29
29
|
app
|
|
30
30
|
.use(cookieParser())
|
|
31
31
|
.use(express.urlencoded({limit: '500mb', extended: true}))
|
|
32
|
-
.use(express.json({limit: '500mb'
|
|
32
|
+
.use(express.json({limit: '500mb'}))
|
|
33
33
|
.use(cors(corsOptions))
|
|
34
34
|
.use(apiRouter)//Routes de App
|
|
35
35
|
.use('/graphql', GraphQLserver);//Server of Graphql
|
package/src/models/index.ts
CHANGED
|
@@ -4,6 +4,6 @@ export const getTestModel = async () => {
|
|
|
4
4
|
return 'This is the text response for Test Query from a model';
|
|
5
5
|
};
|
|
6
6
|
|
|
7
|
-
export const addTextModel = async ({ text }) => {
|
|
7
|
+
export const addTextModel = async ({ text }: {text: string}) => {
|
|
8
8
|
return `Simulate to insert some text: ${text} from a model`;
|
|
9
9
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import server from '
|
|
1
|
+
import server from '@src';
|
|
2
2
|
import supertest from 'supertest';
|
|
3
3
|
describe('global server tests', () => {
|
|
4
|
-
let request
|
|
4
|
+
let request: supertest.SuperTest<supertest.Test>;
|
|
5
5
|
beforeEach(() => {
|
|
6
6
|
request = supertest(server);
|
|
7
7
|
});
|
|
8
|
-
|
|
8
|
+
it('should return Test data from test Query', async () => {
|
|
9
9
|
const bodyResponse = {
|
|
10
10
|
data: {
|
|
11
11
|
test: { test: 'This is the text response for Test Query from a model' }
|
|
@@ -18,7 +18,7 @@ describe('global server tests', () => {
|
|
|
18
18
|
expect(response.body).toEqual(bodyResponse);
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
it('should return Test data from test Mutation', async () => {
|
|
22
22
|
const bodyResponse = {
|
|
23
23
|
data: {
|
|
24
24
|
testMutation: {
|
package/tsconfig.json
CHANGED
|
@@ -6,6 +6,25 @@
|
|
|
6
6
|
"moduleResolution": "node",
|
|
7
7
|
"sourceMap": true,
|
|
8
8
|
"typeRoots" : ["./src/@types", "./node_modules/@types"],
|
|
9
|
+
"strict": true,
|
|
10
|
+
"forceConsistentCasingInFileNames": true,
|
|
11
|
+
"baseUrl": ".",
|
|
12
|
+
"paths": {
|
|
13
|
+
"@src/*": ["src/*"],
|
|
14
|
+
"@src": ["src"],
|
|
15
|
+
"@routes*": ["src/routes/*"],
|
|
16
|
+
"@routes": ["src/routes"],
|
|
17
|
+
"@controllers/*": ["src/controllers/*"],
|
|
18
|
+
"@controllers": ["src/controllers"],
|
|
19
|
+
"@models/*": ["src/models/*"],
|
|
20
|
+
"@models": ["src/models"],
|
|
21
|
+
"@controllerGraphQL/*": ["src/controllers/controllerGraphQL/*"],
|
|
22
|
+
"@controllerGraphQL": ["src/controllers/controllerGraphQL"],
|
|
23
|
+
"@GraphQL/*": ["src/GraphQL/*"],
|
|
24
|
+
"@GraphQL": ["src/GraphQL"],
|
|
25
|
+
"@config/*": ["config/*"],
|
|
26
|
+
"@config": ["config"]
|
|
27
|
+
}
|
|
9
28
|
},
|
|
10
29
|
"lib": ["es2015"]
|
|
11
30
|
}
|
package/webpack.config.dev.ts
CHANGED
|
@@ -4,11 +4,13 @@ import { CleanWebpackPlugin } from 'clean-webpack-plugin';
|
|
|
4
4
|
import ESLintPlugin from 'eslint-webpack-plugin';
|
|
5
5
|
import nodeExternals from 'webpack-node-externals';
|
|
6
6
|
import WebpackShellPluginNext from 'webpack-shell-plugin-next';
|
|
7
|
+
import { resolveTsAliases } from 'resolve-ts-aliases';
|
|
7
8
|
import { deFaultValues } from './config';
|
|
8
9
|
|
|
9
10
|
const ROOT_DIR = path.resolve(__dirname);
|
|
10
|
-
const resolvePath = (...args) => path.resolve(ROOT_DIR, ...args);
|
|
11
|
+
const resolvePath = (...args: string[]) => path.resolve(ROOT_DIR, ...args);
|
|
11
12
|
const BUILD_DIR = resolvePath('build');
|
|
13
|
+
const alias = resolveTsAliases(path.resolve('tsconfig.json'));
|
|
12
14
|
|
|
13
15
|
const config = {
|
|
14
16
|
entry: './src/index.ts',
|
|
@@ -21,13 +23,7 @@ const config = {
|
|
|
21
23
|
},
|
|
22
24
|
resolve: {
|
|
23
25
|
extensions: ['.js', '.ts', '.json', '.gql'],
|
|
24
|
-
alias
|
|
25
|
-
'@controllers': path.resolve(__dirname, 'controllers/'),
|
|
26
|
-
'@models': path.resolve(__dirname, 'models/'),
|
|
27
|
-
'@controllerGraphQL': path.resolve(__dirname, 'controllers/controllerGraphQL/'),
|
|
28
|
-
'@GraphQL': path.resolve(__dirname, 'GraphQL/'),
|
|
29
|
-
'@config': path.resolve(__dirname, 'config/'),
|
|
30
|
-
}
|
|
26
|
+
alias,
|
|
31
27
|
},
|
|
32
28
|
mode: 'development',
|
|
33
29
|
module: {
|
package/webpack.config.ts
CHANGED
|
@@ -4,11 +4,13 @@ import TerserPlugin from 'terser-webpack-plugin';
|
|
|
4
4
|
import { CleanWebpackPlugin } from 'clean-webpack-plugin';
|
|
5
5
|
import ESLintPlugin from 'eslint-webpack-plugin';
|
|
6
6
|
import nodeExternals from 'webpack-node-externals';
|
|
7
|
+
import { resolveTsAliases } from 'resolve-ts-aliases';
|
|
7
8
|
import { deFaultValues } from './config';
|
|
8
9
|
|
|
9
10
|
const ROOT_DIR = path.resolve(__dirname);
|
|
10
|
-
const resolvePath = (...args) => path.resolve(ROOT_DIR, ...args);
|
|
11
|
+
const resolvePath = (...args: string[]) => path.resolve(ROOT_DIR, ...args);
|
|
11
12
|
const BUILD_DIR = resolvePath('build');
|
|
13
|
+
const alias = resolveTsAliases(path.resolve('tsconfig.json'));
|
|
12
14
|
|
|
13
15
|
const config = {
|
|
14
16
|
entry: './src/index.ts',
|
|
@@ -20,13 +22,7 @@ const config = {
|
|
|
20
22
|
},
|
|
21
23
|
resolve: {
|
|
22
24
|
extensions: ['.js', '.ts', '.json', '.gql'],
|
|
23
|
-
alias
|
|
24
|
-
'@controllers': path.resolve(__dirname, 'controllers/'),
|
|
25
|
-
'@models': path.resolve(__dirname, 'models/'),
|
|
26
|
-
'@controllerGraphQL': path.resolve(__dirname, 'controllers/controllerGraphQL/'),
|
|
27
|
-
'@GraphQL': path.resolve(__dirname, 'GraphQL/'),
|
|
28
|
-
'@config': path.resolve(__dirname, 'config/'),
|
|
29
|
-
}
|
|
25
|
+
alias,
|
|
30
26
|
},
|
|
31
27
|
mode: 'production',
|
|
32
28
|
module: {
|