Skip to content

Commit de7932f

Browse files
committed
Resolve TypeReferences in schema applied directives
Fixes #3053
1 parent ed7ddf7 commit de7932f

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

src/main/java/graphql/schema/impl/SchemaUtil.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ public static void replaceTypeReferences(GraphQLSchema schema) {
100100
final Map<String, GraphQLNamedType> typeMap = schema.getTypeMap();
101101
List<GraphQLSchemaElement> roots = new ArrayList<>(typeMap.values());
102102
roots.addAll(schema.getDirectives());
103+
roots.addAll(schema.getSchemaAppliedDirectives());
103104
SchemaTraverser schemaTraverser = new SchemaTraverser(schemaElement -> schemaElement.getChildrenWithTypeReferences().getChildrenAsList());
104105
schemaTraverser.depthFirst(new GraphQLTypeResolvingVisitor(typeMap), roots);
105106
}

src/test/groovy/graphql/TypeReferenceSchema.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package graphql;
22

33
import graphql.schema.Coercing;
4+
import graphql.schema.GraphQLAppliedDirective;
5+
import graphql.schema.GraphQLAppliedDirectiveArgument;
46
import graphql.schema.GraphQLArgument;
57
import graphql.schema.GraphQLCodeRegistry;
68
import graphql.schema.GraphQLDirective;
@@ -315,6 +317,14 @@ public Boolean parseLiteral(Object input) {
315317
.type(QueryDirectiveInput))
316318
.build();
317319

320+
public static GraphQLAppliedDirective cacheApplied = GraphQLAppliedDirective.newDirective()
321+
.name("cache")
322+
.argument(GraphQLAppliedDirectiveArgument.newArgument()
323+
.name("enabled")
324+
.type(GraphQLTypeReference.typeRef(OnOff.getName()))
325+
.valueProgrammatic("On"))
326+
.build();
327+
318328
public static GraphQLCodeRegistry codeRegistry = GraphQLCodeRegistry.newCodeRegistry()
319329
.typeResolver("Pet", new TypeResolverProxy())
320330
.typeResolver("Addressable", new TypeResolverProxy())
@@ -336,5 +346,6 @@ public Boolean parseLiteral(Object input) {
336346
.additionalDirective(enumValueDirective)
337347
.additionalDirective(interfaceDirective)
338348
.codeRegistry(codeRegistry)
349+
.withSchemaAppliedDirectives(cacheApplied)
339350
.build();
340351
}

src/test/groovy/graphql/schema/impl/SchemaUtilTest.groovy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import graphql.AssertException
44
import graphql.DirectivesUtil
55
import graphql.NestedInputSchema
66
import graphql.introspection.Introspection
7+
import graphql.schema.GraphQLAppliedDirectiveArgument
78
import graphql.schema.GraphQLArgument
89
import graphql.schema.GraphQLFieldDefinition
910
import graphql.schema.GraphQLInputObjectType
@@ -164,12 +165,15 @@ class SchemaUtilTest extends Specification {
164165
GraphQLObjectType person = ((GraphQLObjectType) SchemaWithReferences.getType("Person"))
165166
GraphQLArgument cacheEnabled = SchemaWithReferences.getDirectivesByName()
166167
.get(Cache.getName()).getArgument("enabled")
168+
GraphQLAppliedDirectiveArgument appliedCacheEnabled = SchemaWithReferences.getSchemaAppliedDirective(Cache.getName())
169+
.getArgument("enabled")
167170

168171
then:
169172
SchemaWithReferences.allTypesAsList.findIndexOf { it instanceof GraphQLTypeReference } == -1
170173
pet.types.findIndexOf { it instanceof GraphQLTypeReference } == -1
171174
person.interfaces.findIndexOf { it instanceof GraphQLTypeReference } == -1
172175
!(cacheEnabled.getType() instanceof GraphQLTypeReference)
176+
!(appliedCacheEnabled.getType() instanceof GraphQLTypeReference)
173177
}
174178

175179
def "all references are replaced with deprecated directiveWithArg"() {

0 commit comments

Comments
 (0)