diff --git a/packages/utils/src/SchemaDirectiveVisitor.ts b/packages/utils/src/SchemaDirectiveVisitor.ts index d75bde54254..a726d552ec2 100644 --- a/packages/utils/src/SchemaDirectiveVisitor.ts +++ b/packages/utils/src/SchemaDirectiveVisitor.ts @@ -135,7 +135,7 @@ export class SchemaDirectiveVisitor extends SchemaV ); function visitorSelector(type: VisitableSchemaType, methodName: string): Array { - let directiveNodes = type.astNode != null ? type.astNode.directives : []; + let directiveNodes = type?.astNode?.directives ?? []; const extensionASTNodes: ReadonlyArray = (type as { extensionASTNodes?: Array; @@ -143,7 +143,9 @@ export class SchemaDirectiveVisitor extends SchemaV if (extensionASTNodes != null) { extensionASTNodes.forEach(extensionASTNode => { - directiveNodes = directiveNodes.concat(extensionASTNode.directives); + if (extensionASTNode.directives != null) { + directiveNodes = directiveNodes.concat(extensionASTNode.directives); + } }); } diff --git a/packages/utils/src/get-directives.ts b/packages/utils/src/get-directives.ts index 43c725c1fd7..4e7a0f8d562 100644 --- a/packages/utils/src/get-directives.ts +++ b/packages/utils/src/get-directives.ts @@ -74,22 +74,24 @@ export function getDirectives(schema: GraphQLSchema, node: DirectableGraphQLObje const result: DirectiveUseMap = {}; astNodes.forEach(astNode => { - astNode.directives.forEach(directive => { - const schemaDirective = schemaDirectiveMap[directive.name.value]; - if (schemaDirective) { - const directiveValue = getDirectiveValues(schemaDirective, astNode); + if (astNode.directives) { + astNode.directives.forEach(directive => { + const schemaDirective = schemaDirectiveMap[directive.name.value]; + if (schemaDirective) { + const directiveValue = getDirectiveValues(schemaDirective, astNode); - if (schemaDirective.isRepeatable) { - if (result[schemaDirective.name]) { - result[schemaDirective.name] = result[schemaDirective.name].concat([directiveValue]); + if (schemaDirective.isRepeatable) { + if (result[schemaDirective.name]) { + result[schemaDirective.name] = result[schemaDirective.name].concat([directiveValue]); + } else { + result[schemaDirective.name] = [directiveValue]; + } } else { - result[schemaDirective.name] = [directiveValue]; + result[schemaDirective.name] = directiveValue; } - } else { - result[schemaDirective.name] = directiveValue; } - } - }); + }); + } }); return result;