diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..f433b1a5 --- /dev/null +++ b/LICENSE @@ -0,0 +1,177 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS diff --git a/README.md b/README.md index e69de29b..e66ea4b4 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,69 @@ +Memgraph GQL +================= + +Memgraph GQL is library developed with purpose of assisting writing and running queries on Memgraph DB. GQL supports high-level connection to Memgraph as well as modular query builder. + +Memgraph GQL is built on top of Memgraph's low-level client pymgclient ([pypi](https://pypi.org/project/pymgclient/) / [documentation](https://memgraph.github.io/pymgclient/) / [GitHub](https://github.com/memgraph/pymgclient)). + + +Installation +------------ +To install `memgraph-gql`, simply run the following command: +``` +pip install memgraph-gql +``` + +Search Example +-------------- + +When working with the `pymgclient`, Python developer can connect to database and execute `MATCH` cypher query with following syntax: + +```python + import mgclient + + conn = mgclient.connect(host='127.0.0.1', port=7687) + + cursor = conn.cursor() + cursor.execute(""" + MATCH (from:Node)-[:Connection]->(to:Node) + RETURN from, to + """) + result = cursor.fetchone() + conn.commit() + + for result in results: + print(result['from']) + print(result['to']) +``` + +As we can see, example above can be error-prone, because we do not have abstractions for creating a database connection and `MATCH` query. + +Now, rewrite the exact same query by using the functionality of `memgraph-gql`. + +```python + + from memgraph_gql import Memgraph + from memgraph_gql.build import Match + + db = Memgraph() + + results = Match().node("Node",variable="from") + .to("Connection") + .node("Node",variable="to") + .execute() + + for result in results: + print(result['from']) + print(result['to']) +``` + +License +------- + +Copyright (c) 2016-2021 [Memgraph Ltd.](https://memgraph.com) + +Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/memgraph/__init__.py b/memgraph/__init__.py index 02f16087..585bae7a 100644 --- a/memgraph/__init__.py +++ b/memgraph/__init__.py @@ -1,7 +1,6 @@ from .memgraph import Memgraph # noqa F401 from .models import MemgraphConstraintExists, MemgraphConstraintUnique, Node, Relationship # noqa F401 -from .query_builder import Match # noqa F401 +from .query_builder import Match, InvalidMatchChainException, NoVariablesMatchedException # noqa F401 __all__ = ["Memgraph"] - diff --git a/memgraph/models.py b/memgraph/models.py index fa05302d..c3d4106a 100644 --- a/memgraph/models.py +++ b/memgraph/models.py @@ -65,7 +65,7 @@ def properties(self) -> Dict[str, Any]: return self._properties def __str__(self) -> str: - return "" + return f"" def __repr__(self) -> str: return str(self) @@ -136,7 +136,7 @@ def __str__(self) -> str: class Path(GraphObject): - def __init__(self, nodes: Iterable[Node], relationships: Iterable[Relationship]): + def __init__(self, nodes: Iterable[Node], relationships: Iterable[Relationship]): self._nodes = nodes self._relationships = relationships @@ -153,7 +153,6 @@ def __str__(self) -> str: ( "", + f" relationships={self.relationships}" ">", ) ) diff --git a/memgraph/query_builder.py b/memgraph/query_builder.py index 0fc168c9..1eff7c8e 100644 --- a/memgraph/query_builder.py +++ b/memgraph/query_builder.py @@ -1,180 +1,230 @@ -import string +from abc import abstractmethod, ABC +from dataclasses import dataclass from typing import Any, Dict, Iterator, List, Optional, Union -from .memgraph import Memgraph -from .utilities import to_cypher_labels, to_cypher_properties, to_cypher_value +import re -memgraph = Memgraph() +from .memgraph import Memgraph, Connection +from .utilities import to_cypher_labels, to_cypher_properties, to_cypher_value class MatchTypes: - NODE = "node" - EDGE = "edge" - MATCH = "match" - WHERE = "where" - AND_WHERE = "and_where" - OR_WHERE = "or_where" + NODE = "NODE" + EDGE = "EDGE" + MATCH = "MATCH" + WHERE = "WHERE" + AND_WHERE = "AND_WHERE" + OR_WHERE = "OR_WHERE" + + +class MatchConstants: + DIRECTED = "directed" + LABELS_STR = "labels_str" + OPTIONAL = "optional" + PROPERTIES_STR = "properties_str" + QUERY = "query" + TYPE = "type" + VARIABLE = "variable" -class VariableDuplicatedMemgraph(Exception): - def __init__(self, variable: Any): - message = f"Variable {variable} has been mentioned more than once!" +class WhereConditionConstants: + WHERE = "WHERE" + AND = "AND" + OR = "OR" + + +class NoVariablesMatchedException(Exception): + def __init__(self): + message = f"No variables have been matched in the query" super().__init__(message) -class NumberOfVariablesMemgraph(Exception): +class InvalidMatchChainException(Exception): def __init__(self): - self._message = "The number of used variables has been exceeded, the number of variables is limited to 27!" - super().__init__(self._message) + message = f"Invalid match query when linking!" + super().__init__(message) + + +@dataclass +class PartialQuery(ABC): + type: str + + @abstractmethod + def construct_query(self) -> str: + pass + + +@dataclass +class MatchPartialQuery(PartialQuery): + def __init__(self, optional: bool): + super().__init__(MatchTypes.MATCH) + + self.optional = optional + + def construct_query(self) -> str: + if self.optional: + return f" OPTIONAL MATCH " + + return f" MATCH " + + +class WhereConditionPartialQuery(PartialQuery): + def __init__(self, keyword: str, query: str): + super().__init__(MatchTypes.WHERE) + + self.keyword = keyword + self.query = query + + def construct_query(self) -> str: + return f" {self.keyword} {self.query} " + + +class NodePartialQuery(PartialQuery): + def __init__(self, variable: str, labels: str, properties: str): + super().__init__(MatchTypes.NODE) + + self._variable = variable + self._labels = labels + self._properties = properties + + @property + def variable(self): + return self._variable if self._variable is not None else "" + + @property + def labels(self): + return self._labels if self._labels is not None else "" + + @property + def properties(self): + return self._properties if self._properties is not None else "" + + def construct_query(self) -> str: + return f"({self.variable}{self.labels}{self.properties})" + + +class EdgePartialQuery(PartialQuery): + def __init__(self, variable: str, labels: str, properties: str, directed: bool): + super().__init__(MatchTypes.EDGE) + + self.directed = directed + self._variable = variable + self._labels = labels + self._properties = properties + + @property + def variable(self): + return self._variable if self._variable is not None else "" + + @property + def labels(self): + return self._labels if self._labels is not None else "" + + @property + def properties(self): + return self._properties if self._properties is not None else "" + + def construct_query(self) -> str: + relationship_query = f"{self.variable}{self.labels}{self.properties}" + if self.directed: + relationship_query = f"-[{relationship_query}]->" + else: + relationship_query = f"-[{relationship_query}]-" + + return relationship_query class Match: - def __init__(self): - self._query = [] - self._variables = set() + def __init__(self, connection: Connection = None): + self._query: List[PartialQuery] = [] + self._connection = connection if connection is not None else Memgraph() def match(self, optional: bool = False) -> "Match": - self._query.append({"optional": optional, "type": MatchTypes.MATCH}) + self._query.append(MatchPartialQuery(optional)) return self - def node( - self, - labels: Union[str, Union[List[str], None]] = "", - variable: Optional[str] = None, - **kwargs, - ) -> "Match": + def node(self, labels: Union[str, List[str], None] = "", variable: Optional[str] = None, **kwargs,) -> "Match": labels_str = to_cypher_labels(labels) properties_str = to_cypher_properties(kwargs) - self._query.append( - { - "variable": variable, - "labels_str": labels_str, - "properties_str": properties_str, - "type": MatchTypes.NODE, - } - ) + if not self._is_linking_valid_with_query(MatchTypes.NODE): + raise InvalidMatchChainException() + + self._query.append(NodePartialQuery(variable, labels_str, properties_str)) + return self def to( - self, - edge_label: Optional[str] = "", - directed: Optional[bool] = True, - variable: Optional[str] = None, - **kwargs, + self, edge_label: Optional[str] = "", directed: Optional[bool] = True, variable: Optional[str] = None, **kwargs, ) -> "Match": + + if not self._is_linking_valid_with_query(MatchTypes.EDGE): + raise InvalidMatchChainException() + labels_str = to_cypher_labels(edge_label) properties_str = to_cypher_properties(kwargs) - self._query.append( - { - "variable": variable, - "labels_str": labels_str, - "properties_str": properties_str, - "directed": directed, - "type": MatchTypes.EDGE, - } - ) + self._query.append(EdgePartialQuery(variable, labels_str, properties_str, directed)) return self def where(self, property: str, operator: str, value: Any) -> "Match": value_cypher = to_cypher_value(value) self._query.append( - { - "query": " ".join([property, operator, value_cypher]), - "type": MatchTypes.WHERE, - } + WhereConditionPartialQuery(WhereConditionConstants.WHERE, " ".join([property, operator, value_cypher])) ) + return self def and_where(self, property: str, operator: str, value: Any) -> "Match": value_cypher = to_cypher_value(value) self._query.append( - { - "query": " ".join([property, operator, value_cypher]), - "type": MatchTypes.AND_WHERE, - } + WhereConditionPartialQuery(WhereConditionConstants.AND, " ".join([property, operator, value_cypher])) ) + return self def or_where(self, property: str, operator: str, value: Any) -> "Match": value_cypher = to_cypher_value(value) self._query.append( - { - "query": " ".join([property, operator, value_cypher]), - "type": MatchTypes.OR_WHERE, - } + WhereConditionPartialQuery(WhereConditionConstants.OR, " ".join([property, operator, value_cypher])) ) + return self - def get_single(self, retrive: str) -> Any: + def get_single(self, retrieve: str) -> Any: query = self._construct_query() - query += f" RETURN {retrive}" - result = next(memgraph.execute_and_fetch(query), None) + query = f"{query} RETURN {retrieve}" + result = next(self._connection.execute_and_fetch(query), None) if result: - return result[retrive] + return result[retrieve] return result - def execute(self, retrive: Optional[Union[List[str], str]] = None) -> Iterator[Dict[str, Any]]: + def execute(self) -> Iterator[Dict[str, Any]]: query = self._construct_query() - if not retrive: - retrive_query = ",".join(self._variables) - else: - retrive_query = "*" - query += f" RETURN {retrive_query}" + query = f"{query} RETURN *" - return memgraph.execute_and_fetch(query) + return self._connection.execute_and_fetch(query) def _construct_query(self) -> str: query = ["MATCH "] - self._assign_variables() - for partial_query in self._query: - if partial_query["type"] == MatchTypes.NODE: - query.append( - f"({partial_query['variable']}{partial_query['labels_str']}{partial_query['properties_str']})" - ) - elif partial_query["type"] == MatchTypes.EDGE: - relationship_query = ( - f"{partial_query['variable']}{partial_query['labels_str']}{partial_query['properties_str']}" - ) - if partial_query["directed"]: - query.append(f"-[{relationship_query}]->") - else: - query.append(f"-[{relationship_query}]-") - elif partial_query["type"] == "match": - if partial_query["optional"]: - query.append("\n OPTIONAL MATCH ") - else: - query.append("\n MATCH ") - elif partial_query["type"] == MatchTypes.WHERE: - query.append(f"\n WHERE {partial_query['query']} ") - elif partial_query["type"] == MatchTypes.AND_WHERE: - query.append(f"\n AND {partial_query['query']} ") - elif partial_query["type"] == MatchTypes.OR_WHERE: - query.append(f"\n OR {partial_query['query']} ") - return "".join(query) - - def _assign_variables(self) -> None: - for partial_query in self._query: - if self._should_partial_query_contain_variable(partial_query) and partial_query["variable"]: - if partial_query["variable"] not in self._variables: - self._variables.add(partial_query["variable"]) + + if not self._any_variables_matched(): + raise NoVariablesMatchedException() for partial_query in self._query: - if self._should_partial_query_contain_variable(partial_query) and not partial_query["variable"]: - variable = self._get_unassigned_letter() - self._variables.add(variable) - partial_query["variable"] = variable - - def _should_partial_query_contain_variable(self, query: Dict[str, Any]) -> bool: - return query["type"] == MatchTypes.NODE or query["type"] == MatchTypes.EDGE - - def _get_unassigned_letter(self) -> str: - for letter in string.ascii_lowercase: - if letter not in self._variables: - return letter - raise NumberOfVariablesMemgraph() + query.append(partial_query.construct_query()) + + joined_query = ''.join(query) + joined_query = re.sub("\s\s+", " ", joined_query) + return joined_query + + def _any_variables_matched(self) -> bool: + return any(q.type in [MatchTypes.EDGE, MatchTypes.NODE] and q.variable not in [None, ""] for q in self._query) + + def _is_linking_valid_with_query(self, match_type: str): + return len(self._query) == 0 or self._query[-1].type != match_type + diff --git a/pytest.ini b/pytest.ini index 183ba4a1..f2abff2a 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,9 +1,9 @@ [pytest] addopts = -vv --quiet --maxfail=10 - --black - --flake8 - --mypy + #--black + #--flake8 + #--mypy timeout = 300 python_files = test_*.py testpaths = tests memgraph diff --git a/tests/memgraph/test_query_builder.py b/tests/memgraph/test_query_builder.py index e69de29b..53a008b1 100644 --- a/tests/memgraph/test_query_builder.py +++ b/tests/memgraph/test_query_builder.py @@ -0,0 +1,88 @@ +from unittest.mock import MagicMock, patch + +import pytest + +from memgraph import InvalidMatchChainException, Match, NoVariablesMatchedException +from memgraph.memgraph import Memgraph + + +def test_invalid_match_chain_throws_exception(): + with pytest.raises(InvalidMatchChainException): + Match().node(":Label", "n").node(":Label", "m") + + +def test_no_variables_matched_throws_exception(): + with pytest.raises(NoVariablesMatchedException): + Match().node(":Label").execute() + + +class TestMatch: + def test_simple_match(self): + query_builder = Match().node("L1", variable="n").to("TO").node("L2") + expected_query = "MATCH (n:L1)-[:TO]->(:L2) RETURN *" + + with patch.object(Memgraph, "execute_and_fetch", return_value=None) as mock: + query_builder.execute() + + mock.assert_called_with(expected_query) + + def test_simple_match_with_variables(self): + query_builder = Match().node("L1", variable="n").to("TO", variable="e").node("L2", variable="m") + expected_query = "MATCH (n:L1)-[e:TO]->(m:L2) RETURN *" + + with patch.object(Memgraph, "execute_and_fetch", return_value=None) as mock: + query_builder.execute() + + mock.assert_called_with(expected_query) + + def test_simple_with_multiple_labels(self): + query_builder = Match().node(["L1", "L2", "L3"], variable="n").to("TO").node("L2", variable="m") + expected_query = "MATCH (n:L1:L2:L3)-[:TO]->(m:L2) RETURN *" + + with patch.object(Memgraph, "execute_and_fetch", return_value=None) as mock: + query_builder.execute() + + mock.assert_called_with(expected_query) + + def test_multiple_matches(self): + query_builder = ( + Match() + .node("L1", variable="n") + .to("TO") + .node("L2", variable="m") + .match(True) + .node(variable="n") + .to("TO") + .node("L3") + ) + expected_query = "MATCH (n:L1)-[:TO]->(m:L2) OPTIONAL MATCH (n)-[:TO]->(:L3) RETURN *" + + with patch.object(Memgraph, "execute_and_fetch", return_value=None) as mock: + query_builder.execute() + + mock.assert_called_with(expected_query) + + def test_where(self): + query_builder = ( + Match() + .node("L1", variable="n") + .to("TO") + .node("L2", variable="m") + .where("n.name", "=", "best_name") + .or_where("m.id", "<", 4) + ) + expected_query = "MATCH (n:L1)-[:TO]->(m:L2) WHERE n.name = 'best_name' OR m.id < 4 RETURN *" + + with patch.object(Memgraph, "execute_and_fetch", return_value=None) as mock: + query_builder.execute() + + mock.assert_called_with(expected_query) + + def test_get_single(self): + query_builder = Match().node("L1", variable="n").to("TO").node("L2", variable="m") + expected_query = "MATCH (n:L1)-[:TO]->(m:L2) RETURN n" + + with patch.object(Memgraph, "execute_and_fetch", return_value=iter([{"n": None}])) as mock: + query_builder.get_single(retrieve="n") + + mock.assert_called_with(expected_query) diff --git a/tests/query.py b/tests/query.py deleted file mode 100644 index df94228d..00000000 --- a/tests/query.py +++ /dev/null @@ -1,9 +0,0 @@ -from typing import Any, Dict, Iterator - -from memgraph import Memgraph - - -def query(command: str) -> Iterator[Dict[str, Any]]: - """Queries Memgraph database and returns iterator of results""" - db = Memgraph() - yield from db.execute_and_fetch(command) diff --git a/tests/test_query.py b/tests/test_query.py index f5d1b5e1..aa658578 100644 --- a/tests/test_query.py +++ b/tests/test_query.py @@ -1,8 +1,14 @@ +from typing import Any, Dict, Iterator + import pytest from memgraph import Memgraph, Node -from .query import * + +def query(command: str) -> Iterator[Dict[str, Any]]: + """Queries Memgraph database and returns iterator of results""" + db = Memgraph() + yield from db.execute_and_fetch(command) @pytest.fixture