From 4881de86679875cc9cd3e06e4f7af16f7ca014f0 Mon Sep 17 00:00:00 2001 From: Alejandro Lembke Barrientos Date: Mon, 6 Mar 2023 22:19:22 +0000 Subject: [PATCH 1/3] PR-780243: adding only one source of truth. --- jest.config.js | 9 +++++++++ package-lock.json | 13 +++++++++++++ package.json | 1 + src/GraphQL/resolvers/index.ts | 2 +- src/GraphQL/schema/index.ts | 2 +- src/GraphQL/server.ts | 4 ++-- src/controllers/controllerGraphQL/index.ts | 2 +- src/index.ts | 8 ++++---- src/tests/server/index.test.ts | 2 +- tsconfig.json | 17 +++++++++++++++++ webpack.config.dev.ts | 10 +++------- webpack.config.ts | 10 +++------- 12 files changed, 56 insertions(+), 24 deletions(-) diff --git a/jest.config.js b/jest.config.js index 65fa0e8..6698117 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,6 +1,15 @@ +const { pathsToModuleNameMapper } = require('ts-jest'); +const { compilerOptions } = require('./tsconfig'); + +const aliases = pathsToModuleNameMapper(compilerOptions.paths, { + prefix: '' +}); + module.exports = { testEnvironment: 'node', transform: { "^.+\\.ts$": "ts-jest" + },moduleNameMapper: { + ...aliases, }, }; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index a44fee5..3256926 100644 --- a/package-lock.json +++ b/package-lock.json @@ -45,6 +45,7 @@ "eslint-webpack-plugin": "^4.0.0", "jest": "^29.5.0", "nodemon": "^2.0.21", + "resolve-ts-aliases": "^1.0.1", "supertest": "^6.3.3", "ts-jest": "^29.0.5", "ts-loader": "^9.4.2", @@ -9425,6 +9426,12 @@ "node": ">=4" } }, + "node_modules/resolve-ts-aliases": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/resolve-ts-aliases/-/resolve-ts-aliases-1.0.1.tgz", + "integrity": "sha512-BEFJ2lO9FhuJ+QVK8ZJxuDaFM2/oXt0YJJU9bS2R4zoWfMQOmrT0fLeSClXo7PMAD/kEbRfcGUHqhYKn/ZFPOg==", + "dev": true + }, "node_modules/resolve.exports": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/resolve.exports/-/resolve.exports-2.0.0.tgz", @@ -17885,6 +17892,12 @@ "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", "dev": true }, + "resolve-ts-aliases": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/resolve-ts-aliases/-/resolve-ts-aliases-1.0.1.tgz", + "integrity": "sha512-BEFJ2lO9FhuJ+QVK8ZJxuDaFM2/oXt0YJJU9bS2R4zoWfMQOmrT0fLeSClXo7PMAD/kEbRfcGUHqhYKn/ZFPOg==", + "dev": true + }, "resolve.exports": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/resolve.exports/-/resolve.exports-2.0.0.tgz", diff --git a/package.json b/package.json index 0caac67..29fb58a 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,7 @@ "eslint-webpack-plugin": "^4.0.0", "jest": "^29.5.0", "nodemon": "^2.0.21", + "resolve-ts-aliases": "^1.0.1", "supertest": "^6.3.3", "ts-jest": "^29.0.5", "ts-loader": "^9.4.2", diff --git a/src/GraphQL/resolvers/index.ts b/src/GraphQL/resolvers/index.ts index c662741..f298795 100644 --- a/src/GraphQL/resolvers/index.ts +++ b/src/GraphQL/resolvers/index.ts @@ -1,6 +1,6 @@ 'use strict'; -import { getTest, addText } from '../../controllers/controllerGraphQL'; +import { getTest, addText } from '@controllerGraphQL'; // A map of functions which return data for the schema. const resolvers = { diff --git a/src/GraphQL/schema/index.ts b/src/GraphQL/schema/index.ts index 40fe79f..6189687 100644 --- a/src/GraphQL/schema/index.ts +++ b/src/GraphQL/schema/index.ts @@ -1,5 +1,5 @@ import { makeExecutableSchema } from '@graphql-tools/schema'; -import resolvers from'../resolvers'; +import resolvers from'@GraphQL/resolvers'; import Test from './Test.gql'; // The GraphQL schema diff --git a/src/GraphQL/server.ts b/src/GraphQL/server.ts index 5e1d38d..2aa604d 100644 --- a/src/GraphQL/server.ts +++ b/src/GraphQL/server.ts @@ -1,8 +1,8 @@ 'use strict'; import express from 'express'; //express import { graphqlHTTP } from 'express-graphql'; -import { config } from '../../config'; -import schema from './schema'; +import { config } from '@config'; +import schema from '@GraphQL/schema'; const server = express.Router();//Router de Express diff --git a/src/controllers/controllerGraphQL/index.ts b/src/controllers/controllerGraphQL/index.ts index ce41902..a0d11d4 100644 --- a/src/controllers/controllerGraphQL/index.ts +++ b/src/controllers/controllerGraphQL/index.ts @@ -1,6 +1,6 @@ 'use strict'; -import { getTestModel, addTextModel } from '../../models'; +import { getTestModel, addTextModel } from '@models'; // eslint-disable-next-line export const getTest = async ({rootValue, args, context}) => { diff --git a/src/index.ts b/src/index.ts index 037b2e0..1052054 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,11 +6,11 @@ import cors from 'cors'; import cookieParser from 'cookie-parser'; import { useServer } from 'graphql-ws/lib/use/ws'; import { execute, subscribe } from 'graphql'; -import GraphQLserver from './GraphQL/server';// Server of GraphQL, +import GraphQLserver from '@GraphQL/server';// Server of GraphQL, import expressPlayground from 'graphql-playground-middleware-express'; -import schema from './GraphQL/schema'; -import { config } from '../config'; -import apiRouter from './routes'; +import schema from '@GraphQL/schema'; +import { config } from '@config'; +import apiRouter from '@routes'; const app = express(), //creating app whitelist = config.WHITELIST_URLS, diff --git a/src/tests/server/index.test.ts b/src/tests/server/index.test.ts index 045872d..dd72e18 100644 --- a/src/tests/server/index.test.ts +++ b/src/tests/server/index.test.ts @@ -1,4 +1,4 @@ -import server from '../../index'; +import server from '@src'; import supertest from 'supertest'; describe('global server tests', () => { let request; diff --git a/tsconfig.json b/tsconfig.json index 58aa9f6..414c425 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,6 +6,23 @@ "moduleResolution": "node", "sourceMap": true, "typeRoots" : ["./src/@types", "./node_modules/@types"], + "baseUrl": ".", + "paths": { + "@src/*": ["src/*"], + "@src": ["src"], + "@routes*": ["src/routes/*"], + "@routes": ["src/routes"], + "@controllers/*": ["src/controllers/*"], + "@controllers": ["src/controllers"], + "@models/*": ["src/models/*"], + "@models": ["src/models"], + "@controllerGraphQL/*": ["src/controllers/controllerGraphQL/*"], + "@controllerGraphQL": ["src/controllers/controllerGraphQL"], + "@GraphQL/*": ["src/GraphQL/*"], + "@GraphQL": ["src/GraphQL"], + "@config/*": ["config/*"], + "@config": ["config"] + } }, "lib": ["es2015"] } \ No newline at end of file diff --git a/webpack.config.dev.ts b/webpack.config.dev.ts index bf09e57..2f60f95 100644 --- a/webpack.config.dev.ts +++ b/webpack.config.dev.ts @@ -4,11 +4,13 @@ import { CleanWebpackPlugin } from 'clean-webpack-plugin'; import ESLintPlugin from 'eslint-webpack-plugin'; import nodeExternals from 'webpack-node-externals'; import WebpackShellPluginNext from 'webpack-shell-plugin-next'; +import { resolveTsAliases } from 'resolve-ts-aliases'; import { deFaultValues } from './config'; const ROOT_DIR = path.resolve(__dirname); const resolvePath = (...args) => path.resolve(ROOT_DIR, ...args); const BUILD_DIR = resolvePath('build'); +const alias = resolveTsAliases(path.resolve('tsconfig.json')); const config = { entry: './src/index.ts', @@ -21,13 +23,7 @@ const config = { }, resolve: { extensions: ['.js', '.ts', '.json', '.gql'], - alias: { - '@controllers': path.resolve(__dirname, 'controllers/'), - '@models': path.resolve(__dirname, 'models/'), - '@controllerGraphQL': path.resolve(__dirname, 'controllers/controllerGraphQL/'), - '@GraphQL': path.resolve(__dirname, 'GraphQL/'), - '@config': path.resolve(__dirname, 'config/'), - } + alias, }, mode: 'development', module: { diff --git a/webpack.config.ts b/webpack.config.ts index eae73b6..c048458 100644 --- a/webpack.config.ts +++ b/webpack.config.ts @@ -4,11 +4,13 @@ import TerserPlugin from 'terser-webpack-plugin'; import { CleanWebpackPlugin } from 'clean-webpack-plugin'; import ESLintPlugin from 'eslint-webpack-plugin'; import nodeExternals from 'webpack-node-externals'; +import { resolveTsAliases } from 'resolve-ts-aliases'; import { deFaultValues } from './config'; const ROOT_DIR = path.resolve(__dirname); const resolvePath = (...args) => path.resolve(ROOT_DIR, ...args); const BUILD_DIR = resolvePath('build'); +const alias = resolveTsAliases(path.resolve('tsconfig.json')); const config = { entry: './src/index.ts', @@ -20,13 +22,7 @@ const config = { }, resolve: { extensions: ['.js', '.ts', '.json', '.gql'], - alias: { - '@controllers': path.resolve(__dirname, 'controllers/'), - '@models': path.resolve(__dirname, 'models/'), - '@controllerGraphQL': path.resolve(__dirname, 'controllers/controllerGraphQL/'), - '@GraphQL': path.resolve(__dirname, 'GraphQL/'), - '@config': path.resolve(__dirname, 'config/'), - } + alias, }, mode: 'production', module: { From f70d03de84b201026394c0f4477812823d39c252 Mon Sep 17 00:00:00 2001 From: Alejandro Lembke Barrientos Date: Mon, 6 Mar 2023 22:37:37 +0000 Subject: [PATCH 2/3] PR-780243: Adding strict to types. --- package-lock.json | 254 ++++++++++++++++++++- package.json | 8 +- src/GraphQL/resolvers/index.ts | 8 +- src/GraphQL/schema/index.ts | 2 +- src/GraphQL/server.ts | 5 +- src/controllers/controllerGraphQL/index.ts | 8 +- src/index.ts | 6 +- src/models/index.ts | 2 +- src/tests/server/index.test.ts | 2 +- tsconfig.json | 2 + 10 files changed, 280 insertions(+), 17 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3256926..fbef140 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@aleleba/create-node-ts-graphql-server", - "version": "1.2.11", + "version": "1.2.12", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@aleleba/create-node-ts-graphql-server", - "version": "1.2.11", + "version": "1.2.12", "license": "MIT", "dependencies": { "@graphql-tools/schema": "^9.0.16", @@ -32,10 +32,16 @@ "@babel/preset-env": "^7.20.2", "@babel/preset-typescript": "^7.21.0", "@babel/register": "^7.21.0", + "@types/body-parser": "^1.19.2", + "@types/cookie-parser": "^1.4.3", + "@types/cors": "^2.8.13", + "@types/express": "^4.17.17", "@types/jest": "^29.4.0", "@types/node": "^18.14.6", + "@types/supertest": "^2.0.12", "@types/webpack": "^5.28.0", "@types/webpack-node-externals": "^3.0.0", + "@types/ws": "^8.5.4", "@typescript-eslint/eslint-plugin": "^5.54.0", "@typescript-eslint/parser": "^5.54.0", "babel-loader": "^9.1.2", @@ -3057,6 +3063,49 @@ "@babel/types": "^7.3.0" } }, + "node_modules/@types/body-parser": { + "version": "1.19.2", + "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.2.tgz", + "integrity": "sha512-ALYone6pm6QmwZoAgeyNksccT9Q4AWZQ6PvfwR37GT6r6FWUPguq6sUmNGSMV2Wr761oQoBxwGGa6DR5o1DC9g==", + "dev": true, + "dependencies": { + "@types/connect": "*", + "@types/node": "*" + } + }, + "node_modules/@types/connect": { + "version": "3.4.35", + "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.35.tgz", + "integrity": "sha512-cdeYyv4KWoEgpBISTxWvqYsVy444DOqehiF3fM3ne10AmJ62RSyNkUnxMJXHQWRQQX2eR94m5y1IZyDwBjV9FQ==", + "dev": true, + "dependencies": { + "@types/node": "*" + } + }, + "node_modules/@types/cookie-parser": { + "version": "1.4.3", + "resolved": "https://registry.npmjs.org/@types/cookie-parser/-/cookie-parser-1.4.3.tgz", + "integrity": "sha512-CqSKwFwefj4PzZ5n/iwad/bow2hTCh0FlNAeWLtQM3JA/NX/iYagIpWG2cf1bQKQ2c9gU2log5VUCrn7LDOs0w==", + "dev": true, + "dependencies": { + "@types/express": "*" + } + }, + "node_modules/@types/cookiejar": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/@types/cookiejar/-/cookiejar-2.1.2.tgz", + "integrity": "sha512-t73xJJrvdTjXrn4jLS9VSGRbz0nUY3cl2DMGDU48lKl+HR9dbbjW2A9r3g40VA++mQpy6uuHg33gy7du2BKpog==", + "dev": true + }, + "node_modules/@types/cors": { + "version": "2.8.13", + "resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.13.tgz", + "integrity": "sha512-RG8AStHlUiV5ysZQKq97copd2UmVYw3/pRMLefISZ3S1hK104Cwm7iLQ3fTKx+lsUH2CE8FlLaYeEA2LSeqYUA==", + "dev": true, + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/eslint": { "version": "8.21.0", "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.21.0.tgz", @@ -3083,6 +3132,29 @@ "integrity": "sha512-CuPgU6f3eT/XgKKPqKd/gLZV1Xmvf1a2R5POBOGQa6uv82xpls89HU5zKeVoyR8XzHd1RGNOlQlvUe3CFkjWNQ==", "dev": true }, + "node_modules/@types/express": { + "version": "4.17.17", + "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.17.tgz", + "integrity": "sha512-Q4FmmuLGBG58btUnfS1c1r/NQdlp3DMfGDGig8WhfpA2YRUtEkxAjkZb0yvplJGYdF1fsQ81iMDcH24sSCNC/Q==", + "dev": true, + "dependencies": { + "@types/body-parser": "*", + "@types/express-serve-static-core": "^4.17.33", + "@types/qs": "*", + "@types/serve-static": "*" + } + }, + "node_modules/@types/express-serve-static-core": { + "version": "4.17.33", + "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.17.33.tgz", + "integrity": "sha512-TPBqmR/HRYI3eC2E5hmiivIzv+bidAfXofM+sbonAGvyDhySGw9/PQZFt2BLOrjUUR++4eJVpx6KnLQK1Fk9tA==", + "dev": true, + "dependencies": { + "@types/node": "*", + "@types/qs": "*", + "@types/range-parser": "*" + } + }, "node_modules/@types/glob": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/@types/glob/-/glob-7.2.0.tgz", @@ -3142,6 +3214,12 @@ "integrity": "sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==", "dev": true }, + "node_modules/@types/mime": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@types/mime/-/mime-3.0.1.tgz", + "integrity": "sha512-Y4XFY5VJAuw0FgAqPNd6NNoV44jbq9Bz2L7Rh/J6jLTiHBSBJa9fxqQIvkIld4GsoDOcCbvzOUAbLPsSKKg+uA==", + "dev": true + }, "node_modules/@types/minimatch": { "version": "3.0.5", "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.5.tgz", @@ -3160,18 +3238,59 @@ "integrity": "sha512-KufADq8uQqo1pYKVIYzfKbJfBAc0sOeXqGbFaSpv8MRmC/zXgowNZmFcbngndGk922QDmOASEXUZCaY48gs4cg==", "dev": true }, + "node_modules/@types/qs": { + "version": "6.9.7", + "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.9.7.tgz", + "integrity": "sha512-FGa1F62FT09qcrueBA6qYTrJPVDzah9a+493+o2PCXsesWHIn27G98TsSMs3WPNbZIEj4+VJf6saSFpvD+3Zsw==", + "dev": true + }, + "node_modules/@types/range-parser": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.4.tgz", + "integrity": "sha512-EEhsLsD6UsDM1yFhAvy0Cjr6VwmpMWqFBCb9w07wVugF7w9nfajxLuVmngTIpgS6svCnm6Vaw+MZhoDCKnOfsw==", + "dev": true + }, "node_modules/@types/semver": { "version": "7.3.13", "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.3.13.tgz", "integrity": "sha512-21cFJr9z3g5dW8B0CVI9g2O9beqaThGQ6ZFBqHfwhzLDKUxaqTIy3vnfah/UPkfOiF2pLq+tGz+W8RyCskuslw==", "dev": true }, + "node_modules/@types/serve-static": { + "version": "1.15.1", + "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.15.1.tgz", + "integrity": "sha512-NUo5XNiAdULrJENtJXZZ3fHtfMolzZwczzBbnAeBbqBwG+LaG6YaJtuwzwGSQZ2wsCrxjEhNNjAkKigy3n8teQ==", + "dev": true, + "dependencies": { + "@types/mime": "*", + "@types/node": "*" + } + }, "node_modules/@types/stack-utils": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.1.tgz", "integrity": "sha512-Hl219/BT5fLAaz6NDkSuhzasy49dwQS/DSdu4MdggFB8zcXv7vflBI3xp7FEmkmdDkBUI2bPUNeMttp2knYdxw==", "dev": true }, + "node_modules/@types/superagent": { + "version": "4.1.16", + "resolved": "https://registry.npmjs.org/@types/superagent/-/superagent-4.1.16.tgz", + "integrity": "sha512-tLfnlJf6A5mB6ddqF159GqcDizfzbMUB1/DeT59/wBNqzRTNNKsaw79A/1TZ84X+f/EwWH8FeuSkjlCLyqS/zQ==", + "dev": true, + "dependencies": { + "@types/cookiejar": "*", + "@types/node": "*" + } + }, + "node_modules/@types/supertest": { + "version": "2.0.12", + "resolved": "https://registry.npmjs.org/@types/supertest/-/supertest-2.0.12.tgz", + "integrity": "sha512-X3HPWTwXRerBZS7Mo1k6vMVR1Z6zmJcDVn5O/31whe0tnjE4te6ZJSJGq1RiqHPjzPdMTfjCFogDJmwng9xHaQ==", + "dev": true, + "dependencies": { + "@types/superagent": "*" + } + }, "node_modules/@types/webpack": { "version": "5.28.0", "resolved": "https://registry.npmjs.org/@types/webpack/-/webpack-5.28.0.tgz", @@ -3193,6 +3312,15 @@ "webpack": "^5" } }, + "node_modules/@types/ws": { + "version": "8.5.4", + "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.4.tgz", + "integrity": "sha512-zdQDHKUgcX/zBc4GrwsE/7dVdAD8JR4EuiAXiiUhhfyIJXXb2+PrGshFyeXWQPMmmZ2XxgaqclgpIC7eTXc1mg==", + "dev": true, + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/yargs": { "version": "17.0.10", "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.10.tgz", @@ -13134,6 +13262,49 @@ "@babel/types": "^7.3.0" } }, + "@types/body-parser": { + "version": "1.19.2", + "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.2.tgz", + "integrity": "sha512-ALYone6pm6QmwZoAgeyNksccT9Q4AWZQ6PvfwR37GT6r6FWUPguq6sUmNGSMV2Wr761oQoBxwGGa6DR5o1DC9g==", + "dev": true, + "requires": { + "@types/connect": "*", + "@types/node": "*" + } + }, + "@types/connect": { + "version": "3.4.35", + "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.35.tgz", + "integrity": "sha512-cdeYyv4KWoEgpBISTxWvqYsVy444DOqehiF3fM3ne10AmJ62RSyNkUnxMJXHQWRQQX2eR94m5y1IZyDwBjV9FQ==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, + "@types/cookie-parser": { + "version": "1.4.3", + "resolved": "https://registry.npmjs.org/@types/cookie-parser/-/cookie-parser-1.4.3.tgz", + "integrity": "sha512-CqSKwFwefj4PzZ5n/iwad/bow2hTCh0FlNAeWLtQM3JA/NX/iYagIpWG2cf1bQKQ2c9gU2log5VUCrn7LDOs0w==", + "dev": true, + "requires": { + "@types/express": "*" + } + }, + "@types/cookiejar": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/@types/cookiejar/-/cookiejar-2.1.2.tgz", + "integrity": "sha512-t73xJJrvdTjXrn4jLS9VSGRbz0nUY3cl2DMGDU48lKl+HR9dbbjW2A9r3g40VA++mQpy6uuHg33gy7du2BKpog==", + "dev": true + }, + "@types/cors": { + "version": "2.8.13", + "resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.13.tgz", + "integrity": "sha512-RG8AStHlUiV5ysZQKq97copd2UmVYw3/pRMLefISZ3S1hK104Cwm7iLQ3fTKx+lsUH2CE8FlLaYeEA2LSeqYUA==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, "@types/eslint": { "version": "8.21.0", "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.21.0.tgz", @@ -13160,6 +13331,29 @@ "integrity": "sha512-CuPgU6f3eT/XgKKPqKd/gLZV1Xmvf1a2R5POBOGQa6uv82xpls89HU5zKeVoyR8XzHd1RGNOlQlvUe3CFkjWNQ==", "dev": true }, + "@types/express": { + "version": "4.17.17", + "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.17.tgz", + "integrity": "sha512-Q4FmmuLGBG58btUnfS1c1r/NQdlp3DMfGDGig8WhfpA2YRUtEkxAjkZb0yvplJGYdF1fsQ81iMDcH24sSCNC/Q==", + "dev": true, + "requires": { + "@types/body-parser": "*", + "@types/express-serve-static-core": "^4.17.33", + "@types/qs": "*", + "@types/serve-static": "*" + } + }, + "@types/express-serve-static-core": { + "version": "4.17.33", + "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.17.33.tgz", + "integrity": "sha512-TPBqmR/HRYI3eC2E5hmiivIzv+bidAfXofM+sbonAGvyDhySGw9/PQZFt2BLOrjUUR++4eJVpx6KnLQK1Fk9tA==", + "dev": true, + "requires": { + "@types/node": "*", + "@types/qs": "*", + "@types/range-parser": "*" + } + }, "@types/glob": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/@types/glob/-/glob-7.2.0.tgz", @@ -13219,6 +13413,12 @@ "integrity": "sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==", "dev": true }, + "@types/mime": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@types/mime/-/mime-3.0.1.tgz", + "integrity": "sha512-Y4XFY5VJAuw0FgAqPNd6NNoV44jbq9Bz2L7Rh/J6jLTiHBSBJa9fxqQIvkIld4GsoDOcCbvzOUAbLPsSKKg+uA==", + "dev": true + }, "@types/minimatch": { "version": "3.0.5", "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.5.tgz", @@ -13237,18 +13437,59 @@ "integrity": "sha512-KufADq8uQqo1pYKVIYzfKbJfBAc0sOeXqGbFaSpv8MRmC/zXgowNZmFcbngndGk922QDmOASEXUZCaY48gs4cg==", "dev": true }, + "@types/qs": { + "version": "6.9.7", + "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.9.7.tgz", + "integrity": "sha512-FGa1F62FT09qcrueBA6qYTrJPVDzah9a+493+o2PCXsesWHIn27G98TsSMs3WPNbZIEj4+VJf6saSFpvD+3Zsw==", + "dev": true + }, + "@types/range-parser": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.4.tgz", + "integrity": "sha512-EEhsLsD6UsDM1yFhAvy0Cjr6VwmpMWqFBCb9w07wVugF7w9nfajxLuVmngTIpgS6svCnm6Vaw+MZhoDCKnOfsw==", + "dev": true + }, "@types/semver": { "version": "7.3.13", "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.3.13.tgz", "integrity": "sha512-21cFJr9z3g5dW8B0CVI9g2O9beqaThGQ6ZFBqHfwhzLDKUxaqTIy3vnfah/UPkfOiF2pLq+tGz+W8RyCskuslw==", "dev": true }, + "@types/serve-static": { + "version": "1.15.1", + "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.15.1.tgz", + "integrity": "sha512-NUo5XNiAdULrJENtJXZZ3fHtfMolzZwczzBbnAeBbqBwG+LaG6YaJtuwzwGSQZ2wsCrxjEhNNjAkKigy3n8teQ==", + "dev": true, + "requires": { + "@types/mime": "*", + "@types/node": "*" + } + }, "@types/stack-utils": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.1.tgz", "integrity": "sha512-Hl219/BT5fLAaz6NDkSuhzasy49dwQS/DSdu4MdggFB8zcXv7vflBI3xp7FEmkmdDkBUI2bPUNeMttp2knYdxw==", "dev": true }, + "@types/superagent": { + "version": "4.1.16", + "resolved": "https://registry.npmjs.org/@types/superagent/-/superagent-4.1.16.tgz", + "integrity": "sha512-tLfnlJf6A5mB6ddqF159GqcDizfzbMUB1/DeT59/wBNqzRTNNKsaw79A/1TZ84X+f/EwWH8FeuSkjlCLyqS/zQ==", + "dev": true, + "requires": { + "@types/cookiejar": "*", + "@types/node": "*" + } + }, + "@types/supertest": { + "version": "2.0.12", + "resolved": "https://registry.npmjs.org/@types/supertest/-/supertest-2.0.12.tgz", + "integrity": "sha512-X3HPWTwXRerBZS7Mo1k6vMVR1Z6zmJcDVn5O/31whe0tnjE4te6ZJSJGq1RiqHPjzPdMTfjCFogDJmwng9xHaQ==", + "dev": true, + "requires": { + "@types/superagent": "*" + } + }, "@types/webpack": { "version": "5.28.0", "resolved": "https://registry.npmjs.org/@types/webpack/-/webpack-5.28.0.tgz", @@ -13270,6 +13511,15 @@ "webpack": "^5" } }, + "@types/ws": { + "version": "8.5.4", + "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.4.tgz", + "integrity": "sha512-zdQDHKUgcX/zBc4GrwsE/7dVdAD8JR4EuiAXiiUhhfyIJXXb2+PrGshFyeXWQPMmmZ2XxgaqclgpIC7eTXc1mg==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, "@types/yargs": { "version": "17.0.10", "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.10.tgz", diff --git a/package.json b/package.json index 29fb58a..052d878 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@aleleba/create-node-ts-graphql-server", - "version": "1.2.11", + "version": "1.3.0", "description": "Node with Typescript and GraphQL Server", "bin": "./bin/cli.js", "main": "index.js", @@ -53,10 +53,16 @@ "@babel/preset-env": "^7.20.2", "@babel/preset-typescript": "^7.21.0", "@babel/register": "^7.21.0", + "@types/body-parser": "^1.19.2", + "@types/cookie-parser": "^1.4.3", + "@types/cors": "^2.8.13", + "@types/express": "^4.17.17", "@types/jest": "^29.4.0", "@types/node": "^18.14.6", + "@types/supertest": "^2.0.12", "@types/webpack": "^5.28.0", "@types/webpack-node-externals": "^3.0.0", + "@types/ws": "^8.5.4", "@typescript-eslint/eslint-plugin": "^5.54.0", "@typescript-eslint/parser": "^5.54.0", "babel-loader": "^9.1.2", diff --git a/src/GraphQL/resolvers/index.ts b/src/GraphQL/resolvers/index.ts index f298795..24031bb 100644 --- a/src/GraphQL/resolvers/index.ts +++ b/src/GraphQL/resolvers/index.ts @@ -6,17 +6,17 @@ import { getTest, addText } from '@controllerGraphQL'; const resolvers = { Query: { // eslint-disable-next-line - test: (rootValue, args, context) => ({}), + test: (rootValue: any, args: any, context: any) => ({}), }, Mutation: { // eslint-disable-next-line - testMutation: (rootValue, args, context) => ({}), + testMutation: (rootValue: any, args: any, context: any) => ({}), }, Test: { - test: (rootValue, args, context) => getTest({rootValue, args, context}) + test: (rootValue: any, args: any, context: any) => getTest({rootValue, args, context}) }, TestMutation: { - testMutation: (rootValue, args, context) => addText({rootValue, args, context}) + testMutation: (rootValue: any, args: any, context: any) => addText({rootValue, args, context}) } }; diff --git a/src/GraphQL/schema/index.ts b/src/GraphQL/schema/index.ts index 6189687..030c001 100644 --- a/src/GraphQL/schema/index.ts +++ b/src/GraphQL/schema/index.ts @@ -1,6 +1,6 @@ import { makeExecutableSchema } from '@graphql-tools/schema'; import resolvers from'@GraphQL/resolvers'; -import Test from './Test.gql'; +import Test from '@GraphQL/schema/Test.gql'; // The GraphQL schema const rootTypes = ` diff --git a/src/GraphQL/server.ts b/src/GraphQL/server.ts index 2aa604d..c0148af 100644 --- a/src/GraphQL/server.ts +++ b/src/GraphQL/server.ts @@ -21,8 +21,9 @@ server.use( // DO NOT DO app.listen() unless we're testing this directly if (require.main === module) { - server.listen((process.env.PORT || 4000), () => { - console.log(`Iniciando Express en el puerto 4000${server.graphqlPath}`); /*${app.get('port')}*/ + const app = express(); + app.listen((process.env.PORT || 4000), () => { + console.log(`Iniciando Express en el puerto 4000`); /*${app.get('port')}*/ }); } diff --git a/src/controllers/controllerGraphQL/index.ts b/src/controllers/controllerGraphQL/index.ts index a0d11d4..dd6d684 100644 --- a/src/controllers/controllerGraphQL/index.ts +++ b/src/controllers/controllerGraphQL/index.ts @@ -3,12 +3,16 @@ import { getTestModel, addTextModel } from '@models'; // eslint-disable-next-line -export const getTest = async ({rootValue, args, context}) => { +export const getTest = async ({}) => { return getTestModel(); }; // eslint-disable-next-line -export const addText = async ({rootValue, args, context}) => { +export const addText = async ({args}: { + rootValue: any + args: { text: string } + context: any +}) => { const text = args.text; return addTextModel({ text }); }; \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 1052054..077bf64 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,8 +15,8 @@ import apiRouter from '@routes'; const app = express(), //creating app whitelist = config.WHITELIST_URLS, corsOptions = { - origin: function (origin, callback) { - if (whitelist.indexOf(origin) !== -1 || !origin) { + origin: function (origin: string | undefined, callback: (arg0: Error | null, arg1?: boolean) => void) { + if (whitelist.indexOf(origin as string) !== -1 || !origin) { callback(null, true); } else { callback(new Error('Not allowed by CORS')); @@ -29,7 +29,7 @@ const app = express(), //creating app app .use(cookieParser()) .use(express.urlencoded({limit: '500mb', extended: true})) - .use(express.json({limit: '500mb', extended: true})) + .use(express.json({limit: '500mb'})) .use(cors(corsOptions)) .use(apiRouter)//Routes de App .use('/graphql', GraphQLserver);//Server of Graphql diff --git a/src/models/index.ts b/src/models/index.ts index ae93f18..44f39bb 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -4,6 +4,6 @@ export const getTestModel = async () => { return 'This is the text response for Test Query from a model'; }; -export const addTextModel = async ({ text }) => { +export const addTextModel = async ({ text }: {text: string}) => { return `Simulate to insert some text: ${text} from a model`; }; \ No newline at end of file diff --git a/src/tests/server/index.test.ts b/src/tests/server/index.test.ts index dd72e18..28b4921 100644 --- a/src/tests/server/index.test.ts +++ b/src/tests/server/index.test.ts @@ -1,7 +1,7 @@ import server from '@src'; import supertest from 'supertest'; describe('global server tests', () => { - let request; + let request: supertest.SuperTest; beforeEach(() => { request = supertest(server); }); diff --git a/tsconfig.json b/tsconfig.json index 414c425..5e5b434 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,6 +6,8 @@ "moduleResolution": "node", "sourceMap": true, "typeRoots" : ["./src/@types", "./node_modules/@types"], + "strict": true, + "forceConsistentCasingInFileNames": true, "baseUrl": ".", "paths": { "@src/*": ["src/*"], From b79f0396dcbe11e47e12da243606d3821a14e0d1 Mon Sep 17 00:00:00 2001 From: Alejandro Lembke Barrientos Date: Mon, 6 Mar 2023 23:24:25 +0000 Subject: [PATCH 3/3] PR-780243: Adding type to webpack files. --- webpack.config.dev.ts | 2 +- webpack.config.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/webpack.config.dev.ts b/webpack.config.dev.ts index 2f60f95..95bc88f 100644 --- a/webpack.config.dev.ts +++ b/webpack.config.dev.ts @@ -8,7 +8,7 @@ import { resolveTsAliases } from 'resolve-ts-aliases'; import { deFaultValues } from './config'; const ROOT_DIR = path.resolve(__dirname); -const resolvePath = (...args) => path.resolve(ROOT_DIR, ...args); +const resolvePath = (...args: string[]) => path.resolve(ROOT_DIR, ...args); const BUILD_DIR = resolvePath('build'); const alias = resolveTsAliases(path.resolve('tsconfig.json')); diff --git a/webpack.config.ts b/webpack.config.ts index c048458..325418e 100644 --- a/webpack.config.ts +++ b/webpack.config.ts @@ -8,7 +8,7 @@ import { resolveTsAliases } from 'resolve-ts-aliases'; import { deFaultValues } from './config'; const ROOT_DIR = path.resolve(__dirname); -const resolvePath = (...args) => path.resolve(ROOT_DIR, ...args); +const resolvePath = (...args: string[]) => path.resolve(ROOT_DIR, ...args); const BUILD_DIR = resolvePath('build'); const alias = resolveTsAliases(path.resolve('tsconfig.json'));