Skip to content

Commit 1fee982

Browse files
committed
Export complexity directive
1 parent 50c7575 commit 1fee982

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/estimators/directive/index.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,9 @@ import { GraphQLDirective } from 'graphql/type/directives';
44
import { DirectiveLocation } from 'graphql/language/directiveLocation';
55
import get from 'lodash.get';
66

7-
export default function (options?: {}): ComplexityEstimator {
8-
const mergedOptions = {
9-
name: 'complexity',
10-
...(options || {})
11-
};
12-
13-
const directive = new GraphQLDirective({
14-
name: mergedOptions.name,
7+
export function complexityDirective(name: string = 'complexity') {
8+
return new GraphQLDirective({
9+
name,
1510
description: 'Define a relation between the field and other nodes',
1611
locations: [
1712
DirectiveLocation.FIELD,
@@ -26,6 +21,10 @@ export default function (options?: {}): ComplexityEstimator {
2621
}
2722
},
2823
});
24+
}
25+
26+
export default function (options: { name?: string } = {}): ComplexityEstimator {
27+
const directive = complexityDirective(options.name);
2928

3029
return (args: ComplexityEstimatorArgs) => {
3130
// Ignore if astNode is undefined

src/estimators/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export {default as simpleEstimator} from './simple';
2-
export {default as directiveEstimator} from './directive';
2+
export {default as directiveEstimator, complexityDirective} from './directive';
33
export {default as fieldExtensionsEstimator} from './fieldExtensions';

0 commit comments

Comments
 (0)