Skip to content

Commit ae9e7f9

Browse files
committed
Use uniqueDirectiveMap instead of repeatableMap
1 parent 3a7fafa commit ae9e7f9

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

src/validation/rules/UniqueDirectivesPerLocation.js

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,20 @@ export function duplicateDirectiveMessage(directiveName: string): string {
3333
export function UniqueDirectivesPerLocation(
3434
context: ValidationContext | SDLValidationContext,
3535
): ASTVisitor {
36-
const repeatableMap = Object.create(null);
36+
const uniqueDirectiveMap = Object.create(null);
3737

3838
const schema = context.getSchema();
3939
const definedDirectives = schema
4040
? schema.getDirectives()
4141
: specifiedDirectives;
4242
for (const directive of definedDirectives) {
43-
repeatableMap[directive.name] = directive.repeatable;
43+
uniqueDirectiveMap[directive.name] = !directive.repeatable;
4444
}
4545

4646
const astDefinitions = context.getDocument().definitions;
4747
for (const def of astDefinitions) {
4848
if (def.kind === Kind.DIRECTIVE_DEFINITION) {
49-
repeatableMap[def.name.value] = def.repeatable;
49+
uniqueDirectiveMap[def.name.value] = !def.repeatable;
5050
}
5151
}
5252

@@ -62,21 +62,18 @@ export function UniqueDirectivesPerLocation(
6262
const knownDirectives = Object.create(null);
6363
for (const directive of directives) {
6464
const directiveName = directive.name.value;
65-
const repeatable = repeatableMap[directiveName];
6665

67-
if (repeatable === undefined || repeatable) {
68-
continue;
69-
}
70-
71-
if (knownDirectives[directiveName]) {
72-
context.reportError(
73-
new GraphQLError(duplicateDirectiveMessage(directiveName), [
74-
knownDirectives[directiveName],
75-
directive,
76-
]),
77-
);
78-
} else {
79-
knownDirectives[directiveName] = directive;
66+
if (uniqueDirectiveMap[directiveName]) {
67+
if (knownDirectives[directiveName]) {
68+
context.reportError(
69+
new GraphQLError(duplicateDirectiveMessage(directiveName), [
70+
knownDirectives[directiveName],
71+
directive,
72+
]),
73+
);
74+
} else {
75+
knownDirectives[directiveName] = directive;
76+
}
8077
}
8178
}
8279
}

0 commit comments

Comments
 (0)