Skip to content

Commit 85848b6

Browse files
committed
Permit parent restricted nodes to map to isolated nodes
1 parent 72645a5 commit 85848b6

File tree

2 files changed

+118
-11
lines changed

2 files changed

+118
-11
lines changed

src/main/java/graphql/schema/diffing/DiffImpl.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -400,19 +400,21 @@ private double calcLowerBoundMappingCost(Vertex v,
400400
Map<Vertex, Double> isolatedVerticesCache,
401401
Map<Vertex, Vertex> nonFixedParentRestrictions) {
402402
if (nonFixedParentRestrictions.containsKey(v) || partialMapping.hasParentRestriction(v)) {
403-
Vertex uParentRestriction = nonFixedParentRestrictions.get(v);
404-
if (uParentRestriction == null) {
405-
uParentRestriction = partialMapping.getParentRestriction(v);
406-
}
403+
if (!u.isIsolated()) { // Always allow mapping to isolated nodes
404+
Vertex uParentRestriction = nonFixedParentRestrictions.get(v);
405+
if (uParentRestriction == null) {
406+
uParentRestriction = partialMapping.getParentRestriction(v);
407+
}
407408

408-
Collection<Edge> parentEdges = completeTargetGraph.getAdjacentEdgesInverseNonCopy(u);
409-
if (parentEdges.size() != 1) {
410-
return Integer.MAX_VALUE;
411-
}
409+
Collection<Edge> parentEdges = completeTargetGraph.getAdjacentEdgesInverseNonCopy(u);
410+
if (parentEdges.size() != 1) {
411+
return Integer.MAX_VALUE;
412+
}
412413

413-
Vertex uParent = parentEdges.iterator().next().getFrom();
414-
if (uParent != uParentRestriction) {
415-
return Integer.MAX_VALUE;
414+
Vertex uParent = parentEdges.iterator().next().getFrom();
415+
if (uParent != uParentRestriction) {
416+
return Integer.MAX_VALUE;
417+
}
416418
}
417419
}
418420

src/test/groovy/graphql/schema/diffing/ana/EditOperationAnalyzerTest.groovy

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3044,6 +3044,111 @@ class EditOperationAnalyzerTest extends Specification {
30443044
userModification.details.isEmpty()
30453045
}
30463046

3047+
def "deleted field with fixed parent binding can map to isolated node"() {
3048+
given:
3049+
def oldSdl = '''
3050+
type Query {
3051+
notifications: NotificationQuery
3052+
}
3053+
type NotificationQuery {
3054+
notificationFeed(
3055+
feedFilter: NotificationFeedFilter
3056+
first: Int = 25
3057+
after: String
3058+
): NotificationGroupedConnection!
3059+
unseenNotificationCount(workspaceId: String, product: String): Int!
3060+
}
3061+
input NotificationFeedFilter {
3062+
workspaceId: String
3063+
productFilter: String
3064+
groupId: String
3065+
}
3066+
type NotificationItem {
3067+
notificationId: ID!
3068+
workspaceId: String
3069+
}
3070+
type NotificationGroupedItem {
3071+
groupId: ID!
3072+
groupSize: Int!
3073+
headNotification: NotificationItem!
3074+
childItems(first: Int, after: String): [NotificationItem!]
3075+
}
3076+
type NotificationGroupedConnection {
3077+
nodes: [NotificationGroupedItem!]!
3078+
}
3079+
'''
3080+
def newSdl = '''
3081+
type Query {
3082+
notifications: NotificationQuery
3083+
}
3084+
type NotificationQuery {
3085+
notificationFeed(
3086+
filter: NotificationFilter
3087+
first: Int = 25
3088+
after: String
3089+
): NotificationFeedConnection!
3090+
notificationGroup(
3091+
groupId: String!
3092+
filter: NotificationFilter
3093+
first: Int = 25
3094+
after: String
3095+
): NotificationGroupConnection!
3096+
unseenNotificationCount(workspaceId: String, product: String): Int!
3097+
}
3098+
input NotificationFilter {
3099+
workspaceId: String
3100+
productFilter: String
3101+
}
3102+
type NotificationEntityModel{
3103+
objectId: String!
3104+
containerId: String
3105+
workspaceId: String
3106+
cloudId: String
3107+
}
3108+
type NotificationItem {
3109+
notificationId: ID!
3110+
entityModel: NotificationEntityModel
3111+
workspaceId: String
3112+
}
3113+
type NotificationHeadItem {
3114+
groupId: ID!
3115+
groupSize: Int!
3116+
readStates: [String]!
3117+
additionalTypes: [String!]!
3118+
headNotification: NotificationItem!
3119+
endCursor: String
3120+
}
3121+
type NotificationFeedConnection {
3122+
nodes: [NotificationHeadItem!]!
3123+
}
3124+
type NotificationGroupConnection {
3125+
nodes: [NotificationItem!]!
3126+
}
3127+
'''
3128+
3129+
when:
3130+
def changes = calcDiff(oldSdl, newSdl)
3131+
3132+
then:
3133+
changes["NotificationGroupedItem"] === changes["NotificationHeadItem"]
3134+
changes["NotificationGroupedConnection"] === changes["NotificationFeedConnection"]
3135+
changes["NotificationGroupedItem"] instanceof ObjectModification
3136+
changes["NotificationGroupedConnection"] instanceof ObjectModification
3137+
changes["NotificationEntityModel"] instanceof ObjectAddition
3138+
changes["NotificationGroupConnection"] instanceof ObjectAddition
3139+
changes["NotificationItem"] instanceof ObjectModification
3140+
changes["NotificationQuery"] instanceof ObjectModification
3141+
3142+
changes["NotificationFeedFilter"] === changes["NotificationFilter"]
3143+
changes["NotificationFeedFilter"] instanceof InputObjectModification
3144+
3145+
def notificationFeedFilterChange = changes["NotificationFeedFilter"] as InputObjectModification
3146+
notificationFeedFilterChange.details.size() == 1
3147+
notificationFeedFilterChange.details[0] instanceof InputObjectFieldDeletion
3148+
def groupIdInputObjectFieldDeletion = notificationFeedFilterChange.details[0] as InputObjectFieldDeletion
3149+
groupIdInputObjectFieldDeletion.name == "groupId"
3150+
}
3151+
30473152
EditOperationAnalysisResult calcDiff(
30483153
String oldSdl,
30493154
String newSdl

0 commit comments

Comments
 (0)