|
10 | 10 | import com.intuit.graphql.orchestrator.resolverdirective.InvalidDirectivePairingException;
|
11 | 11 | import com.intuit.graphql.orchestrator.resolverdirective.NotAValidLocationForFieldResolverDirective;
|
12 | 12 | import com.intuit.graphql.orchestrator.utils.XtextTypeUtils;
|
| 13 | +import com.intuit.graphql.orchestrator.utils.XtextUtils; |
13 | 14 | import com.intuit.graphql.orchestrator.xtext.XtextGraph;
|
14 | 15 | import java.util.ArrayList;
|
15 | 16 | import java.util.List;
|
@@ -58,34 +59,20 @@ private void validateFieldWithResolver(List<FieldResolverContext> fieldResolverC
|
58 | 59 | }
|
59 | 60 |
|
60 | 61 | EList<Directive> directives = fieldDefinition.getDirectives();
|
61 |
| - boolean hasResolverDirective = false; |
62 |
| - boolean hasExternalDirective = false; |
63 |
| - boolean hasProvidesDirective = false; |
64 |
| - boolean hasRequiresDirective = false; |
65 |
| - |
66 |
| - for (Directive directive : directives) { |
67 |
| - String directiveName = directive.getDefinition().getName(); |
68 |
| - switch (directiveName) { |
69 |
| - case "resolver": |
70 |
| - hasResolverDirective = true; |
71 |
| - break; |
72 |
| - case "external": |
73 |
| - hasExternalDirective = true; |
74 |
| - break; |
75 |
| - case "provides": |
76 |
| - hasProvidesDirective = true; |
77 |
| - break; |
78 |
| - case "requires": |
79 |
| - hasRequiresDirective = true; |
80 |
| - break; |
81 |
| - } |
82 |
| - } |
83 | 62 |
|
84 |
| - if (hasResolverDirective) { |
85 |
| - if (hasExternalDirective || hasProvidesDirective || hasRequiresDirective) { |
86 |
| - throw new InvalidDirectivePairingException(fieldName, parentTypeName); |
87 |
| - } |
| 63 | + boolean[] properDirectivesDefs = {false}; |
| 64 | + |
| 65 | + XtextUtils.getDirectivesWithNameFromDefinition((FieldDefinition) directives, "external") |
| 66 | + .forEach(directive -> properDirectivesDefs[0] = true); |
| 67 | + XtextUtils.getDirectivesWithNameFromDefinition((FieldDefinition) directives, "provides") |
| 68 | + .forEach(directive -> properDirectivesDefs[0] = true); |
| 69 | + XtextUtils.getDirectivesWithNameFromDefinition((FieldDefinition) directives, "requires") |
| 70 | + .forEach(directive -> properDirectivesDefs[0] = true); |
| 71 | + |
| 72 | + if(properDirectivesDefs[0]) { |
| 73 | + throw new InvalidDirectivePairingException(fieldName, parentTypeName); |
88 | 74 | }
|
| 75 | + |
89 | 76 | });
|
90 | 77 | }
|
91 | 78 |
|
|
0 commit comments