-
Notifications
You must be signed in to change notification settings - Fork 49
Fix for relationship mutations are not using the correct direction #107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix for relationship mutations are not using the correct direction #107
Conversation
…esolves neo4j-graphql#98) This bugfix solves the problem that the mapping was wrong for incoming relations
?.getDirective(DirectiveConstants.RELATION)?.let { it to false } | ||
?.getDirective(DirectiveConstants.RELATION)?.let { | ||
// do inverse mapping, if the current type is the `to` mapping of the relation | ||
it to (fieldObjectType.getFieldDefinition(it.getArgument(RELATION_TO, null))?.name == typeName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need to be careful, this doesn't always work. if you have a rich relationship which has the same type in to/from then we need to use the explicit information from that type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need the information the rel-field then I mean that indicates the correct direction otherwise it's "random" if from/to is matching the type name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see: #45
@@ -49,9 +49,13 @@ fun GraphQLFieldsContainer.relationshipFor(name: String): RelationshipInfo? { | |||
?: throw IllegalArgumentException("$name is not defined on ${this.name}") | |||
val fieldObjectType = field.type.inner() as? GraphQLFieldsContainer ?: return null | |||
|
|||
val (relDirective, isRelFromType) = if (isRelationType()) { | |||
val (relDirective, inverse) = if (isRelationType()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps we can simplify this code a bit so it gets easier to understand.
|
||
val inverse = isRelFromType && fieldObjectType.getFieldDefinition(relInfo.startField)?.name != this.name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where is this bit handled now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was the fix for issue #45
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved it to https://github.com/Andy2003/neo4j-graphql-java/blob/bugfix/%2398-fix-relationship-mapping/src/main/kotlin/org/neo4j/graphql/GraphQLExtensions.kt#L57 since it is only relevant for rich relations
@@ -0,0 +1,323 @@ | |||
:toc: | |||
|
|||
= Movie Test TCK |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be Relationship Test TCK
rather than Movie Test TCK
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for spotting this, fixed in master.
This bugfix solves the problem that the mapping was wrong for incoming relations
(resolves #98)