Skip to content

Commit 1951ed6

Browse files
committed
This adds support for QueryAppliedDirective on operations and documents - refactor
1 parent 1740162 commit 1951ed6

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/main/java/graphql/execution/directives/DirectivesResolver.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import com.google.common.collect.BiMap;
44
import com.google.common.collect.HashBiMap;
55
import com.google.common.collect.ImmutableBiMap;
6-
import com.google.common.collect.ImmutableList;
76
import graphql.GraphQLContext;
87
import graphql.Internal;
8+
import graphql.collect.ImmutableKit;
99
import graphql.execution.CoercedVariables;
1010
import graphql.execution.ValuesResolver;
1111
import graphql.language.Directive;
@@ -14,7 +14,6 @@
1414
import graphql.schema.GraphQLDirective;
1515
import graphql.schema.GraphQLSchema;
1616

17-
import java.util.Collection;
1817
import java.util.List;
1918
import java.util.Locale;
2019
import java.util.Map;
@@ -66,13 +65,16 @@ private void buildArguments(GraphQLDirective.Builder directiveBuilder,
6665

6766
public List<QueryAppliedDirective> toAppliedDirectives(List<Directive> directives, GraphQLSchema schema, CoercedVariables variables, GraphQLContext graphQLContext, Locale locale) {
6867
BiMap<GraphQLDirective, Directive> directivesMap = resolveDirectives(directives, schema, variables, graphQLContext, locale);
69-
return toAppliedDirectives(directivesMap.keySet());
70-
}
71-
72-
public List<QueryAppliedDirective> toAppliedDirectives(Collection<GraphQLDirective> directives) {
73-
return directives.stream().map(this::toAppliedDirective).collect(ImmutableList.toImmutableList());
68+
return ImmutableKit.map(directivesMap.keySet(), this::toAppliedDirective);
7469
}
7570

71+
/**
72+
* This helps us remodel the applied GraphQLDirective back to the better modelled and named {@link QueryAppliedDirective}
73+
*
74+
* @param directive the directive to remodel
75+
*
76+
* @return a QueryAppliedDirective
77+
*/
7678
public QueryAppliedDirective toAppliedDirective(GraphQLDirective directive) {
7779
QueryAppliedDirective.Builder builder = QueryAppliedDirective.newDirective();
7880
builder.name(directive.getName());

0 commit comments

Comments
 (0)