From 395ca75e744664dbde520eb1107f090670f46f03 Mon Sep 17 00:00:00 2001 From: Bojan Serafimov Date: Tue, 18 Aug 2020 10:22:54 -0400 Subject: [PATCH 1/3] Add pagination test with inline fragment --- .../snapshot_tests/test_query_pagination.py | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/graphql_compiler/tests/snapshot_tests/test_query_pagination.py b/graphql_compiler/tests/snapshot_tests/test_query_pagination.py index 680745853..885e26225 100644 --- a/graphql_compiler/tests/snapshot_tests/test_query_pagination.py +++ b/graphql_compiler/tests/snapshot_tests/test_query_pagination.py @@ -1770,3 +1770,67 @@ def test_pagination_missing_edge_class_count(self) -> None: first_page_and_remainder, advisories = paginate_query(schema_info, query, 1) self.assertTrue(first_page_and_remainder.remainder == tuple()) self.assertEqual(advisories, (MissingClassCount("Animal_LivesIn"),)) + + @pytest.mark.xfail( + strict=True, reason="inline fragment not supported", raises=Exception + ) + @pytest.mark.usefixtures("snapshot_orientdb_client") + def test_pagination_with_inline_fragment(self) -> None: + schema_graph = generate_schema_graph(self.orientdb_client) + graphql_schema, type_equivalence_hints = get_graphql_schema_from_schema_graph(schema_graph) + pagination_keys = {vertex_name: "uuid" for vertex_name in schema_graph.vertex_class_names} + pagination_keys["Species"] = "limbs" # Force pagination on int field + uuid4_field_info = { + vertex_name: {"uuid": UUIDOrdering.LeftToRight} + for vertex_name in schema_graph.vertex_class_names + } + class_counts = {"Species": 1000} + statistics = LocalStatistics( + class_counts, + field_quantiles={("Species", "limbs"): list(range(100))}, + ) + schema_info = QueryPlanningSchemaInfo( + schema=graphql_schema, + type_equivalence_hints=type_equivalence_hints, + schema_graph=schema_graph, + statistics=statistics, + pagination_keys=pagination_keys, + uuid4_field_info=uuid4_field_info, + ) + + query = QueryStringWithParameters("""{ + Species { + out_Entity_Related { + ... on Species { + name @output(out_name: "species_name") + } + } + } + }""", {}) + analysis = analyze_query_string(schema_info, query) + + vertex_partition_plan = VertexPartitionPlan(("Species", "out_Entity_Related"), "limbs", 2) + + generated_parameters = generate_parameters_for_vertex_partition( + schema_info, analysis.ast_with_parameters, vertex_partition_plan + ) + + sentinel = object() + first_param = next(generated_parameters, sentinel) + self.assertEqual(50, first_param) + + page_query, _ = generate_parameterized_queries( + analysis, vertex_partition_plan, first_param + ) + + expected_page_query_string = """{ + Species { + out_Entity_Related { + ... on Species { + limbs @filter(op_name: "<", value: ["$__paged_param_0"]) + name @output(out_name: "species_name") + } + } + } + }""" + compare_graphql(self, expected_page_query_string, print_ast(page_query.query_ast)) From f4d5d23d407d3e6715d12b05fe0148a5eea544ec Mon Sep 17 00:00:00 2001 From: Bojan Serafimov Date: Tue, 18 Aug 2020 10:24:55 -0400 Subject: [PATCH 2/3] Lint --- .../snapshot_tests/test_query_pagination.py | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/graphql_compiler/tests/snapshot_tests/test_query_pagination.py b/graphql_compiler/tests/snapshot_tests/test_query_pagination.py index 885e26225..15e3c4d1d 100644 --- a/graphql_compiler/tests/snapshot_tests/test_query_pagination.py +++ b/graphql_compiler/tests/snapshot_tests/test_query_pagination.py @@ -1771,12 +1771,10 @@ def test_pagination_missing_edge_class_count(self) -> None: self.assertTrue(first_page_and_remainder.remainder == tuple()) self.assertEqual(advisories, (MissingClassCount("Animal_LivesIn"),)) - @pytest.mark.xfail( - strict=True, reason="inline fragment not supported", raises=Exception - ) + @pytest.mark.xfail(strict=True, reason="inline fragment not supported", raises=Exception) @pytest.mark.usefixtures("snapshot_orientdb_client") def test_pagination_with_inline_fragment(self) -> None: - schema_graph = generate_schema_graph(self.orientdb_client) + schema_graph = generate_schema_graph(self.orientdb_client) # type: ignore # from fixture graphql_schema, type_equivalence_hints = get_graphql_schema_from_schema_graph(schema_graph) pagination_keys = {vertex_name: "uuid" for vertex_name in schema_graph.vertex_class_names} pagination_keys["Species"] = "limbs" # Force pagination on int field @@ -1786,8 +1784,7 @@ def test_pagination_with_inline_fragment(self) -> None: } class_counts = {"Species": 1000} statistics = LocalStatistics( - class_counts, - field_quantiles={("Species", "limbs"): list(range(100))}, + class_counts, field_quantiles={("Species", "limbs"): list(range(100))}, ) schema_info = QueryPlanningSchemaInfo( schema=graphql_schema, @@ -1798,7 +1795,8 @@ def test_pagination_with_inline_fragment(self) -> None: uuid4_field_info=uuid4_field_info, ) - query = QueryStringWithParameters("""{ + query = QueryStringWithParameters( + """{ Species { out_Entity_Related { ... on Species { @@ -1806,7 +1804,9 @@ def test_pagination_with_inline_fragment(self) -> None: } } } - }""", {}) + }""", + {}, + ) analysis = analyze_query_string(schema_info, query) vertex_partition_plan = VertexPartitionPlan(("Species", "out_Entity_Related"), "limbs", 2) @@ -1819,9 +1819,7 @@ def test_pagination_with_inline_fragment(self) -> None: first_param = next(generated_parameters, sentinel) self.assertEqual(50, first_param) - page_query, _ = generate_parameterized_queries( - analysis, vertex_partition_plan, first_param - ) + page_query, _ = generate_parameterized_queries(analysis, vertex_partition_plan, first_param) expected_page_query_string = """{ Species { From 2eb033ea4ad5050c11707f52d1b9abe3c12b0c9f Mon Sep 17 00:00:00 2001 From: Bojan Serafimov Date: Tue, 18 Aug 2020 10:48:03 -0400 Subject: [PATCH 3/3] Trigger CI rebuild