-
Notifications
You must be signed in to change notification settings - Fork 3
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
Optional autocomplete of relationships #3
Conversation
Interesting, thanks so much for your contribution! The fact that this depends on apoc is a bit sad. I don't really understand, why this is necessary, though, to be honest. @fskpf - I think the implemenation that we are using in App Generator uses a much simpler cypher query to get the additional information and it does not depend on apoc. Can you check out our solution and see if we can merge the ideas. I think doing the filtering to relationship types should be done on the api level, too, before we merge this because otherwise this would be a slightly incompatible API change in the future. We can always just perform the check/filter in python, too, if the cypher query gets too complicated. |
Not it's not necessary, the neo4j browser does the same thing without it. But it's very convenient, and apoc is often installed (just not always). My thinking was basically that this works now and could be useful for many others too. It's always possible to improve later. |
Couldn't we just use a cypher query like this? this would also trivially allow us to specify the types of relationships:
or
we would then need to add these relationships to the ones returned by the original query, of course. |
Yes this works, that was actually easier than I initially thought. |
Thanks! Great! |
Yes the neo4j browser also behaves like this, self-loops are shown even if you just match a single node. |
return len(self._autocomplete_relationships) > 0 | ||
|
||
def _get_relationship_types_expression(self): | ||
if self._autocomplete_relationships == True: |
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.
My IDE complains about this and suggests simplifying it to if self._autocomplete_relationships:
.
However, changing it to the simplified code breaks the logic because an array of rel-types would then return ""
instead of the additional clause.
Can you refactor it to make the IDE happy (and avoid other devs just "simplifying" the code with ALT+ENTER and thus breaking it in the future)?
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.
Please see the next comment!
def _get_relationship_types_expression(self): | ||
if self._autocomplete_relationships == True: | ||
return "" | ||
elif len(self._autocomplete_relationships) > 0: |
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.
The IDE warns about the len(self._autocomplete_relationships)
statements:
Expected type 'Sized', got 'bool' instead
Guess this is due to the dynamic type of the _autocomplete_relationships
any chance of improving this?
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 have updated this, and made it a bit simpler. I don't know what IDE you are using (and what tool that is using to analyze the code), but at least pylint is happy with the new version.
@HEnquist thank you for the PR, I've added some notes, please have a second look. Other than the minor comments, it seems to work as intended. Another question: What is the pythonic way of using the properties? In my test case, I used
or
But just using |
The
It would be no problem to switch from the setter method to a property (https://docs.python.org/3/library/functions.html#property), so you can do |
Thanks for the explanation. I'd say keep the setter method for now. We can still switch to properties in a future update then. I'm not deep into Python, what would you say is more common for libraries? Actual properties or setter/getter methods? If there is a case to change it, we should create a different issue then. |
Thanks for merging and for the great feedback along the say!
Both ways are used, I couldn't say which one is the more common. I would say that properties are somewhat more pythonic. But it's questionable if that is reason enough to switch :D |
This is a simple implementation for autocompleting relationships in the graph. Solves #1, but it's a simple on/off switch so it does not address the part about providing a list of relationship types.