Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions src/main/java/graphql/schema/SchemaTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,7 @@
import graphql.util.TraverserContext;
import graphql.util.TraverserVisitor;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.function.Consumer;

import static graphql.Assert.assertNotEmpty;
Expand Down Expand Up @@ -539,7 +530,7 @@ private static class DummyRoot implements GraphQLSchemaElement {
GraphQLObjectType mutation;
GraphQLObjectType subscription;
GraphQLObjectType introspectionSchemaType;
Set<GraphQLType> additionalTypes;
Set<GraphQLType> allTypesExceptOperationTypes;
Set<GraphQLDirective> directives;
Set<GraphQLDirective> schemaDirectives;
Set<GraphQLAppliedDirective> schemaAppliedDirectives;
Expand All @@ -550,13 +541,27 @@ private static class DummyRoot implements GraphQLSchemaElement {
query = schema.getQueryType();
mutation = schema.isSupportingMutations() ? schema.getMutationType() : null;
subscription = schema.isSupportingSubscriptions() ? schema.getSubscriptionType() : null;
additionalTypes = schema.getAdditionalTypes();
allTypesExceptOperationTypes = allTypesExceptOpOnes(schema);
schemaDirectives = new LinkedHashSet<>(schema.getSchemaDirectives());
schemaAppliedDirectives = new LinkedHashSet<>(schema.getSchemaAppliedDirectives());
directives = new LinkedHashSet<>(schema.getDirectives());
introspectionSchemaType = schema.getIntrospectionSchemaType();
}

private Set<GraphQLType> allTypesExceptOpOnes(GraphQLSchema schema) {
Set<GraphQLType> types = new HashSet<>(schema.getTypeMap().values());
removeIfNotNull(types, schema.getQueryType());
removeIfNotNull(types, schema.getMutationType());
removeIfNotNull(types, schema.getSubscriptionType());
return types;
}

private void removeIfNotNull(Set<GraphQLType> types, GraphQLType type) {
if (type != null) {
types.remove(type);
}
}

DummyRoot(GraphQLSchemaElement schemaElement) {
this.schemaElement = schemaElement;
}
Expand Down Expand Up @@ -584,7 +589,7 @@ public SchemaElementChildrenContainer getChildrenWithTypeReferences() {
if (schema.isSupportingSubscriptions()) {
builder.child(SUBSCRIPTION, subscription);
}
builder.children(ADD_TYPES, additionalTypes);
builder.children(ADD_TYPES, allTypesExceptOperationTypes);
builder.children(DIRECTIVES, directives);
builder.children(SCHEMA_DIRECTIVES, schemaDirectives);
builder.children(SCHEMA_APPLIED_DIRECTIVES, schemaAppliedDirectives);
Expand All @@ -604,7 +609,7 @@ public GraphQLSchemaElement withNewChildren(SchemaElementChildrenContainer newCh
mutation = newChildren.getChildOrNull(MUTATION);
subscription = newChildren.getChildOrNull(SUBSCRIPTION);
introspectionSchemaType = newChildren.getChildOrNull(INTROSPECTION);
additionalTypes = new LinkedHashSet<>(newChildren.getChildren(ADD_TYPES));
allTypesExceptOperationTypes = new LinkedHashSet<>(newChildren.getChildren(ADD_TYPES));
directives = new LinkedHashSet<>(newChildren.getChildren(DIRECTIVES));
schemaDirectives = new LinkedHashSet<>(newChildren.getChildren(SCHEMA_DIRECTIVES));
schemaAppliedDirectives = new LinkedHashSet<>(newChildren.getChildren(SCHEMA_APPLIED_DIRECTIVES));
Expand All @@ -621,7 +626,7 @@ public GraphQLSchema rebuildSchema(GraphQLCodeRegistry.Builder codeRegistry) {
.query(this.query)
.mutation(this.mutation)
.subscription(this.subscription)
.additionalTypes(this.additionalTypes)
.additionalTypes(this.allTypesExceptOperationTypes)
.additionalDirectives(this.directives)
.introspectionSchemaType(this.introspectionSchemaType)
.withSchemaDirectives(this.schemaDirectives)
Expand Down
14 changes: 7 additions & 7 deletions src/test/groovy/graphql/schema/SchemaTransformerTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -1056,13 +1056,13 @@ type Query {
"""

def schema = TestUtil.schema(sdl)
schema = schema.transform { builder ->
for (def type : schema.getTypeMap().values()) {
if (type != schema.getQueryType() && type != schema.getMutationType() && type != schema.getSubscriptionType()) {
builder.additionalType(type)
}
}
}
// schema = schema.transform { builder ->
// for (def type : schema.getTypeMap().values()) {
// if (type != schema.getQueryType() && type != schema.getMutationType() && type != schema.getSubscriptionType()) {
// builder.additionalType(type)
// }
// }
// }


def visitor = new GraphQLTypeVisitorStub() {
Expand Down
Loading