Skip to content

Commit a3080af

Browse files
M-TGHtaion
authored andcommitted
Fix TypeErrors resulting from trying to use nulldata (#20)
1 parent 15f2f80 commit a3080af

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/index.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export class ComplexityVisitor {
9595

9696
getFieldCostFactor() {
9797
const fieldDef = this.context.getFieldDef();
98-
if (fieldDef.getCostFactor) {
98+
if (fieldDef && fieldDef.getCostFactor) {
9999
return fieldDef.getCostFactor();
100100
}
101101

@@ -131,7 +131,7 @@ export class ComplexityVisitor {
131131

132132
getFieldCost() {
133133
const fieldDef = this.context.getFieldDef();
134-
if (fieldDef.getCost) {
134+
if (fieldDef && fieldDef.getCost) {
135135
return fieldDef.getCost();
136136
}
137137

@@ -155,13 +155,11 @@ export class ComplexityVisitor {
155155

156156
getDirectiveValue(directiveName) {
157157
const fieldDef = this.context.getFieldDef();
158-
159-
const { astNode } = fieldDef;
160-
if (!astNode || !astNode.directives) {
158+
if (!fieldDef || !fieldDef.astNode || !fieldDef.astNode.directives) {
161159
return null;
162160
}
163161

164-
const directive = astNode.directives.find(
162+
const directive = fieldDef.astNode.directives.find(
165163
({ name }) => name.value === directiveName,
166164
);
167165
if (!directive) {

0 commit comments

Comments
 (0)