Skip to content

Commit

Permalink
Merge pull request #93 from slavikovbasa/fix-untrack-for-a-node-when-…
Browse files Browse the repository at this point in the history
…no-ids

Fix _untrack not triggering for nodes without linked ids
  • Loading branch information
slavikovbasa committed Feb 22, 2023
2 parents 8b5598c + 87c80e3 commit 6a2cc03
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
2 changes: 2 additions & 0 deletions hiku/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,8 @@ def process_link(
if to_ids:
self.process_node(path, self._graph.nodes_map[graph_link.node],
query_link.node, to_ids)
else:
self._untrack(path)

return None

Expand Down
24 changes: 20 additions & 4 deletions tests/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@
FieldsQuery,
LinkQuery,
)
from hiku.graph import Graph, Link, Node, Option, Root, Field
from hiku.graph import Graph, Link, Node, Option, Root, Field, Nothing
from hiku.types import (
Integer,
String,
TypeRef,
Sequence,
Record,
Any,
Optional,
)
from hiku.engine import Engine
from hiku.readers.graphql import read
Expand Down Expand Up @@ -189,6 +190,10 @@ def link_user(opts):
return opts['id']


def link_empty_user(ids):
return [Nothing] * len(ids)


def link_company(opts):
return opts['id']

Expand Down Expand Up @@ -393,7 +398,13 @@ def get_field(field, product):
Field('owner_id', Integer, company_sg),
Field('address', TypeRef['Address'],
company_sg.c(get_address(S.this))),
Link('owner', TypeRef['User'], direct_link, requires='owner_id')
Link('owner', TypeRef['User'], direct_link, requires='owner_id'),
Link(
'emptyOwner',
Optional[TypeRef['User']],
link_empty_user,
requires='id',
)
]),
Node('AttributeValue', [
Field('id', Integer, attribute_value_sg),
Expand Down Expand Up @@ -452,6 +463,9 @@ def get_product_query(product_id: int) -> str:
username
photo(size: 50)
}
emptyOwner {
username
}
}
}
}
Expand Down Expand Up @@ -539,7 +553,8 @@ def execute(q):
'id': 10,
'name': 'apple',
'address': {'city': 'Kyiv'},
'owner': Reference('User', 100)
'owner': Reference('User', 100),
'emptyOwner': None,
},
},
'Product': {'company': Reference('Company', 10)}
Expand Down Expand Up @@ -588,7 +603,8 @@ def execute(q):
'owner': {
'username': 'steve',
'photo': 'https://example.com/photo.jpg?size=50'
}
},
'emptyOwner': None,
}
}
}
Expand Down

0 comments on commit 6a2cc03

Please sign in to comment.