|
1
|
|
|
import pytest |
|
2
|
|
|
|
|
3
|
|
|
import graphinate.builders |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
@pytest.mark.parametrize('execution_number', range(5)) |
|
7
|
|
|
def test_graphql_builder__map_graph_model(execution_number, map_graph_model, graphql_query): |
|
8
|
|
|
# arrange |
|
9
|
|
|
expected_country_count, expected_city_count, graph_model = map_graph_model |
|
10
|
|
|
expected_person_count = expected_city_count |
|
11
|
|
|
|
|
12
|
|
|
# act |
|
13
|
|
|
builder = graphinate.builders.GraphQLBuilder(graph_model) |
|
14
|
|
|
|
|
15
|
|
|
import strawberry |
|
16
|
|
|
schema: strawberry.Schema = builder.build() |
|
17
|
|
|
execution_result = schema.execute_sync(graphql_query) |
|
18
|
|
|
actual_graph = execution_result.data |
|
19
|
|
|
|
|
20
|
|
|
node_ids: set = {v['id'] for v in actual_graph['nodes']} |
|
21
|
|
|
edges = actual_graph['edges'] |
|
22
|
|
|
edges_source_ids: set = {v['source']['id'] for v in edges} |
|
23
|
|
|
edges_targets_ids: set = {v['target']['id'] for v in edges} |
|
24
|
|
|
|
|
25
|
|
|
# assert |
|
26
|
|
|
assert actual_graph |
|
27
|
|
|
assert actual_graph['graph'] |
|
28
|
|
|
assert actual_graph['nodes'] |
|
29
|
|
|
assert actual_graph['edges'] |
|
30
|
|
|
assert actual_graph['graph']['name'] == 'Map' |
|
31
|
|
|
node_types_counts = {c['name']: c['value'] for c in actual_graph['graph']['nodeTypeCounts']} |
|
32
|
|
|
assert node_types_counts['country'] == expected_country_count |
|
33
|
|
|
assert node_types_counts['city'] == expected_city_count |
|
34
|
|
|
assert len(actual_graph['nodes']) == expected_country_count + expected_city_count + expected_person_count |
|
35
|
|
|
assert edges_source_ids.issubset(node_ids) |
|
36
|
|
|
assert edges_targets_ids.issubset(node_ids) |
|
37
|
|
|
assert node_ids.issuperset(edges_source_ids) |
|
38
|
|
|
assert node_ids.issuperset(edges_targets_ids) |
|
39
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
graphql_operations_cases = [ |
|
42
|
|
|
("""{ |
|
43
|
|
|
empty: measure(measure: is_empty){...Details} |
|
44
|
|
|
directed: measure(measure: is_directed){...Details} |
|
45
|
|
|
planar: measure(measure: is_planar){...Details} |
|
46
|
|
|
connectivity: measure(measure: is_connected){...Details} |
|
47
|
|
|
node_connectivity: measure(measure: node_connectivity){...Details} |
|
48
|
|
|
threshold_graph: measure(measure: is_threshold_graph){...Details} |
|
49
|
|
|
} |
|
50
|
|
|
fragment Details on Measure {name value} |
|
51
|
|
|
""", { |
|
52
|
|
|
"empty": { |
|
53
|
|
|
"name": "is_empty", |
|
54
|
|
|
"value": 0 |
|
55
|
|
|
}, |
|
56
|
|
|
"directed": { |
|
57
|
|
|
"name": "is_directed", |
|
58
|
|
|
"value": 0 |
|
59
|
|
|
}, |
|
60
|
|
|
"planar": { |
|
61
|
|
|
"name": "is_planar", |
|
62
|
|
|
"value": 1 |
|
63
|
|
|
}, |
|
64
|
|
|
"connectivity": { |
|
65
|
|
|
"name": "is_connected", |
|
66
|
|
|
"value": 1 |
|
67
|
|
|
}, |
|
68
|
|
|
"node_connectivity": { |
|
69
|
|
|
"name": "node_connectivity", |
|
70
|
|
|
"value": 2 |
|
71
|
|
|
}, |
|
72
|
|
|
"threshold_graph": { |
|
73
|
|
|
"name": "is_threshold_graph", |
|
74
|
|
|
"value": 0 |
|
75
|
|
|
} |
|
76
|
|
|
}), |
|
77
|
|
|
(( |
|
78
|
|
|
'query Graph {\n' |
|
79
|
|
|
'nodes(nodeId: "KDAsKQ==") {type label}\n' |
|
80
|
|
|
'edges(edgeId: "KCdLREFzS1E9PScsICdLREVzS1E9PScp") {type label}\n' |
|
81
|
|
|
'}' |
|
82
|
|
|
), |
|
83
|
|
|
# noqa: E501 |
|
84
|
|
|
{ |
|
85
|
|
|
"nodes": [ |
|
86
|
|
|
{ |
|
87
|
|
|
"type": "node", |
|
88
|
|
|
"label": "0" |
|
89
|
|
|
} |
|
90
|
|
|
], |
|
91
|
|
|
"edges": [ |
|
92
|
|
|
{ |
|
93
|
|
|
"type": "edge", |
|
94
|
|
|
"label": "0 ⟹ 1" |
|
95
|
|
|
} |
|
96
|
|
|
] |
|
97
|
|
|
}), |
|
98
|
|
|
("mutation {refresh}", {'refresh': True}) |
|
99
|
|
|
] |
|
100
|
|
|
|
|
101
|
|
|
|
|
102
|
|
|
@pytest.mark.parametrize(('graphql_query', 'expected_response'), graphql_operations_cases) |
|
103
|
|
|
def test_graphql_builder_query(octagonal_graph_model, graphql_query, expected_response): |
|
104
|
|
|
# act |
|
105
|
|
|
builder = graphinate.builders.GraphQLBuilder(octagonal_graph_model) |
|
106
|
|
|
|
|
107
|
|
|
import strawberry |
|
108
|
|
|
schema: strawberry.Schema = builder.build( |
|
109
|
|
|
default_node_attributes=graphinate.builders.Builder.default_node_attributes |
|
110
|
|
|
) |
|
111
|
|
|
execution_result = schema.execute_sync(graphql_query) |
|
112
|
|
|
actual_response = execution_result.data |
|
113
|
|
|
|
|
114
|
|
|
# assert |
|
115
|
|
|
assert actual_response == expected_response |
|
116
|
|
|
|
|
117
|
|
|
|
|
118
|
|
|
def test_graphql_builder__ast_model__graph_query(ast_graph_model, graphql_query): |
|
119
|
|
|
# act |
|
120
|
|
|
builder = graphinate.builders.GraphQLBuilder(ast_graph_model) |
|
121
|
|
|
import strawberry |
|
122
|
|
|
schema: strawberry.Schema = builder.build() |
|
123
|
|
|
execution_result = schema.execute_sync(graphql_query) |
|
124
|
|
|
actual_graph = execution_result.data |
|
125
|
|
|
|
|
126
|
|
|
# assert |
|
127
|
|
|
assert actual_graph |
|
128
|
|
|
assert actual_graph['graph'] |
|
129
|
|
|
assert actual_graph['nodes'] |
|
130
|
|
|
assert actual_graph['edges'] |
|
131
|
|
|
assert actual_graph['graph']['name'] == 'AST Graph' |
|
132
|
|
|
node_types_counts = {c['name']: c['value'] for c in actual_graph['graph']['nodeTypeCounts']} |
|
133
|
|
|
assert node_types_counts |
|
134
|
|
|
|