Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

guard against undefined directives #1506

Merged
merged 1 commit into from
May 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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