diff --git a/src/main/java/graphql/schema/GraphQLSchema.java b/src/main/java/graphql/schema/GraphQLSchema.java index e365ef774b..e7026ad6c3 100644 --- a/src/main/java/graphql/schema/GraphQLSchema.java +++ b/src/main/java/graphql/schema/GraphQLSchema.java @@ -71,7 +71,7 @@ public class GraphQLSchema { private final ImmutableMap> interfaceNameToObjectTypeNames; /* - * This constructs partial GraphQL schema object which has has the schema (query / mutation / subscription) trees + * This constructs partial GraphQL schema object which has the schema (query / mutation / subscription) trees * in it but it does not have the collected types, code registry nor the type references replaced * * But it can be traversed to discover all that and filled out later via another constructor. @@ -104,7 +104,7 @@ private GraphQLSchema(Builder builder) { } /* - * This constructs a full fledged graphql schema object that has not yet had its type references replaced + * This constructs a fully fledged graphql schema object that has not yet had its type references replaced * but it's otherwise complete */ @Internal @@ -255,7 +255,7 @@ public List getTypes(Collection typeNames) { /** * Gets the named type from the schema or null if it's not present. - * + *

* Warning - you are inviting class cast errors if the types are not what you expect. * * @param typeName the name of the type to retrieve @@ -286,7 +286,7 @@ public boolean containsType(String typeName) { * * @return a graphql object type or null if there is one * - * @throws graphql.GraphQLException if the type is NOT a object type + * @throws graphql.GraphQLException if the type is NOT an object type */ public GraphQLObjectType getObjectType(String typeName) { GraphQLType graphQLType = typeMap.get(typeName); @@ -433,14 +433,14 @@ public List getDirectives() { } /** - * @return a map of non repeatable directives by directive name + * @return a map of non-repeatable directives by directive name */ public Map getDirectivesByName() { return directiveDefinitionsHolder.getDirectivesByName(); } /** - * Returns a named directive that (for legacy reasons) will be only in the set of non repeatable directives + * Returns a named directive that (for legacy reasons) will be only in the set of non-repeatable directives * * @param directiveName the name of the directive to retrieve * @@ -535,7 +535,7 @@ public List getSchemaDirectives(String directiveName) { * directives for all schema elements, whereas this is just for the schema * element itself * - * @return a map of directives + * @return a list of directives */ public List getSchemaAppliedDirectives() { return schemaAppliedDirectivesHolder.getAppliedDirectives(); @@ -641,6 +641,7 @@ public static Builder newSchema(GraphQLSchema existingSchema) { .query(existingSchema.getQueryType()) .mutation(existingSchema.getMutationType()) .subscription(existingSchema.getSubscriptionType()) + .extensionDefinitions(existingSchema.getExtensionDefinitions()) .introspectionSchemaType(existingSchema.getIntrospectionSchemaType()) .codeRegistry(existingSchema.getCodeRegistry()) .clearAdditionalTypes() @@ -873,8 +874,8 @@ public GraphQLSchema build(Set additionalTypes) { /** * Builds the schema * - * @param additionalTypes - please don't use this any more - * @param additionalDirectives - please don't use this any more + * @param additionalTypes - please don't use this anymore + * @param additionalDirectives - please don't use this anymore * * @return the built schema * diff --git a/src/test/groovy/graphql/schema/GraphQLSchemaTest.groovy b/src/test/groovy/graphql/schema/GraphQLSchemaTest.groovy index de2a51bf04..bf18e083c2 100644 --- a/src/test/groovy/graphql/schema/GraphQLSchemaTest.groovy +++ b/src/test/groovy/graphql/schema/GraphQLSchemaTest.groovy @@ -5,6 +5,8 @@ import graphql.Directives import graphql.ExecutionInput import graphql.GraphQL import graphql.TestUtil +import graphql.language.Directive +import graphql.language.SchemaExtensionDefinition import graphql.schema.idl.RuntimeWiring import graphql.schema.idl.TypeRuntimeWiring import graphql.util.TraversalControl @@ -129,6 +131,23 @@ class GraphQLSchemaTest extends Specification { )) } + def "schema builder copies extension definitions"() { + setup: + def schemaBuilder = basicSchemaBuilder() + def newDirective = Directive.newDirective().name("pizza").build() + def extension = SchemaExtensionDefinition.newSchemaExtensionDefinition().directive(newDirective).build() + def oldSchema = schemaBuilder.extensionDefinitions([extension]).build() + + when: + def newSchema = GraphQLSchema.newSchema(oldSchema).build() + + then: + oldSchema.extensionDefinitions.size() == 1 + newSchema.extensionDefinitions.size() == 1 + ((Directive) oldSchema.extensionDefinitions.first().getDirectives().first()).name == "pizza" + ((Directive) newSchema.extensionDefinitions.first().getDirectives().first()).name == "pizza" + } + def "clear directives works as expected"() { setup: def schemaBuilder = basicSchemaBuilder() @@ -233,10 +252,8 @@ class GraphQLSchemaTest extends Specification { } union UnionType = Cat | Dog - ''' - when: def schema = TestUtil.schema(sdl)