Skip to content

Commit 5444e27

Browse files
committed
Replace fieldConfigEstimator usage in tests with fieldExtensionsEstimator. Remove fieldConfigEstimator and legacyEstimator.
1 parent 38aafdc commit 5444e27

File tree

12 files changed

+29
-1076
lines changed

12 files changed

+29
-1076
lines changed

src/QueryComplexity.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ import {
3030
GraphQLError
3131
} from 'graphql';
3232
import {
33-
simpleEstimator,
34-
legacyEstimator
33+
simpleEstimator
3534
} from './estimators';
3635

3736
declare module 'graphql/type/definition' {
@@ -135,7 +134,6 @@ export default class QueryComplexity {
135134
}
136135

137136
this.estimators = options.estimators || [
138-
legacyEstimator(),
139137
simpleEstimator()
140138
];
141139

@@ -178,7 +176,7 @@ export default class QueryComplexity {
178176
if (typeof this.options.operationName === 'string' && this.options.operationName !== operation.name.value) {
179177
return;
180178
}
181-
179+
182180
if (this.options.onComplete) {
183181
this.options.onComplete(this.complexity);
184182
}

src/__tests__/QueryComplexity-test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import ComplexityVisitor, {getComplexity} from '../QueryComplexity';
1919
import {
2020
simpleEstimator,
2121
directiveEstimator,
22-
fieldConfigEstimator,
22+
fieldExtensionsEstimator,
2323
} from '../index';
2424

2525
describe('QueryComplexity analysis', () => {
@@ -136,7 +136,7 @@ describe('QueryComplexity analysis', () => {
136136

137137
const complexity = getComplexity({
138138
estimators: [
139-
fieldConfigEstimator(),
139+
fieldExtensionsEstimator(),
140140
simpleEstimator({defaultComplexity: 1})
141141
],
142142
schema,
@@ -179,7 +179,7 @@ describe('QueryComplexity analysis', () => {
179179
const visitor = new ComplexityVisitor(context, {
180180
maximumComplexity: 100,
181181
estimators: [
182-
fieldConfigEstimator(),
182+
fieldExtensionsEstimator(),
183183
simpleEstimator({
184184
defaultComplexity: 1
185185
})
@@ -209,7 +209,7 @@ describe('QueryComplexity analysis', () => {
209209
const visitor = new ComplexityVisitor(context, {
210210
maximumComplexity: 100,
211211
estimators: [
212-
fieldConfigEstimator(),
212+
fieldExtensionsEstimator(),
213213
simpleEstimator({
214214
defaultComplexity: 1
215215
})
@@ -236,7 +236,7 @@ describe('QueryComplexity analysis', () => {
236236
const visitor = new ComplexityVisitor(context, {
237237
maximumComplexity: 100,
238238
estimators: [
239-
fieldConfigEstimator(),
239+
fieldExtensionsEstimator(),
240240
simpleEstimator({
241241
defaultComplexity: 1
242242
})
@@ -263,7 +263,7 @@ describe('QueryComplexity analysis', () => {
263263
const visitor = new ComplexityVisitor(context, {
264264
maximumComplexity: 100,
265265
estimators: [
266-
fieldConfigEstimator(),
266+
fieldExtensionsEstimator(),
267267
simpleEstimator({
268268
defaultComplexity: 1
269269
})
@@ -290,7 +290,7 @@ describe('QueryComplexity analysis', () => {
290290
const visitor = new ComplexityVisitor(context, {
291291
maximumComplexity: 100,
292292
estimators: [
293-
fieldConfigEstimator(),
293+
fieldExtensionsEstimator(),
294294
simpleEstimator({
295295
defaultComplexity: 1
296296
})
@@ -316,7 +316,7 @@ describe('QueryComplexity analysis', () => {
316316
const visitor = new ComplexityVisitor(context, {
317317
maximumComplexity: 100,
318318
estimators: [
319-
fieldConfigEstimator(),
319+
fieldExtensionsEstimator(),
320320
simpleEstimator({
321321
defaultComplexity: 1
322322
})
@@ -338,7 +338,7 @@ describe('QueryComplexity analysis', () => {
338338
const visitor = new ComplexityVisitor(context, {
339339
maximumComplexity: 100,
340340
estimators: [
341-
fieldConfigEstimator(),
341+
fieldExtensionsEstimator(),
342342
simpleEstimator({
343343
defaultComplexity: 1
344344
})
@@ -360,7 +360,7 @@ describe('QueryComplexity analysis', () => {
360360
const visitor = new ComplexityVisitor(context, {
361361
maximumComplexity: 100,
362362
estimators: [
363-
fieldConfigEstimator(),
363+
fieldExtensionsEstimator(),
364364
simpleEstimator({
365365
defaultComplexity: 1
366366
})
@@ -402,7 +402,7 @@ describe('QueryComplexity analysis', () => {
402402
const visitor = new ComplexityVisitor(context, {
403403
maximumComplexity: 100,
404404
estimators: [
405-
fieldConfigEstimator()
405+
fieldExtensionsEstimator()
406406
]
407407
});
408408
visit(ast, visitWithTypeInfo(typeInfo, visitor));
@@ -468,7 +468,7 @@ describe('QueryComplexity analysis', () => {
468468

469469
const complexity1 = getComplexity({
470470
estimators: [
471-
fieldConfigEstimator(),
471+
fieldExtensionsEstimator(),
472472
simpleEstimator({defaultComplexity: 1})
473473
],
474474
schema,
@@ -478,7 +478,7 @@ describe('QueryComplexity analysis', () => {
478478

479479
const complexity2 = getComplexity({
480480
estimators: [
481-
fieldConfigEstimator(),
481+
fieldExtensionsEstimator(),
482482
simpleEstimator({defaultComplexity: 1})
483483
],
484484
schema,

src/__tests__/fixtures/schema.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,22 @@ const Item: GraphQLObjectType = new GraphQLObjectType({
2121
fields: () => ({
2222
variableList: {
2323
type: Item,
24-
complexity: (args: ComplexityEstimatorArgs) => args.childComplexity * (args.args.count || 10),
24+
extensions: {
25+
complexity: (args: ComplexityEstimatorArgs) => args.childComplexity * (args.args.count || 10)
26+
},
2527
args: {
2628
count: {
2729
type: GraphQLInt
2830
}
2931
}
3032
},
3133
scalar: { type: GraphQLString },
32-
complexScalar: { type: GraphQLString, complexity: 20 },
34+
complexScalar: { type: GraphQLString, extensions: { complexity: 20 } },
3335
variableScalar: {
3436
type: Item,
35-
complexity: (args: ComplexityEstimatorArgs) => 10 * (args.args.count || 10),
37+
extensions: {
38+
complexity: (args: ComplexityEstimatorArgs) => 10 * (args.args.count || 10)
39+
},
3640
args: {
3741
count: {
3842
type: GraphQLInt
@@ -97,7 +101,9 @@ const Query = new GraphQLObjectType({
97101
name: { type: GraphQLString },
98102
variableList: {
99103
type: Item,
100-
complexity: (args: ComplexityEstimatorArgs) => args.childComplexity * (args.args.count || 10),
104+
extensions: {
105+
complexity: (args: ComplexityEstimatorArgs) => args.childComplexity * (args.args.count || 10)
106+
},
101107
args: {
102108
count: {
103109
type: GraphQLInt
@@ -107,11 +113,13 @@ const Query = new GraphQLObjectType({
107113
interface: {type: NameInterface},
108114
enum: {type: EnumType},
109115
scalar: { type: GraphQLString },
110-
complexScalar: { type: GraphQLString, complexity: 20 },
116+
complexScalar: { type: GraphQLString, extensions: { complexity: 20 } },
111117
union: { type: Union },
112118
variableScalar: {
113119
type: Item,
114-
complexity: (args: ComplexityEstimatorArgs) => 10 * (args.args.count || 10),
120+
extensions: {
121+
complexity: (args: ComplexityEstimatorArgs) => 10 * (args.args.count || 10)
122+
},
115123
args: {
116124
count: {
117125
type: GraphQLInt

src/estimators/fieldConfig/README.md

Lines changed: 0 additions & 90 deletions
This file was deleted.

0 commit comments

Comments
 (0)