From 4ffc696ee4292317d38f850b43180bfd0c72caf2 Mon Sep 17 00:00:00 2001 From: Alejandro Lembke Barrientos Date: Fri, 10 Mar 2023 13:18:24 +0000 Subject: [PATCH] PR-757991: adding typegraphql. --- package-lock.json | 304 ++++++++++++++++++--- package.json | 5 +- schema.gql | 28 ++ src/GraphQL/resolvers/index.ts | 23 -- src/GraphQL/resolvers/test.resolver.ts | 18 ++ src/GraphQL/schema/Test.gql | 13 - src/GraphQL/schema/index.ts | 23 +- src/GraphQL/schema/test.schema.ts | 36 +++ src/GraphQL/server.ts | 6 +- src/controllers/controllerGraphQL/index.ts | 8 +- src/index.ts | 1 + src/models/index.ts | 4 +- src/tests/server/index.test.ts | 31 ++- tsconfig.json | 6 +- 14 files changed, 392 insertions(+), 114 deletions(-) create mode 100644 schema.gql delete mode 100644 src/GraphQL/resolvers/index.ts create mode 100644 src/GraphQL/resolvers/test.resolver.ts delete mode 100644 src/GraphQL/schema/Test.gql create mode 100644 src/GraphQL/schema/test.schema.ts diff --git a/package-lock.json b/package-lock.json index fbef140..3ef45bf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,16 +1,17 @@ { "name": "@aleleba/create-node-ts-graphql-server", - "version": "1.2.12", + "version": "1.4.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@aleleba/create-node-ts-graphql-server", - "version": "1.2.12", + "version": "1.4.0", "license": "MIT", "dependencies": { "@graphql-tools/schema": "^9.0.16", "body-parser": "^1.20.2", + "class-validator": "^0.14.0", "cookie-parser": "^1.4.6", "cors": "^2.8.5", "dotenv": "^16.0.3", @@ -21,6 +22,8 @@ "graphql-subscriptions": "^2.0.0", "graphql-tools": "^8.3.18", "graphql-ws": "^5.12.0", + "reflect-metadata": "^0.1.13", + "type-graphql": "^2.0.0-beta.1", "web-push": "^3.5.0", "ws": "^8.12.1" }, @@ -3221,16 +3224,14 @@ "dev": true }, "node_modules/@types/minimatch": { - "version": "3.0.5", - "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.5.tgz", - "integrity": "sha512-Klz949h02Gz2uZCMGwDUSDS1YBlTdDDgbWHi+81l29tQALUtvz4rAYi5uoVhE5Lagoq6DeqAUlbrHvW/mXDgdQ==", - "dev": true + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-5.1.2.tgz", + "integrity": "sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA==" }, "node_modules/@types/node": { "version": "18.14.6", "resolved": "https://registry.npmjs.org/@types/node/-/node-18.14.6.tgz", - "integrity": "sha512-93+VvleD3mXwlLI/xASjw0FzKcwzl3OdTCzm1LaRfqgS21gfFtK3zDXM5Op9TeeMsJVOaJ2VRDpT9q4Y3d0AvA==", - "dev": true + "integrity": "sha512-93+VvleD3mXwlLI/xASjw0FzKcwzl3OdTCzm1LaRfqgS21gfFtK3zDXM5Op9TeeMsJVOaJ2VRDpT9q4Y3d0AvA==" }, "node_modules/@types/prettier": { "version": "2.7.2", @@ -3253,8 +3254,7 @@ "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 + "integrity": "sha512-21cFJr9z3g5dW8B0CVI9g2O9beqaThGQ6ZFBqHfwhzLDKUxaqTIy3vnfah/UPkfOiF2pLq+tGz+W8RyCskuslw==" }, "node_modules/@types/serve-static": { "version": "1.15.1", @@ -3291,6 +3291,11 @@ "@types/superagent": "*" } }, + "node_modules/@types/validator": { + "version": "13.7.13", + "resolved": "https://registry.npmjs.org/@types/validator/-/validator-13.7.13.tgz", + "integrity": "sha512-EMfHccxNKXaSxTK6DN0En9WsXa7uR4w3LQtx31f6Z2JjG5hJQeVX5zUYMZoatjZgnoQmRcT94WnNWwi0BzQW6Q==" + }, "node_modules/@types/webpack": { "version": "5.28.0", "resolved": "https://registry.npmjs.org/@types/webpack/-/webpack-5.28.0.tgz", @@ -4376,8 +4381,7 @@ "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", - "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", - "dev": true + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" }, "node_modules/binary-extensions": { "version": "2.2.0", @@ -4635,6 +4639,16 @@ "integrity": "sha512-cOU9usZw8/dXIXKtwa8pM0OTJQuJkxMN6w30csNRUerHfeQ5R6U3kkU/FtJeIf3M202OHfY2U8ccInBG7/xogA==", "dev": true }, + "node_modules/class-validator": { + "version": "0.14.0", + "resolved": "https://registry.npmjs.org/class-validator/-/class-validator-0.14.0.tgz", + "integrity": "sha512-ct3ltplN8I9fOwUd8GrP8UQixwff129BkEtuWDKL5W45cQuLd19xqmTLu5ge78YDm/fdje6FMt0hGOhl0lii3A==", + "dependencies": { + "@types/validator": "^13.7.10", + "libphonenumber-js": "^1.10.14", + "validator": "^13.7.0" + } + }, "node_modules/clean-webpack-plugin": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/clean-webpack-plugin/-/clean-webpack-plugin-4.0.0.tgz", @@ -6061,8 +6075,7 @@ "node_modules/fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", - "dev": true + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" }, "node_modules/fsevents": { "version": "2.3.2", @@ -6241,6 +6254,17 @@ "express": "^4.16.2" } }, + "node_modules/graphql-query-complexity": { + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/graphql-query-complexity/-/graphql-query-complexity-0.12.0.tgz", + "integrity": "sha512-fWEyuSL6g/+nSiIRgIipfI6UXTI7bAxrpPlCY1c0+V3pAEUo1ybaKmSBgNr1ed2r+agm1plJww8Loig9y6s2dw==", + "dependencies": { + "lodash.get": "^4.4.2" + }, + "peerDependencies": { + "graphql": "^14.6.0 || ^15.0.0 || ^16.0.0" + } + }, "node_modules/graphql-subscriptions": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/graphql-subscriptions/-/graphql-subscriptions-2.0.0.tgz", @@ -6490,7 +6514,6 @@ "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", - "dev": true, "dependencies": { "once": "^1.3.0", "wrappy": "1" @@ -8574,6 +8597,11 @@ "node": ">= 0.8.0" } }, + "node_modules/libphonenumber-js": { + "version": "1.10.21", + "resolved": "https://registry.npmjs.org/libphonenumber-js/-/libphonenumber-js-1.10.21.tgz", + "integrity": "sha512-/udZhx49av2r2gZR/+xXSrwcR8smX/sDNrVpOFrvW+CA26TfYTVZfwb3MIDvmwAYMLs7pXuJjZX0VxxGpqPhsA==" + }, "node_modules/lines-and-columns": { "version": "1.2.4", "resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.2.4.tgz", @@ -8607,6 +8635,11 @@ "integrity": "sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow==", "dev": true }, + "node_modules/lodash.get": { + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz", + "integrity": "sha512-z+Uw/vLuy6gQe8cfaFWD7p0wVv8fJl3mbzXh33RS+0oW2wvUqiRXiQ69gLWSLpgB5/6sU+r6BlQR0MBILadqTQ==" + }, "node_modules/lodash.memoize": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz", @@ -8635,7 +8668,6 @@ "version": "6.0.0", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", - "dev": true, "dependencies": { "yallist": "^4.0.0" }, @@ -8945,7 +8977,6 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", - "dev": true, "dependencies": { "wrappy": "1" } @@ -9400,6 +9431,11 @@ "node": ">= 10.13.0" } }, + "node_modules/reflect-metadata": { + "version": "0.1.13", + "resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.1.13.tgz", + "integrity": "sha512-Ts1Y/anZELhSsjMcU605fU9RE4Oi3p5ORujwbIKXfWa+0Zxs510Qrmrce5/Jowq3cHSZSJqBjypxmHarc+vEWg==" + }, "node_modules/regenerate": { "version": "1.4.2", "resolved": "https://registry.npmjs.org/regenerate/-/regenerate-1.4.2.tgz", @@ -10472,6 +10508,93 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/type-graphql": { + "version": "2.0.0-beta.1", + "resolved": "https://registry.npmjs.org/type-graphql/-/type-graphql-2.0.0-beta.1.tgz", + "integrity": "sha512-eafe1WJAdiCTEma43Imi1NRRgioIL1nk2FIprpQ0uvodcpIz0uoR+SZgRGu0AXof7DdcrlL3ZdRVoOiuolOQMA==", + "hasInstallScript": true, + "dependencies": { + "@types/glob": "^8.0.0", + "@types/node": "*", + "@types/semver": "^7.3.12", + "glob": "^8.0.3", + "graphql-query-complexity": "^0.12.0", + "graphql-subscriptions": "^2.0.0", + "semver": "^7.3.7", + "tslib": "^2.4.0" + }, + "engines": { + "node": ">= 14.5.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typegraphql" + }, + "peerDependencies": { + "class-validator": ">=0.13.0", + "graphql": "^16.6.0" + } + }, + "node_modules/type-graphql/node_modules/@types/glob": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/@types/glob/-/glob-8.1.0.tgz", + "integrity": "sha512-IO+MJPVhoqz+28h1qLAcBEH2+xHMK6MTyHJc7MTnnYb6wsoLR29POVGJ7LycmVXIqyy/4/2ShP5sUwTXuOwb/w==", + "dependencies": { + "@types/minimatch": "^5.1.2", + "@types/node": "*" + } + }, + "node_modules/type-graphql/node_modules/brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/type-graphql/node_modules/glob": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz", + "integrity": "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==", + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^5.0.1", + "once": "^1.3.0" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/type-graphql/node_modules/minimatch": { + "version": "5.1.6", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz", + "integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==", + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/type-graphql/node_modules/semver": { + "version": "7.3.8", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", + "integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==", + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/type-is": { "version": "1.6.18", "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", @@ -10613,6 +10736,14 @@ "node": ">=10.12.0" } }, + "node_modules/validator": { + "version": "13.9.0", + "resolved": "https://registry.npmjs.org/validator/-/validator-13.9.0.tgz", + "integrity": "sha512-B+dGG8U3fdtM0/aNK4/X8CXq/EcxU2WPrPEkJGslb47qyHsxmbggTWK0yEA4qnYVNF+nxNlN88o14hIcPmSIEA==", + "engines": { + "node": ">= 0.10" + } + }, "node_modules/value-or-promise": { "version": "1.0.12", "resolved": "https://registry.npmjs.org/value-or-promise/-/value-or-promise-1.0.12.tgz", @@ -10960,8 +11091,7 @@ "node_modules/wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", - "dev": true + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" }, "node_modules/write-file-atomic": { "version": "4.0.2", @@ -11023,8 +11153,7 @@ "node_modules/yallist": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", - "dev": true + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" }, "node_modules/yargs": { "version": "17.7.1", @@ -13420,16 +13549,14 @@ "dev": true }, "@types/minimatch": { - "version": "3.0.5", - "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.5.tgz", - "integrity": "sha512-Klz949h02Gz2uZCMGwDUSDS1YBlTdDDgbWHi+81l29tQALUtvz4rAYi5uoVhE5Lagoq6DeqAUlbrHvW/mXDgdQ==", - "dev": true + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-5.1.2.tgz", + "integrity": "sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA==" }, "@types/node": { "version": "18.14.6", "resolved": "https://registry.npmjs.org/@types/node/-/node-18.14.6.tgz", - "integrity": "sha512-93+VvleD3mXwlLI/xASjw0FzKcwzl3OdTCzm1LaRfqgS21gfFtK3zDXM5Op9TeeMsJVOaJ2VRDpT9q4Y3d0AvA==", - "dev": true + "integrity": "sha512-93+VvleD3mXwlLI/xASjw0FzKcwzl3OdTCzm1LaRfqgS21gfFtK3zDXM5Op9TeeMsJVOaJ2VRDpT9q4Y3d0AvA==" }, "@types/prettier": { "version": "2.7.2", @@ -13452,8 +13579,7 @@ "@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 + "integrity": "sha512-21cFJr9z3g5dW8B0CVI9g2O9beqaThGQ6ZFBqHfwhzLDKUxaqTIy3vnfah/UPkfOiF2pLq+tGz+W8RyCskuslw==" }, "@types/serve-static": { "version": "1.15.1", @@ -13490,6 +13616,11 @@ "@types/superagent": "*" } }, + "@types/validator": { + "version": "13.7.13", + "resolved": "https://registry.npmjs.org/@types/validator/-/validator-13.7.13.tgz", + "integrity": "sha512-EMfHccxNKXaSxTK6DN0En9WsXa7uR4w3LQtx31f6Z2JjG5hJQeVX5zUYMZoatjZgnoQmRcT94WnNWwi0BzQW6Q==" + }, "@types/webpack": { "version": "5.28.0", "resolved": "https://registry.npmjs.org/@types/webpack/-/webpack-5.28.0.tgz", @@ -14289,8 +14420,7 @@ "balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", - "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", - "dev": true + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" }, "binary-extensions": { "version": "2.2.0", @@ -14476,6 +14606,16 @@ "integrity": "sha512-cOU9usZw8/dXIXKtwa8pM0OTJQuJkxMN6w30csNRUerHfeQ5R6U3kkU/FtJeIf3M202OHfY2U8ccInBG7/xogA==", "dev": true }, + "class-validator": { + "version": "0.14.0", + "resolved": "https://registry.npmjs.org/class-validator/-/class-validator-0.14.0.tgz", + "integrity": "sha512-ct3ltplN8I9fOwUd8GrP8UQixwff129BkEtuWDKL5W45cQuLd19xqmTLu5ge78YDm/fdje6FMt0hGOhl0lii3A==", + "requires": { + "@types/validator": "^13.7.10", + "libphonenumber-js": "^1.10.14", + "validator": "^13.7.0" + } + }, "clean-webpack-plugin": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/clean-webpack-plugin/-/clean-webpack-plugin-4.0.0.tgz", @@ -15563,8 +15703,7 @@ "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", - "dev": true + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" }, "fsevents": { "version": "2.3.2", @@ -15694,6 +15833,14 @@ "graphql-playground-html": "^1.6.30" } }, + "graphql-query-complexity": { + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/graphql-query-complexity/-/graphql-query-complexity-0.12.0.tgz", + "integrity": "sha512-fWEyuSL6g/+nSiIRgIipfI6UXTI7bAxrpPlCY1c0+V3pAEUo1ybaKmSBgNr1ed2r+agm1plJww8Loig9y6s2dw==", + "requires": { + "lodash.get": "^4.4.2" + } + }, "graphql-subscriptions": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/graphql-subscriptions/-/graphql-subscriptions-2.0.0.tgz", @@ -15866,7 +16013,6 @@ "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", - "dev": true, "requires": { "once": "^1.3.0", "wrappy": "1" @@ -17410,6 +17556,11 @@ "type-check": "~0.4.0" } }, + "libphonenumber-js": { + "version": "1.10.21", + "resolved": "https://registry.npmjs.org/libphonenumber-js/-/libphonenumber-js-1.10.21.tgz", + "integrity": "sha512-/udZhx49av2r2gZR/+xXSrwcR8smX/sDNrVpOFrvW+CA26TfYTVZfwb3MIDvmwAYMLs7pXuJjZX0VxxGpqPhsA==" + }, "lines-and-columns": { "version": "1.2.4", "resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.2.4.tgz", @@ -17437,6 +17588,11 @@ "integrity": "sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow==", "dev": true }, + "lodash.get": { + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz", + "integrity": "sha512-z+Uw/vLuy6gQe8cfaFWD7p0wVv8fJl3mbzXh33RS+0oW2wvUqiRXiQ69gLWSLpgB5/6sU+r6BlQR0MBILadqTQ==" + }, "lodash.memoize": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz", @@ -17462,7 +17618,6 @@ "version": "6.0.0", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", - "dev": true, "requires": { "yallist": "^4.0.0" } @@ -17698,7 +17853,6 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", - "dev": true, "requires": { "wrappy": "1" } @@ -18023,6 +18177,11 @@ "resolve": "^1.20.0" } }, + "reflect-metadata": { + "version": "0.1.13", + "resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.1.13.tgz", + "integrity": "sha512-Ts1Y/anZELhSsjMcU605fU9RE4Oi3p5ORujwbIKXfWa+0Zxs510Qrmrce5/Jowq3cHSZSJqBjypxmHarc+vEWg==" + }, "regenerate": { "version": "1.4.2", "resolved": "https://registry.npmjs.org/regenerate/-/regenerate-1.4.2.tgz", @@ -18782,6 +18941,68 @@ "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", "dev": true }, + "type-graphql": { + "version": "2.0.0-beta.1", + "resolved": "https://registry.npmjs.org/type-graphql/-/type-graphql-2.0.0-beta.1.tgz", + "integrity": "sha512-eafe1WJAdiCTEma43Imi1NRRgioIL1nk2FIprpQ0uvodcpIz0uoR+SZgRGu0AXof7DdcrlL3ZdRVoOiuolOQMA==", + "requires": { + "@types/glob": "^8.0.0", + "@types/node": "*", + "@types/semver": "^7.3.12", + "glob": "^8.0.3", + "graphql-query-complexity": "^0.12.0", + "graphql-subscriptions": "^2.0.0", + "semver": "^7.3.7", + "tslib": "^2.4.0" + }, + "dependencies": { + "@types/glob": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/@types/glob/-/glob-8.1.0.tgz", + "integrity": "sha512-IO+MJPVhoqz+28h1qLAcBEH2+xHMK6MTyHJc7MTnnYb6wsoLR29POVGJ7LycmVXIqyy/4/2ShP5sUwTXuOwb/w==", + "requires": { + "@types/minimatch": "^5.1.2", + "@types/node": "*" + } + }, + "brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "requires": { + "balanced-match": "^1.0.0" + } + }, + "glob": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz", + "integrity": "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==", + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^5.0.1", + "once": "^1.3.0" + } + }, + "minimatch": { + "version": "5.1.6", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz", + "integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==", + "requires": { + "brace-expansion": "^2.0.1" + } + }, + "semver": { + "version": "7.3.8", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", + "integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==", + "requires": { + "lru-cache": "^6.0.0" + } + } + } + }, "type-is": { "version": "1.6.18", "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", @@ -18876,6 +19097,11 @@ "convert-source-map": "^1.6.0" } }, + "validator": { + "version": "13.9.0", + "resolved": "https://registry.npmjs.org/validator/-/validator-13.9.0.tgz", + "integrity": "sha512-B+dGG8U3fdtM0/aNK4/X8CXq/EcxU2WPrPEkJGslb47qyHsxmbggTWK0yEA4qnYVNF+nxNlN88o14hIcPmSIEA==" + }, "value-or-promise": { "version": "1.0.12", "resolved": "https://registry.npmjs.org/value-or-promise/-/value-or-promise-1.0.12.tgz", @@ -19124,8 +19350,7 @@ "wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", - "dev": true + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" }, "write-file-atomic": { "version": "4.0.2", @@ -19160,8 +19385,7 @@ "yallist": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", - "dev": true + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" }, "yargs": { "version": "17.7.1", diff --git a/package.json b/package.json index 052d878..07adaf2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@aleleba/create-node-ts-graphql-server", - "version": "1.3.0", + "version": "1.4.0", "description": "Node with Typescript and GraphQL Server", "bin": "./bin/cli.js", "main": "index.js", @@ -35,6 +35,7 @@ "dependencies": { "@graphql-tools/schema": "^9.0.16", "body-parser": "^1.20.2", + "class-validator": "^0.14.0", "cookie-parser": "^1.4.6", "cors": "^2.8.5", "dotenv": "^16.0.3", @@ -45,6 +46,8 @@ "graphql-subscriptions": "^2.0.0", "graphql-tools": "^8.3.18", "graphql-ws": "^5.12.0", + "reflect-metadata": "^0.1.13", + "type-graphql": "^2.0.0-beta.1", "web-push": "^3.5.0", "ws": "^8.12.1" }, diff --git a/schema.gql b/schema.gql new file mode 100644 index 0000000..6820687 --- /dev/null +++ b/schema.gql @@ -0,0 +1,28 @@ +# ----------------------------------------------- +# !!! THIS FILE WAS GENERATED BY TYPE-GRAPHQL !!! +# !!! DO NOT MODIFY THIS FILE BY YOURSELF !!! +# ----------------------------------------------- + +type Mutation { + testMutation: TestMutation! +} + +type Query { + test: Test! +} + +type Test { + text: Text! +} + +type TestMutation { + textMutation(text: String!): TextMutation! +} + +type Text { + text: String! +} + +type TextMutation { + text: String! +} \ No newline at end of file diff --git a/src/GraphQL/resolvers/index.ts b/src/GraphQL/resolvers/index.ts deleted file mode 100644 index 24031bb..0000000 --- a/src/GraphQL/resolvers/index.ts +++ /dev/null @@ -1,23 +0,0 @@ -'use strict'; - -import { getTest, addText } from '@controllerGraphQL'; - -// A map of functions which return data for the schema. -const resolvers = { - Query: { - // eslint-disable-next-line - test: (rootValue: any, args: any, context: any) => ({}), - }, - Mutation: { - // eslint-disable-next-line - testMutation: (rootValue: any, args: any, context: any) => ({}), - }, - Test: { - test: (rootValue: any, args: any, context: any) => getTest({rootValue, args, context}) - }, - TestMutation: { - testMutation: (rootValue: any, args: any, context: any) => addText({rootValue, args, context}) - } -}; - -export default resolvers; \ No newline at end of file diff --git a/src/GraphQL/resolvers/test.resolver.ts b/src/GraphQL/resolvers/test.resolver.ts new file mode 100644 index 0000000..eb97de1 --- /dev/null +++ b/src/GraphQL/resolvers/test.resolver.ts @@ -0,0 +1,18 @@ +'use strict'; + +import { Query, Resolver, Mutation, Arg } from 'type-graphql'; +import { Test, TestMutation } from '@GraphQL/schema/test.schema'; + +@Resolver(() => Test) +export class TestResolver { + @Query(() => Test) + async test() { + return {}; + } + + @Mutation(() => TestMutation) + async testMutation() { + return {}; + } +} + diff --git a/src/GraphQL/schema/Test.gql b/src/GraphQL/schema/Test.gql deleted file mode 100644 index c0e5e96..0000000 --- a/src/GraphQL/schema/Test.gql +++ /dev/null @@ -1,13 +0,0 @@ -module.exports = ` - - """Test Query""" - type Test { - test: String - } - - """Esta es la Data de LogIn, Si los datos no son correctos devuelve el usuario Null y la conexion en False""" - type TestMutation { - testMutation(text: String): String - } - -` \ No newline at end of file diff --git a/src/GraphQL/schema/index.ts b/src/GraphQL/schema/index.ts index 030c001..bad08d7 100644 --- a/src/GraphQL/schema/index.ts +++ b/src/GraphQL/schema/index.ts @@ -1,17 +1,10 @@ -import { makeExecutableSchema } from '@graphql-tools/schema'; -import resolvers from'@GraphQL/resolvers'; -import Test from '@GraphQL/schema/Test.gql'; +'use strict' -// The GraphQL schema -const rootTypes = ` - type Query { - test: Test - } - type Mutation { - testMutation: TestMutation - } -`; +import { buildSchemaSync } from "type-graphql" +import { TestResolver } from "@GraphQL/resolvers/test.resolver"; -const typeDefs = [ rootTypes, Test ]; - -export default makeExecutableSchema({typeDefs, resolvers}); \ No newline at end of file +const schema = buildSchemaSync({ + resolvers: [TestResolver], + emitSchemaFile: true, + }) +export default schema \ No newline at end of file diff --git a/src/GraphQL/schema/test.schema.ts b/src/GraphQL/schema/test.schema.ts new file mode 100644 index 0000000..4863e44 --- /dev/null +++ b/src/GraphQL/schema/test.schema.ts @@ -0,0 +1,36 @@ +'use strict'; + +import { Field, ObjectType, Arg } from "type-graphql"; +import { getTest, addText } from '@controllerGraphQL'; + +@ObjectType() +export class Test { + @Field(() => Text) + async text(){ + return { + text: await getTest({}) + } + } +} + +@ObjectType() +export class Text { + @Field() + text?: string +} + +@ObjectType() +export class TestMutation { + @Field(type => TextMutation) + async textMutation(@Arg('text') text?: string){ + return { + text: await addText({text}) + } + } +} + +@ObjectType() +export class TextMutation { + @Field() + text?: string +} diff --git a/src/GraphQL/server.ts b/src/GraphQL/server.ts index c0148af..7d1788e 100644 --- a/src/GraphQL/server.ts +++ b/src/GraphQL/server.ts @@ -1,8 +1,10 @@ 'use strict'; + import express from 'express'; //express import { graphqlHTTP } from 'express-graphql'; import { config } from '@config'; -import schema from '@GraphQL/schema'; +import schema from '@src/GraphQL/schema'; + const server = express.Router();//Router de Express @@ -17,8 +19,6 @@ server.use( }), ); - - // DO NOT DO app.listen() unless we're testing this directly if (require.main === module) { const app = express(); diff --git a/src/controllers/controllerGraphQL/index.ts b/src/controllers/controllerGraphQL/index.ts index dd6d684..56d717f 100644 --- a/src/controllers/controllerGraphQL/index.ts +++ b/src/controllers/controllerGraphQL/index.ts @@ -1,6 +1,7 @@ 'use strict'; import { getTestModel, addTextModel } from '@models'; +import { TextMutation } from '@src/GraphQL/schema/test.schema'; // eslint-disable-next-line export const getTest = async ({}) => { @@ -8,11 +9,6 @@ export const getTest = async ({}) => { }; // eslint-disable-next-line -export const addText = async ({args}: { - rootValue: any - args: { text: string } - context: any -}) => { - const text = args.text; +export const addText = async ({ text }: TextMutation) => { return addTextModel({ text }); }; \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 077bf64..df88f9a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,6 @@ 'use strict'; +import "reflect-metadata"; import ws from 'ws'; // yarn add ws import express from 'express'; //express import cors from 'cors'; diff --git a/src/models/index.ts b/src/models/index.ts index 44f39bb..15ada4e 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -1,9 +1,11 @@ 'use strict'; +import { TextMutation } from "@GraphQL/schema/test.schema"; + export const getTestModel = async () => { return 'This is the text response for Test Query from a model'; }; -export const addTextModel = async ({ text }: {text: string}) => { +export const addTextModel = async ({ text }: TextMutation) => { 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 28b4921..65261c4 100644 --- a/src/tests/server/index.test.ts +++ b/src/tests/server/index.test.ts @@ -2,17 +2,21 @@ import server from '@src'; import supertest from 'supertest'; describe('global server tests', () => { let request: supertest.SuperTest; - beforeEach(() => { - request = supertest(server); - }); + beforeEach( async () => { + request = await supertest(server); + }); + it('should return Test data from test Query', async () => { const bodyResponse = { data: { - test: { test: 'This is the text response for Test Query from a model' } + test: { + text: { + text: "This is the text response for Test Query from a model" + } + } } } - - const response = await request.get('/graphql?query=%7B%0A%20%20test%7B%0A%20%20%20%20test%0A%20%20%7D%0A%7D%0A') + 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') .set('Accept', 'application/json') expect(response.status).toEqual(200); expect(response.body).toEqual(bodyResponse); @@ -21,14 +25,21 @@ describe('global server tests', () => { it('should return Test data from test Mutation', async () => { const bodyResponse = { data: { - testMutation: { - testMutation: 'Simulate to insert some text: test text from a model' + testMutation: { + textMutation: { + text: "Simulate to insert some text: testing text from a model" } + } } } - const response = await request.post('/graphql') - .send({"query":"mutation{\n testMutation{\n testMutation(text: \"test text\")\n }\n}\n","variables":null}) + .send({'query': `mutation{ + testMutation{ + textMutation(text: "testing text"){ + text + } + } + }`}) .set('Accept', 'application/json') expect(response.status).toEqual(200); expect(response.body).toEqual(bodyResponse); diff --git a/tsconfig.json b/tsconfig.json index 5e5b434..de0c1c1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,12 +2,14 @@ "compilerOptions": { "module": "commonjs", "esModuleInterop": true, - "target": "es6", + "target": "es2018", "moduleResolution": "node", "sourceMap": true, "typeRoots" : ["./src/@types", "./node_modules/@types"], "strict": true, "forceConsistentCasingInFileNames": true, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, "baseUrl": ".", "paths": { "@src/*": ["src/*"], @@ -26,5 +28,5 @@ "@config": ["config"] } }, - "lib": ["es2015"] + "lib": ["es2018", "esnext.asynciterable"] } \ No newline at end of file