Skip to content
Closed
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
77 changes: 77 additions & 0 deletions src/test/groovy/graphql/schema/impl/SchemaUtilTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@ import graphql.NestedInputSchema
import graphql.introspection.Introspection
import graphql.schema.GraphQLAppliedDirectiveArgument
import graphql.schema.GraphQLArgument
import graphql.schema.GraphQLCodeRegistry
import graphql.schema.GraphQLFieldDefinition
import graphql.schema.GraphQLInputObjectType
import graphql.schema.GraphQLObjectType
import graphql.schema.GraphQLSchema
import graphql.schema.GraphQLSchemaElement
import graphql.schema.GraphQLType
import graphql.schema.GraphQLTypeVisitorStub
import graphql.schema.GraphQLTypeReference
import graphql.schema.GraphQLUnionType
import graphql.schema.SchemaTransformer
import graphql.util.TraversalControl
import graphql.util.TraverserContext
import spock.lang.Issue
import spock.lang.Specification

import static graphql.Scalars.GraphQLBoolean
Expand Down Expand Up @@ -41,6 +49,7 @@ import static graphql.schema.GraphQLArgument.newArgument
import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition
import static graphql.schema.GraphQLInputObjectField.newInputObjectField
import static graphql.schema.GraphQLInputObjectType.newInputObject
import static graphql.schema.GraphQLInterfaceType.newInterface
import static graphql.schema.GraphQLList.list
import static graphql.schema.GraphQLObjectType.newObject
import static graphql.schema.GraphQLSchema.newSchema
Expand Down Expand Up @@ -190,6 +199,74 @@ class SchemaUtilTest extends Specification {
!(cacheEnabled.getType() instanceof GraphQLTypeReference)
}

@Issue("https://github.com/graphql-java/graphql-java/issues/3384")
def "can rebuild schema after removing root type that made an implemented interface reachable"() {
given:
def schema = issue3384Schema()
def node = schema.getType("Node")

when:
def rebuiltSchema = newSchema(schema)
.mutation((GraphQLObjectType) null)
.build()

then:
rebuiltSchema.getMutationType() == null
rebuiltSchema.getType("Node") == node
rebuiltSchema.getObjectType("Person").interfaces == [node]
}

@Issue("https://github.com/graphql-java/graphql-java/issues/3384")
def "can transform schema after deleting root type that made an implemented interface reachable"() {
given:
def schema = issue3384Schema()
def node = schema.getType("Node")

when:
def transformedSchema = SchemaTransformer.transformSchemaWithDeletes(schema, new GraphQLTypeVisitorStub() {
@Override
TraversalControl visitGraphQLObjectType(GraphQLObjectType graphQLObjectType, TraverserContext<GraphQLSchemaElement> context) {
if (graphQLObjectType.name == "Mutation") {
return deleteNode(context)
}
return TraversalControl.CONTINUE
}
})

then:
transformedSchema.getMutationType() == null
transformedSchema.getType("Node") == node
transformedSchema.getObjectType("Person").interfaces == [node]
}

private GraphQLSchema issue3384Schema() {
def node = newInterface()
.name("Node")
.field(newFieldDefinition().name("id").type(GraphQLString))
.build()
def person = newObject()
.name("Person")
.withInterface(typeRef("Node"))
.field(newFieldDefinition().name("id").type(GraphQLString))
.build()
def query = newObject()
.name("Query")
.field(newFieldDefinition().name("person").type(person))
.build()
def mutation = newObject()
.name("Mutation")
.field(newFieldDefinition().name("node").type(node))
.build()
def codeRegistry = GraphQLCodeRegistry.newCodeRegistry()
.typeResolver(node, { env -> person })
.build()
return newSchema()
.query(query)
.mutation(mutation)
.codeRegistry(codeRegistry)
.build()
}

def "redefined types are caught"() {
when:
final GraphQLInputObjectType attributeListInputObjectType = newInputObject().name("attributes")
Expand Down
Loading