From 65ae057b3fac68243f5c93d05026fa2855b603a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Lytek?= Date: Sun, 6 Oct 2019 18:21:43 +0200 Subject: [PATCH 1/2] feat(complexity): update `graphql-query-complexity` dependency --- CHANGELOG.md | 1 + package-lock.json | 564 +++++++++++++++++++++++++++++++++++++++++++++- package.json | 2 +- 3 files changed, 563 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe3995520..4e654e48b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Features - **Breaking Change**: emit in schema only types actually used by provided resolvers classes (#415) - **Breaking Change**: update `graphql-js` peer dependency to `^14.5.4` +- update `graphql-query-complexity` dependency to `^0.4.0` ### Fixes - refactor union types function syntax handling to prevent possible errors with circular refs diff --git a/package-lock.json b/package-lock.json index 84b1c1ca5..ec31e124b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -809,6 +809,7 @@ "anymatch": "^2.0.0", "async-each": "^1.0.1", "braces": "^2.3.2", + "fsevents": "^1.2.7", "glob-parent": "^3.1.0", "inherits": "^2.0.3", "is-binary-path": "^1.0.0", @@ -2309,6 +2310,7 @@ "anymatch": "^2.0.0", "async-each": "^1.0.0", "braces": "^2.3.0", + "fsevents": "^1.2.2", "glob-parent": "^3.1.0", "inherits": "^2.0.1", "is-binary-path": "^1.0.0", @@ -4035,6 +4037,554 @@ "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" }, + "fsevents": { + "version": "1.2.9", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-1.2.9.tgz", + "integrity": "sha512-oeyj2H3EjjonWcFjD5NvZNE9Rqe4UW+nQBU2HNeKw0koVLEFIhtyETyAakeAM3de7Z/SW5kcA+fZUait9EApnw==", + "dev": true, + "optional": true, + "requires": { + "nan": "^2.12.1", + "node-pre-gyp": "^0.12.0" + }, + "dependencies": { + "abbrev": { + "version": "1.1.1", + "bundled": true, + "dev": true, + "optional": true + }, + "ansi-regex": { + "version": "2.1.1", + "bundled": true, + "dev": true, + "optional": true + }, + "aproba": { + "version": "1.2.0", + "bundled": true, + "dev": true, + "optional": true + }, + "are-we-there-yet": { + "version": "1.1.5", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "delegates": "^1.0.0", + "readable-stream": "^2.0.6" + } + }, + "balanced-match": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "optional": true + }, + "brace-expansion": { + "version": "1.1.11", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "chownr": { + "version": "1.1.1", + "bundled": true, + "dev": true, + "optional": true + }, + "code-point-at": { + "version": "1.1.0", + "bundled": true, + "dev": true, + "optional": true + }, + "concat-map": { + "version": "0.0.1", + "bundled": true, + "dev": true, + "optional": true + }, + "console-control-strings": { + "version": "1.1.0", + "bundled": true, + "dev": true, + "optional": true + }, + "core-util-is": { + "version": "1.0.2", + "bundled": true, + "dev": true, + "optional": true + }, + "debug": { + "version": "4.1.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "ms": "^2.1.1" + } + }, + "deep-extend": { + "version": "0.6.0", + "bundled": true, + "dev": true, + "optional": true + }, + "delegates": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "optional": true + }, + "detect-libc": { + "version": "1.0.3", + "bundled": true, + "dev": true, + "optional": true + }, + "fs-minipass": { + "version": "1.2.5", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "minipass": "^2.2.1" + } + }, + "fs.realpath": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "optional": true + }, + "gauge": { + "version": "2.7.4", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "aproba": "^1.0.3", + "console-control-strings": "^1.0.0", + "has-unicode": "^2.0.0", + "object-assign": "^4.1.0", + "signal-exit": "^3.0.0", + "string-width": "^1.0.1", + "strip-ansi": "^3.0.1", + "wide-align": "^1.1.0" + } + }, + "glob": { + "version": "7.1.3", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, + "has-unicode": { + "version": "2.0.1", + "bundled": true, + "dev": true, + "optional": true + }, + "iconv-lite": { + "version": "0.4.24", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "safer-buffer": ">= 2.1.2 < 3" + } + }, + "ignore-walk": { + "version": "3.0.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "minimatch": "^3.0.4" + } + }, + "inflight": { + "version": "1.0.6", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "inherits": { + "version": "2.0.3", + "bundled": true, + "dev": true, + "optional": true + }, + "ini": { + "version": "1.3.5", + "bundled": true, + "dev": true, + "optional": true + }, + "is-fullwidth-code-point": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "number-is-nan": "^1.0.0" + } + }, + "isarray": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "optional": true + }, + "minimatch": { + "version": "3.0.4", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "brace-expansion": "^1.1.7" + } + }, + "minimist": { + "version": "0.0.8", + "bundled": true, + "dev": true, + "optional": true + }, + "minipass": { + "version": "2.3.5", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "safe-buffer": "^5.1.2", + "yallist": "^3.0.0" + } + }, + "minizlib": { + "version": "1.2.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "minipass": "^2.2.1" + } + }, + "mkdirp": { + "version": "0.5.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "minimist": "0.0.8" + } + }, + "ms": { + "version": "2.1.1", + "bundled": true, + "dev": true, + "optional": true + }, + "needle": { + "version": "2.3.0", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "debug": "^4.1.0", + "iconv-lite": "^0.4.4", + "sax": "^1.2.4" + } + }, + "node-pre-gyp": { + "version": "0.12.0", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "detect-libc": "^1.0.2", + "mkdirp": "^0.5.1", + "needle": "^2.2.1", + "nopt": "^4.0.1", + "npm-packlist": "^1.1.6", + "npmlog": "^4.0.2", + "rc": "^1.2.7", + "rimraf": "^2.6.1", + "semver": "^5.3.0", + "tar": "^4" + } + }, + "nopt": { + "version": "4.0.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "abbrev": "1", + "osenv": "^0.1.4" + } + }, + "npm-bundled": { + "version": "1.0.6", + "bundled": true, + "dev": true, + "optional": true + }, + "npm-packlist": { + "version": "1.4.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "ignore-walk": "^3.0.1", + "npm-bundled": "^1.0.1" + } + }, + "npmlog": { + "version": "4.1.2", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "are-we-there-yet": "~1.1.2", + "console-control-strings": "~1.1.0", + "gauge": "~2.7.3", + "set-blocking": "~2.0.0" + } + }, + "number-is-nan": { + "version": "1.0.1", + "bundled": true, + "dev": true, + "optional": true + }, + "object-assign": { + "version": "4.1.1", + "bundled": true, + "dev": true, + "optional": true + }, + "once": { + "version": "1.4.0", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "wrappy": "1" + } + }, + "os-homedir": { + "version": "1.0.2", + "bundled": true, + "dev": true, + "optional": true + }, + "os-tmpdir": { + "version": "1.0.2", + "bundled": true, + "dev": true, + "optional": true + }, + "osenv": { + "version": "0.1.5", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "os-homedir": "^1.0.0", + "os-tmpdir": "^1.0.0" + } + }, + "path-is-absolute": { + "version": "1.0.1", + "bundled": true, + "dev": true, + "optional": true + }, + "process-nextick-args": { + "version": "2.0.0", + "bundled": true, + "dev": true, + "optional": true + }, + "rc": { + "version": "1.2.8", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "deep-extend": "^0.6.0", + "ini": "~1.3.0", + "minimist": "^1.2.0", + "strip-json-comments": "~2.0.1" + }, + "dependencies": { + "minimist": { + "version": "1.2.0", + "bundled": true, + "dev": true, + "optional": true + } + } + }, + "readable-stream": { + "version": "2.3.6", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, + "rimraf": { + "version": "2.6.3", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "glob": "^7.1.3" + } + }, + "safe-buffer": { + "version": "5.1.2", + "bundled": true, + "dev": true, + "optional": true + }, + "safer-buffer": { + "version": "2.1.2", + "bundled": true, + "dev": true, + "optional": true + }, + "sax": { + "version": "1.2.4", + "bundled": true, + "dev": true, + "optional": true + }, + "semver": { + "version": "5.7.0", + "bundled": true, + "dev": true, + "optional": true + }, + "set-blocking": { + "version": "2.0.0", + "bundled": true, + "dev": true, + "optional": true + }, + "signal-exit": { + "version": "3.0.2", + "bundled": true, + "dev": true, + "optional": true + }, + "string-width": { + "version": "1.0.2", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "code-point-at": "^1.0.0", + "is-fullwidth-code-point": "^1.0.0", + "strip-ansi": "^3.0.0" + } + }, + "string_decoder": { + "version": "1.1.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "safe-buffer": "~5.1.0" + } + }, + "strip-ansi": { + "version": "3.0.1", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "ansi-regex": "^2.0.0" + } + }, + "strip-json-comments": { + "version": "2.0.1", + "bundled": true, + "dev": true, + "optional": true + }, + "tar": { + "version": "4.4.8", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "chownr": "^1.1.1", + "fs-minipass": "^1.2.5", + "minipass": "^2.3.4", + "minizlib": "^1.1.1", + "mkdirp": "^0.5.0", + "safe-buffer": "^5.1.2", + "yallist": "^3.0.2" + } + }, + "util-deprecate": { + "version": "1.0.2", + "bundled": true, + "dev": true, + "optional": true + }, + "wide-align": { + "version": "1.1.3", + "bundled": true, + "dev": true, + "optional": true, + "requires": { + "string-width": "^1.0.2 || 2" + } + }, + "wrappy": { + "version": "1.0.2", + "bundled": true, + "dev": true, + "optional": true + }, + "yallist": { + "version": "3.0.3", + "bundled": true, + "dev": true, + "optional": true + } + } + }, "function-bind": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", @@ -4304,9 +4854,9 @@ } }, "graphql-query-complexity": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/graphql-query-complexity/-/graphql-query-complexity-0.3.0.tgz", - "integrity": "sha512-JVqHT81Eh9O17iOjs1r1qzsh5YY2upfA3zoUsQGggT4d+1hajWitk4GQQY5SZtq5eul7y6jMsM9qRUSOAKhDJQ==", + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/graphql-query-complexity/-/graphql-query-complexity-0.4.0.tgz", + "integrity": "sha512-DsrYDk05G46dF9BfNCytIAXwQRcsDuRusO0BtcE7w/JUDx8iXtHucAJlfuFFwQXmBKLeW02x9FBsAPTivPB4Rw==", "requires": { "lodash.get": "^4.4.2" } @@ -5557,6 +6107,7 @@ "@jest/types": "^24.9.0", "anymatch": "^2.0.0", "fb-watchman": "^2.0.0", + "fsevents": "^1.2.7", "graceful-fs": "^4.1.15", "invariant": "^2.2.4", "jest-serializer": "^24.9.0", @@ -7076,6 +7627,13 @@ "thenify-all": "^1.0.0" } }, + "nan": { + "version": "2.14.0", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.14.0.tgz", + "integrity": "sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg==", + "dev": true, + "optional": true + }, "nanomatch": { "version": "1.2.9", "resolved": "https://registry.npmjs.org/nanomatch/-/nanomatch-1.2.9.tgz", diff --git a/package.json b/package.json index f458d9f10..620d6e48a 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "@types/semver": "^6.0.2", "class-validator": ">=0.9.1", "glob": "^7.1.4", - "graphql-query-complexity": "^0.3.0", + "graphql-query-complexity": "^0.4.0", "graphql-subscriptions": "^1.1.0", "semver": "^6.3.0", "tslib": "^1.10.0" From 1cd84f7f8679d09ab744091d15a2e1061c1e0fa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Lytek?= Date: Sun, 6 Oct 2019 18:23:07 +0200 Subject: [PATCH 2/2] feat(complexity): add support only for `fieldExtensionsEstimator` --- CHANGELOG.md | 4 +--- docs/complexity.md | 4 ++-- examples/query-complexity/index.ts | 6 +++--- src/schema/schema-generator.ts | 8 ++++++-- tests/functional/resolvers.ts | 6 +++--- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e654e48b..c30e06505 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,8 +5,7 @@ ### Features - **Breaking Change**: emit in schema only types actually used by provided resolvers classes (#415) - **Breaking Change**: update `graphql-js` peer dependency to `^14.5.4` -- update `graphql-query-complexity` dependency to `^0.4.0` - +- **Breaking Change**: update `graphql-query-complexity` dependency to `^0.4.0` and drop support for `fieldConfigEstimator` (use `fieldExtensionsEstimator` instead) ### Fixes - refactor union types function syntax handling to prevent possible errors with circular refs @@ -16,7 +15,6 @@ - update deps to newest minor versions (`tslib`, `semver`, `graphql-query-complexity` and `glob`) - support nested array types (`@Field(type => [[Int]])`) (#393) - deprecate the direct array syntax for union types - ### Fixes - fix errors on circular refs in union types (#364) by adding the function syntax (`() => TClassTypes`) diff --git a/docs/complexity.md b/docs/complexity.md index 8b69edd7d..55d565a7e 100644 --- a/docs/complexity.md +++ b/docs/complexity.md @@ -63,8 +63,8 @@ async function bootstrap() { // numeric value that is being returned by an estimator is used as the field complexity. // If no estimator returns a value, an exception is raised. estimators: [ - // Using fieldConfigEstimator is mandatory to make it work with type-graphql. - fieldConfigEstimator(), + // Using fieldExtensionsEstimator is mandatory to make it work with type-graphql. + fieldExtensionsEstimator(), // Add more estimators here... // This will assign each field a complexity of 1 // if no other estimator returned a value. diff --git a/examples/query-complexity/index.ts b/examples/query-complexity/index.ts index e4998b0f9..020f3936c 100644 --- a/examples/query-complexity/index.ts +++ b/examples/query-complexity/index.ts @@ -1,6 +1,6 @@ import "reflect-metadata"; import { ApolloServer } from "apollo-server"; -import { getComplexity, simpleEstimator, fieldConfigEstimator } from "graphql-query-complexity"; +import { getComplexity, simpleEstimator, fieldExtensionsEstimator } from "graphql-query-complexity"; import { separateOperations } from "graphql"; import { buildSchema } from "../../src"; @@ -40,8 +40,8 @@ async function bootstrap() { // numeric value that is being returned by an estimator is used as the field complexity. // If no estimator returns a value, an exception is raised. estimators: [ - // Using fieldConfigEstimator is mandatory to make it work with type-graphql. - fieldConfigEstimator(), + // Using fieldExtensionsEstimator is mandatory to make it work with type-graphql. + fieldExtensionsEstimator(), // Add more estimators here... // This will assign each field a complexity of 1 // if no other estimator returned a value. diff --git a/src/schema/schema-generator.ts b/src/schema/schema-generator.ts index a45b57b93..473bcbf85 100644 --- a/src/schema/schema-generator.ts +++ b/src/schema/schema-generator.ts @@ -295,13 +295,15 @@ export abstract class SchemaGenerator { ); fieldsMap[field.schemaName] = { type: this.getGraphQLOutputType(field.name, field.getType(), field.typeOptions), - complexity: field.complexity, args: this.generateHandlerArgs(field.params!), resolve: fieldResolverMetadata ? createAdvancedFieldResolver(fieldResolverMetadata) : createSimpleFieldResolver(field), description: field.description, deprecationReason: field.deprecationReason, + extensions: { + complexity: field.complexity, + }, }; return fieldsMap; }, @@ -457,7 +459,9 @@ export abstract class SchemaGenerator { resolve: createHandlerResolver(handler), description: handler.description, deprecationReason: handler.deprecationReason, - complexity: handler.complexity, + extensions: { + complexity: handler.complexity, + }, }; return fields; }, {}); diff --git a/tests/functional/resolvers.ts b/tests/functional/resolvers.ts index 1d611f02c..9af4fc27f 100644 --- a/tests/functional/resolvers.ts +++ b/tests/functional/resolvers.ts @@ -19,7 +19,7 @@ import { } from "graphql"; import * as path from "path"; import { plainToClass } from "class-transformer"; -import { fieldConfigEstimator, simpleEstimator } from "graphql-query-complexity"; +import { fieldExtensionsEstimator, simpleEstimator } from "graphql-query-complexity"; import ComplexityVisitor from "graphql-query-complexity/dist/QueryComplexity"; import { @@ -1112,7 +1112,7 @@ describe("Resolvers", () => { const context = new ValidationContext(schema, ast, typeInfo); const visitor = new ComplexityVisitor(context, { maximumComplexity, - estimators: [fieldConfigEstimator(), simpleEstimator({ defaultComplexity: 1 })], + estimators: [fieldExtensionsEstimator(), simpleEstimator({ defaultComplexity: 1 })], }); visit(ast, visitWithTypeInfo(typeInfo, visitor)); return context; @@ -1897,7 +1897,7 @@ describe("Resolvers", () => { const context = new ValidationContext(schema, ast, typeInfo); const visitor = new ComplexityVisitor(context, { maximumComplexity: 2, - estimators: [fieldConfigEstimator(), simpleEstimator({ defaultComplexity: 1 })], + estimators: [fieldExtensionsEstimator(), simpleEstimator({ defaultComplexity: 1 })], }); visit(ast, visitWithTypeInfo(typeInfo, visitor)); expect(context.getErrors().length).toEqual(1);