Reproduction of issue 4133 · graphql-java/graphql-java@c839bf7

File tree

1 file changed

lines changed

  • src/test/groovy/graphql/schema

1 file changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -1022,4 +1022,76 @@ type Query {

10221022

}

10231023

"""

10241024

}

1025+
1026+

def "issue 4133 reproduction"() {

1027+

def sdl = """

1028+

directive @remove on FIELD_DEFINITION

1029+
1030+

type Query {

1031+

rental: Rental @remove

1032+

customer: Customer

1033+

}

1034+
1035+

type Store {

1036+

inventory: Inventory @remove

1037+

}

1038+
1039+

type Inventory {

1040+

store: Store @remove

1041+

}

1042+
1043+

type Customer {

1044+

rental: Rental

1045+

payment: Payment @remove

1046+

}

1047+
1048+

type Payment {

1049+

inventory: Inventory @remove

1050+

}

1051+
1052+

type Rental {

1053+

id: ID

1054+

customer: Customer @remove

1055+

}

1056+

"""

1057+
1058+

def schema = TestUtil.schema(sdl)

1059+
1060+

def visitor = new GraphQLTypeVisitorStub() {

1061+

@Override

1062+

TraversalControl visitGraphQLFieldDefinition(GraphQLFieldDefinition node, TraverserContext<GraphQLSchemaElement> context) {

1063+

if (node.hasAppliedDirective("remove")) {

1064+

return deleteNode(context)

1065+

}

1066+

return TraversalControl.CONTINUE

1067+

}

1068+
1069+

@Override

1070+

TraversalControl visitGraphQLObjectType(GraphQLObjectType node, TraverserContext<GraphQLSchemaElement> context) {

1071+

if (node.getFields().stream().allMatch(field -> field.hasAppliedDirective("remove"))) {

1072+

return deleteNode(context)

1073+

}

1074+
1075+

return TraversalControl.CONTINUE

1076+

}

1077+

}

1078+
1079+

when:

1080+

def newSchema = SchemaTransformer.transformSchema(schema, visitor)

1081+

def newSdl = new SchemaPrinter().print(newSchema)

1082+
1083+

then:

1084+

newSdl == """

1085+

type Query {

1086+

customer: Customer

1087+

}

1088+
1089+

type Customer {

1090+

rental: Rental

1091+

}

1092+
1093+

type Rental {

1094+

id: ID

1095+

}""".stripIndent().trim()

1096+

}

10251097

}