Skip to content

Commit c8a9d18

Browse files
authored
Merge pull request #4275 from graphql-java/check-in-union-example
Check in field visibility transformer test - union member error now fixed
2 parents 3924d86 + c48c88c commit c8a9d18

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

src/test/groovy/graphql/schema/transform/FieldVisibilitySchemaTransformationTest.groovy

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2010,4 +2010,73 @@ class FieldVisibilitySchemaTransformationTest extends Specification {
20102010
assertSchemaIsValid(restrictedSchema)
20112011
}
20122012

2013+
def "type is not deleted if remains a union member after its only private field path is removed"() {
2014+
given:
2015+
GraphQLSchema schema = TestUtil.schema("""
2016+
2017+
directive @private on FIELD_DEFINITION
2018+
2019+
type Query {
2020+
hello: String
2021+
createPizzaTopping(name: String!): PizzaToppingCreationPayload @private
2022+
toBeRemoved: PizzaToBeRemoved @private
2023+
}
2024+
2025+
union PizzaPolicy =
2026+
| PizzaTopping
2027+
| PizzaCrust
2028+
| PizzaDiscount
2029+
| PizzaAllergen
2030+
2031+
interface Payload {
2032+
success: Boolean!
2033+
}
2034+
2035+
type PizzaToppingCreationPayload implements Payload {
2036+
topping: PizzaTopping
2037+
success: Boolean!
2038+
}
2039+
2040+
type PizzaTopping {
2041+
id: ID
2042+
name: String
2043+
}
2044+
2045+
type PizzaCrust {
2046+
id: ID
2047+
name: String
2048+
}
2049+
2050+
type PizzaDiscount {
2051+
id: ID
2052+
percentage: Float
2053+
}
2054+
2055+
type PizzaAllergen {
2056+
id: ID
2057+
allergen: String
2058+
}
2059+
2060+
type PizzaToBeRemoved {
2061+
id: ID
2062+
}
2063+
""")
2064+
2065+
when:
2066+
GraphQLSchema restrictedSchema = visibilitySchemaTransformation.apply(schema)
2067+
2068+
then: "the private field paths are removed"
2069+
(restrictedSchema.getType("Query") as GraphQLObjectType).getFieldDefinition("createPizzaTopping") == null
2070+
restrictedSchema.getType("PizzaToppingCreationPayload") == null
2071+
2072+
and: "PizzaTopping is still present because it is reachable as a union member of the public PizzaPolicy"
2073+
restrictedSchema.getType("PizzaTopping") != null
2074+
2075+
and: "Types with no reference at all (not a union member) is correctly removed"
2076+
restrictedSchema.getType("PizzaToBeRemoved") == null
2077+
2078+
and: "the resulting schema is valid - previously this would produce an invalid schema"
2079+
assertSchemaIsValid(restrictedSchema)
2080+
}
2081+
20132082
}

0 commit comments

Comments
 (0)