99import graphql .util .FpKit ;
1010
1111import java .util .Collection ;
12+ import java .util .Collections ;
1213import java .util .List ;
1314import java .util .Map ;
1415import java .util .Optional ;
@@ -91,7 +92,6 @@ public static GraphQLDirective getFirstDirective(String name, Map<String, List<G
9192 * directives collection takes precedence.
9293 *
9394 * @param directiveContainer the schema element holding applied directives
94- *
9595 * @return a combined list unique by name
9696 */
9797 public static List <GraphQLAppliedDirective > toAppliedDirectives (GraphQLDirectiveContainer directiveContainer ) {
@@ -104,7 +104,6 @@ public static List<GraphQLAppliedDirective> toAppliedDirectives(GraphQLDirective
104104 *
105105 * @param appliedDirectives the applied directives to use
106106 * @param directives the legacy directives to use
107- *
108107 * @return a combined list unique by name
109108 */
110109 public static List <GraphQLAppliedDirective > toAppliedDirectives (Collection <GraphQLAppliedDirective > appliedDirectives , Collection <GraphQLDirective > directives ) {
@@ -127,6 +126,7 @@ public static List<GraphQLAppliedDirective> toAppliedDirectives(Collection<Graph
127126 * A holder class that breaks a list of directives into maps to be more easily accessible in using classes
128127 */
129128 public static class DirectivesHolder {
129+ private static final DirectivesHolder EMPTY_HOLDER = new DirectivesHolder (Collections .emptyList (), Collections .emptyList ());
130130
131131 private final ImmutableMap <String , List <GraphQLDirective >> allDirectivesByName ;
132132 private final ImmutableMap <String , GraphQLDirective > nonRepeatableDirectivesByName ;
@@ -145,7 +145,14 @@ public DirectivesHolder(Collection<GraphQLDirective> allDirectives, Collection<G
145145
146146 this .allAppliedDirectives = ImmutableList .copyOf (allAppliedDirectives );
147147 this .allAppliedDirectivesByName = ImmutableMap .copyOf (FpKit .groupingBy (allAppliedDirectives , GraphQLAppliedDirective ::getName ));
148+ }
149+
150+ public static DirectivesHolder create (List <GraphQLDirective > directives , List <GraphQLAppliedDirective > appliedDirectives ) {
151+ if (directives .isEmpty () && appliedDirectives .isEmpty ()) {
152+ return EMPTY_HOLDER ;
153+ }
148154
155+ return new DirectivesHolder (directives , appliedDirectives );
149156 }
150157
151158 public ImmutableMap <String , List <GraphQLDirective >> getAllDirectivesByName () {
0 commit comments