File tree 1 file changed +27
-0
lines changed
1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -104,6 +104,33 @@ type ComplexityEstimatorArgs = {
104
104
type ComplexityEstimator = (options : ComplexityEstimatorArgs ) => number | void ;
105
105
```
106
106
107
+ ## Calculate query complexity
108
+ ``` javascript
109
+ import { calculateComplexity , simpleEstimator } from " graphql-query-complexity/dist/QueryComplexity" ;
110
+ import { parse } from ' graphql' ;
111
+
112
+ // In a resolver the schema can be retrieved from the info argument.
113
+ const schema = undefined ;
114
+ const query = parse (`
115
+ query {
116
+ some_value
117
+ some_list(count: 10) {
118
+ some_child_value
119
+ }
120
+ }
121
+ ` );
122
+
123
+ const complexity = calculateComplexity ({
124
+ estimators: [
125
+ simpleEstimator ({defaultComplexity: 1 })
126
+ ],
127
+ schema,
128
+ query
129
+ });
130
+
131
+ console .log (complexity); // Output: 3
132
+ ```
133
+
107
134
## Usage with express-graphql
108
135
109
136
To use the query complexity analysis validation rule with express-graphql, use something like the
You can’t perform that action at this time.
0 commit comments