Skip to content

Commit c71950c

Browse files
committed
PR follow up
1 parent 213fc1e commit c71950c

4 files changed

Lines changed: 65 additions & 6 deletions

File tree

src/main/java/graphql/schema/DelegatingDataFetchingEnvironment.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,6 @@ public CacheControl getCacheControl() {
137137
return delegateEnvironment.getCacheControl();
138138
}
139139

140-
@Override
141-
public Locale getLocale() {
142-
return delegateEnvironment.getLocale();
143-
}
144-
145140
public OperationDefinition getOperationDefinition() {
146141
return delegateEnvironment.getOperationDefinition();
147142
}

src/main/java/graphql/schema/GraphQLSchema.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import static graphql.Assert.assertNotNull;
2626
import static graphql.Assert.assertShouldNeverHappen;
2727
import static graphql.Assert.assertTrue;
28+
import static graphql.DirectivesUtil.directivesByName;
2829
import static graphql.schema.GraphqlTypeComparators.byNameAsc;
2930
import static graphql.schema.GraphqlTypeComparators.sortTypes;
3031
import static java.util.Arrays.asList;
@@ -225,10 +226,26 @@ public GraphqlFieldVisibility getFieldVisibility() {
225226
return codeRegistry.getFieldVisibility();
226227
}
227228

229+
/**
230+
* This returns the list of directives that are associated with this schema object including
231+
* built in ones.
232+
*
233+
* @return a list of directives
234+
*/
228235
public List<GraphQLDirective> getDirectives() {
229236
return new ArrayList<>(directives);
230237
}
231238

239+
/**
240+
* This returns a map of directives that are associated with this schema object including
241+
* built in ones.
242+
*
243+
* @return a map of directives
244+
*/
245+
public Map<String, GraphQLDirective> getDirectiveByName() {
246+
return directivesByName(getDirectives());
247+
}
248+
232249
public GraphQLDirective getDirective(String name) {
233250
for (GraphQLDirective directive : getDirectives()) {
234251
if (directive.getName().equals(name)) {
@@ -250,6 +267,18 @@ public List<GraphQLDirective> getSchemaDirectives() {
250267
return new ArrayList<>(schemaDirectives.values());
251268
}
252269

270+
/**
271+
* This returns a map of directives that have been explicitly put on the
272+
* schema object. Note that {@link {@link #getDirectives()}} will return
273+
* directives for all schema elements, whereas this is just for the schema
274+
* element itself
275+
*
276+
* @return a list of directives
277+
*/
278+
public Map<String, GraphQLDirective> getSchemaDirectiveByName() {
279+
return directivesByName(getSchemaDirectives());
280+
}
281+
253282
/**
254283
* This returns the named directive that have been explicitly put on the
255284
* schema object. Note that {@link {@link #getDirective(String)} ()}} will return

src/main/java/graphql/schema/idl/SchemaExtensionsChecker.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import graphql.Assert;
44
import graphql.GraphQLError;
5+
import graphql.Internal;
56
import graphql.language.Directive;
67
import graphql.language.ObjectTypeDefinition;
78
import graphql.language.OperationTypeDefinition;
@@ -23,6 +24,7 @@
2324
import java.util.Optional;
2425
import java.util.function.Consumer;
2526

27+
@Internal
2628
public class SchemaExtensionsChecker {
2729

2830
static Map<String, OperationTypeDefinition> gatherOperationDefs(TypeDefinitionRegistry typeRegistry) {

src/test/groovy/graphql/schema/idl/SchemaGeneratorTest.groovy

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1945,14 +1945,47 @@ class SchemaGeneratorTest extends Specification {
19451945
schema.getQueryType().name == 'Query'
19461946
schema.getMutationType().name == 'Mutation'
19471947
1948+
when:
19481949
def directives = schema.getSchemaDirectives()
1949-
directives.size() == 3
19501950
1951+
then:
1952+
directives.size() == 3
19511953
schema.getSchemaDirective("sd1") != null
19521954
schema.getSchemaDirective("sd2") != null
19531955
schema.getSchemaDirective("sd3") != null
19541956
1957+
when:
1958+
def directivesMap = schema.getSchemaDirectiveByName()
1959+
then:
1960+
directives.size() == 3
1961+
directivesMap["sd1"] != null
1962+
directivesMap["sd2"] != null
1963+
directivesMap["sd3"] != null
1964+
1965+
when:
1966+
directives = schema.getDirectives()
1967+
1968+
then:
1969+
directives.size() == 6 // built in ones : include / skip and deprecated
1970+
def directiveNames = directives.collect { it.name }
1971+
directiveNames.contains("include")
1972+
directiveNames.contains("skip")
1973+
directiveNames.contains("deprecated")
1974+
directiveNames.contains("sd1")
1975+
directiveNames.contains("sd2")
1976+
directiveNames.contains("sd3")
19551977
1978+
when:
1979+
directivesMap = schema.getDirectiveByName()
1980+
1981+
then:
1982+
directivesMap.size() == 6 // built in ones
1983+
directivesMap.containsKey("include")
1984+
directivesMap.containsKey("skip")
1985+
directivesMap.containsKey("deprecated")
1986+
directivesMap.containsKey("sd1")
1987+
directivesMap.containsKey("sd2")
1988+
directivesMap.containsKey("sd3")
19561989
}
19571990
19581991
def "directive arg descriptions are captured correctly"() {

0 commit comments

Comments
 (0)