File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -104,6 +104,33 @@ type ComplexityEstimatorArgs = {
104104type ComplexityEstimator = (options : ComplexityEstimatorArgs ) => number | void ;
105105```
106106
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+
107134## Usage with express-graphql
108135
109136To 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