Skip to content

Commit

Permalink
guard against undefined directives (#1506)
Browse files Browse the repository at this point in the history
in --some-- codebase locations!

closes #1486
  • Loading branch information
yaacovCR authored May 19, 2020
1 parent 5392a6d commit 861e467
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
6 changes: 4 additions & 2 deletions packages/utils/src/SchemaDirectiveVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,17 @@ export class SchemaDirectiveVisitor<TArgs = any, TContext = any> extends SchemaV
);

function visitorSelector(type: VisitableSchemaType, methodName: string): Array<SchemaDirectiveVisitor> {
let directiveNodes = type.astNode != null ? type.astNode.directives : [];
let directiveNodes = type?.astNode?.directives ?? [];

const extensionASTNodes: ReadonlyArray<TypeSystemExtensionNode> = (type as {
extensionASTNodes?: Array<TypeSystemExtensionNode>;
}).extensionASTNodes;

if (extensionASTNodes != null) {
extensionASTNodes.forEach(extensionASTNode => {
directiveNodes = directiveNodes.concat(extensionASTNode.directives);
if (extensionASTNode.directives != null) {
directiveNodes = directiveNodes.concat(extensionASTNode.directives);
}
});
}

Expand Down
26 changes: 14 additions & 12 deletions packages/utils/src/get-directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 861e467

Please sign in to comment.