You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Add ES module support #37
* Update yarn.lock, consolidate tsconfig.cjs.json into tsconfig.json
* Fix linting issues
* Add createComplexityRule as named export
The complexity calculation of a GraphQL query can be customized with so called complexity estimators.
70
70
A complexity estimator is a simple function that calculates the complexity for a field. You can add
71
-
any number of complexity estimators to the rule, which are then executed one after another.
72
-
The first estimator that returns a numeric complexity value determines the complexity for that field.
71
+
any number of complexity estimators to the rule, which are then executed one after another.
72
+
The first estimator that returns a numeric complexity value determines the complexity for that field.
73
73
74
74
At least one estimator has to return a complexity value, otherwise an exception is raised. You can
75
75
for example use the [simpleEstimator](./src/estimators/simple/README.md) as the last estimator
76
-
in your chain to define a default value.
76
+
in your chain to define a default value.
77
77
78
78
You can use any of the available estimators to calculate the complexity of a field
79
79
or write your own:
80
80
81
-
***[`simpleEstimator`](src/estimators/simple/README.md):** The simple estimator returns a fixed complexity for each field. Can be used as
82
-
last estimator in the chain for a default value.
83
-
***[`directiveEstimator`](src/estimators/directive/README.md):** Set the complexity via a directive in your
84
-
schema definition (for example via GraphQL SDL)
85
-
***[`fieldExtensionsEstimator`](src/estimators/fieldExtensions/README.md):** The field extensions estimator lets you set a numeric value or a custom estimator
86
-
function in the field config extensions of your schema.
87
-
* PRs welcome...
81
+
-**[`simpleEstimator`](src/estimators/simple/README.md):** The simple estimator returns a fixed complexity for each field. Can be used as
82
+
last estimator in the chain for a default value.
83
+
-**[`directiveEstimator`](src/estimators/directive/README.md):** Set the complexity via a directive in your
84
+
schema definition (for example via GraphQL SDL)
85
+
-**[`fieldExtensionsEstimator`](src/estimators/fieldExtensions/README.md):** The field extensions estimator lets you set a numeric value or a custom estimator
86
+
function in the field config extensions of your schema.
87
+
- PRs welcome...
88
88
89
-
Consult the documentation of each estimator for information about how to use them.
89
+
Consult the documentation of each estimator for information about how to use them.
90
90
91
91
## Creating Custom Estimators
92
92
93
-
An estimator has the following function signature:
93
+
An estimator has the following function signature:
94
94
95
95
```typescript
96
96
typeComplexityEstimatorArgs= {
97
97
// The composite type (interface, object, union) that the evaluated field belongs to
98
-
type:GraphQLCompositeType,
99
-
98
+
type:GraphQLCompositeType;
99
+
100
100
// The GraphQLField that is being evaluated
101
-
field:GraphQLField<any, any>,
102
-
101
+
field:GraphQLField<any, any>;
102
+
103
103
// The GraphQL node that is being evaluated
104
-
node:FieldNode,
105
-
104
+
node:FieldNode;
105
+
106
106
// The input arguments of the field
107
-
args: {[key:string]:any},
108
-
107
+
args: {[key:string]:any };
108
+
109
109
// The complexity of all child selections for that field
0 commit comments