forked from hasura/graphql-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_remote_relationships.py
354 lines (279 loc) · 14.5 KB
/
test_remote_relationships.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
#!/usr/bin/env python3
import pytest
from conftest import extract_server_address_from
from remote_server import NodeGraphQL
from validate import check_query_f
@pytest.fixture(scope='class')
@pytest.mark.early
def graphql_service(worker_id: str, hge_fixture_env: dict[str, str]):
(_, port) = extract_server_address_from('GRAPHQL_SERVICE_HANDLER')
server = NodeGraphQL(worker_id, 'remote_schemas/nodejs/index.js', port=port)
server.start()
print(f'{graphql_service.__name__} server started on {server.url}')
hge_fixture_env['GRAPHQL_SERVICE_HANDLER'] = server.url
yield server
server.stop()
use_test_fixtures = pytest.mark.usefixtures(
"graphql_service",
"per_method_tests_db_state"
)
@use_test_fixtures
class TestCreateRemoteRelationship:
@classmethod
def dir(cls):
return "queries/remote_schemas/remote_relationships/"
# @pytest.fixture(autouse=True)
# def transact(self, hge_ctx, graphql_service):
# print("In setup method")
# graphql_service.start()
# try:
# hge_ctx.v1q_f(self.dir() + 'setup.yaml')
# yield
# hge_ctx.v1q_f(self.dir() + 'teardown.yaml')
# finally:
# graphql_service.stop()
def test_create_valid(self, hge_ctx):
files = [
'setup_remote_rel_basic.yaml',
'setup_remote_rel_nested_args.yaml',
'setup_remote_rel_array.yaml',
'setup_remote_rel_nested_fields.yaml',
'setup_remote_rel_multiple_fields.yaml',
'setup_remote_rel_joining_singleton_with_array.yaml',
'setup_remote_rel_with_interface.yaml',
'setup_remote_rel_with_union.yaml',
'setup_remote_rel_with_enum.yaml',
'setup_remote_rel_computed_fields.yaml',
]
for f in files:
hge_ctx.v1q_f(self.dir() + f)
def test_create_invalid(self, hge_ctx):
files = [
'setup_invalid_remote_rel_hasura_field.yaml',
'setup_invalid_remote_rel_literal.yaml',
'setup_invalid_remote_rel_variable.yaml',
'setup_invalid_remote_rel_remote_args.yaml',
'setup_invalid_remote_rel_remote_schema.yaml',
'setup_invalid_remote_rel_remote_field.yaml',
'setup_invalid_remote_rel_nested_args.yaml',
'setup_invalid_remote_rel_array.yaml',
'setup_invalid_remote_rel_computed_field.yaml',
]
for f in files:
hge_ctx.v1q_f(self.dir() + f, expected_status_code = 400)
def test_generation(self, hge_ctx):
hge_ctx.v1q_f(self.dir() + 'setup_remote_rel_basic.yaml')
hge_ctx.v1q_f(self.dir() + 'setup_remote_rel_nested_args.yaml')
check_query_f(hge_ctx, self.dir() + 'select_remote_fields.yaml')
@use_test_fixtures
class TestDeleteRemoteRelationship:
@classmethod
def dir(cls):
return "queries/remote_schemas/remote_relationships/"
def test_delete(self, hge_ctx):
hge_ctx.v1q_f(self.dir() + 'setup_remote_rel_basic.yaml')
hge_ctx.v1q_f(self.dir() + 'delete_remote_rel.yaml')
def test_delete_dependencies(self, hge_ctx):
hge_ctx.v1q_f(self.dir() + 'setup_remote_rel_basic.yaml')
hge_ctx.v1q_f(self.dir() + 'remove_remote_schema.yaml', expected_status_code = 400)
hge_ctx.v1q_f(self.dir() + 'delete_remote_rel.yaml')
def test_deleting_column_with_remote_relationship_dependency(self, hge_ctx):
check_query_f(hge_ctx, self.dir() + 'drop_col_with_remote_rel_dependency.yaml')
self._check_no_remote_relationships(hge_ctx, 'profiles')
def test_deleting_table_with_remote_relationship_dependency(self, hge_ctx):
check_query_f(hge_ctx, self.dir() + 'drop_table_with_remote_rel_dependency.yaml')
self._check_no_remote_relationships(hge_ctx, 'profiles')
def _check_no_remote_relationships(self, hge_ctx, table):
export_metadata_q = {
'type': 'export_metadata',
'args': {}
}
resp = hge_ctx.v1q(export_metadata_q)
tables = resp['sources'][0]['tables']
for t in tables:
if t['table']['name'] == table:
assert 'event_triggers' not in t
@use_test_fixtures
class TestUpdateRemoteRelationship:
@classmethod
def dir(cls):
return "queries/remote_schemas/remote_relationships/"
def test_update(self, hge_ctx):
hge_ctx.v1q_f(self.dir() + 'setup_remote_rel_basic.yaml')
check_query_f(hge_ctx, self.dir() + 'basic_relationship.yaml')
hge_ctx.v1q_f(self.dir() + 'update_remote_rel_basic.yaml')
check_query_f(hge_ctx, self.dir() + 'update_basic_query.yaml')
@use_test_fixtures
class TestExecution:
@classmethod
def dir(cls):
return "queries/remote_schemas/remote_relationships/"
# def test_basic_mixed(self, hge_ctx):
# check_query_f(hge_ctx, self.dir() + 'basic_mixed.yaml')
def test_basic_relationship(self, hge_ctx):
hge_ctx.v1q_f(self.dir() + 'setup_remote_rel_basic.yaml')
check_query_f(hge_ctx, self.dir() + 'basic_relationship.yaml')
def test_basic_relationship_on_object(self, hge_ctx):
hge_ctx.v1q_f(self.dir() + 'setup_remote_rel_basic.yaml')
check_query_f(hge_ctx, self.dir() + 'query_with_object_rel.yaml')
hge_ctx.v1q_f(self.dir() + 'setup_remote_rel_nested_args.yaml')
check_query_f(hge_ctx, self.dir() + 'query_with_arr_rel.yaml')
def test_regression_7172(self, hge_ctx):
hge_ctx.v1q_f(self.dir() + 'setup_regression_7172.yaml')
check_query_f(hge_ctx, self.dir() + 'regression_7172.yaml')
def test_basic_relationship_joining_singleton_to_array(self, hge_ctx):
hge_ctx.v1q_f(self.dir() + 'setup_remote_rel_joining_singleton_with_array.yaml')
check_query_f(hge_ctx, self.dir() + 'basic_relationship_joining_singleton_with_array.yaml')
def test_basic_array(self, hge_ctx):
hge_ctx.v1q_f(self.dir() + 'setup_remote_rel_array.yaml')
check_query_f(hge_ctx, self.dir() + 'basic_array.yaml')
def test_basic_array_without_join_key(self, hge_ctx):
hge_ctx.v1q_f(self.dir() + 'setup_remote_rel_array.yaml')
check_query_f(hge_ctx, self.dir() + 'basic_array_without_join_key.yaml')
def test_multiple_fields(self, hge_ctx):
hge_ctx.v1q_f(self.dir() + 'setup_remote_rel_multiple_fields.yaml')
check_query_f(hge_ctx, self.dir() + 'basic_multiple_fields.yaml')
# https://github.com/hasura/graphql-engine/issues/5448
def test_remote_join_fields_with_null_joining_fields(self, hge_ctx):
hge_ctx.v1q_f(self.dir() + 'setup_remote_rel_null_joining_fields.yaml')
check_query_f(hge_ctx, self.dir() + 'remote_rel_with_null_joining_fields.yaml')
def test_nested_fields(self, hge_ctx):
hge_ctx.v1q_f(self.dir() + 'setup_remote_rel_nested_fields.yaml')
check_query_f(hge_ctx, self.dir() + 'basic_nested_fields.yaml')
def test_arguments(self, hge_ctx):
hge_ctx.v1q_f(self.dir() + 'setup_remote_rel_nested_args.yaml')
check_query_f(hge_ctx, self.dir() + 'query_with_arguments.yaml')
def test_with_variables(self, hge_ctx):
# check_query_f(hge_ctx, self.dir() + 'mixed_variables.yaml') -- uses heterogenous execution, due to which this assert fails
hge_ctx.v1q_f(self.dir() + 'setup_remote_rel_nested_args.yaml')
check_query_f(hge_ctx, self.dir() + 'remote_rel_variables.yaml')
def test_with_fragments(self, hge_ctx):
check_query_f(hge_ctx, self.dir() + 'mixed_fragments.yaml')
hge_ctx.v1q_f(self.dir() + 'setup_remote_rel_basic.yaml')
check_query_f(hge_ctx, self.dir() + 'remote_rel_fragments.yaml')
def test_with_interface(self, hge_ctx):
hge_ctx.v1q_f(self.dir() + 'setup_remote_rel_with_interface.yaml')
check_query_f(hge_ctx, self.dir() + 'mixed_interface.yaml')
check_query_f(hge_ctx, self.dir() + 'remote_rel_interface.yaml')
def test_with_union(self, hge_ctx):
hge_ctx.v1q_f(self.dir() + 'setup_remote_rel_with_union.yaml')
check_query_f(hge_ctx, self.dir() + 'remote_rel_union.yaml')
def test_with_enum(self, hge_ctx):
hge_ctx.v1q_f(self.dir() + 'setup_remote_rel_with_enum.yaml')
check_query_f(hge_ctx, self.dir() + 'remote_rel_enum.yaml')
def test_with_errors(self, hge_ctx):
hge_ctx.v1q_f(self.dir() + 'setup_remote_rel_basic.yaml')
check_query_f(hge_ctx, self.dir() + 'query_with_errors_obj.yaml')
hge_ctx.v1q_f(self.dir() + 'setup_remote_rel_nested_args.yaml')
check_query_f(hge_ctx, self.dir() + 'query_with_errors_arr.yaml')
def test_with_aliased_remote_join_keys(self, hge_ctx):
"""
Regression test for https://github.com/hasura/graphql-engine/issues/7180.
"""
hge_ctx.v1q_f(self.dir() + 'setup_remote_rel_basic.yaml')
check_query_f(hge_ctx, self.dir() + 'basic_relationship_alias.yaml')
def test_with_scalar_relationship(self, hge_ctx):
hge_ctx.v1q_f(self.dir() + 'setup_remote_rel_scalar.yaml')
check_query_f(hge_ctx, self.dir() + 'query_with_scalar_rel.yaml')
def test_renaming_column_with_remote_relationship_dependency(self, hge_ctx):
hge_ctx.v1q_f(self.dir() + 'setup_remote_rel_nested_args.yaml')
check_query_f(hge_ctx, self.dir() + 'rename_col_with_remote_rel_dependency.yaml')
def test_renaming_table_with_remote_relationship_dependency(self, hge_ctx):
hge_ctx.v1q_f(self.dir() + 'setup_remote_rel_nested_args.yaml')
check_query_f(hge_ctx, self.dir() + 'rename_table_with_remote_rel_dependency.yaml')
# The check for the presence of the remote relationships is deferred to later stage
# in the server source code. To run this test we need to use proper websocket client
# instead of HTTP.
# def test_remote_joins_with_subscription_should_throw_error(self, hge_ctx):
# hge_ctx.v1q_f(self.dir() + 'setup_remote_rel_basic.yaml')
# check_query_f(hge_ctx, self.dir() + 'subscription_with_remote_join_fields.yaml')
def test_remote_joins_in_mutation_response(self, hge_ctx):
hge_ctx.v1q_f(self.dir() + 'setup_remote_rel_basic_with_authors.yaml')
check_query_f(hge_ctx, self.dir() + 'mutation_output_with_remote_join_fields.yaml')
class TestDeepExecution:
@classmethod
def dir(cls):
return "queries/remote_schemas/remote_relationships/"
@pytest.fixture(autouse=True)
def transact(self, hge_ctx, graphql_service):
print("In setup method")
hge_ctx.v1q_f(self.dir() + 'setup.yaml')
hge_ctx.v1q_f(self.dir() + 'setup_address.yaml')
yield
hge_ctx.v1q_f(self.dir() + 'teardown_address.yaml')
hge_ctx.v1q_f(self.dir() + 'teardown.yaml')
def test_with_deep_object(self, hge_ctx):
hge_ctx.v1q_f(self.dir() + 'setup_remote_rel_basic.yaml')
check_query_f(hge_ctx, self.dir() + 'query_with_deep_nesting_obj.yaml')
def test_with_deep_array(self, hge_ctx):
hge_ctx.v1q_f(self.dir() + 'setup_remote_rel_nested_args.yaml')
check_query_f(hge_ctx, self.dir() + 'query_with_deep_nesting_arr.yaml')
def test_with_complex_path_object(self, hge_ctx):
hge_ctx.v1q_f(self.dir() + 'setup_remote_rel_basic.yaml')
check_query_f(hge_ctx, self.dir() + 'query_with_deep_nesting_complex_path_obj.yaml')
check_query_f(hge_ctx, self.dir() + 'query_with_deep_nesting_complex_path_obj2.yaml')
def test_with_complex_path_array(self, hge_ctx):
hge_ctx.v1q_f(self.dir() + 'setup_remote_rel_basic.yaml')
check_query_f(hge_ctx, self.dir() + 'query_with_deep_nesting_complex_path_arr.yaml')
check_query_f(hge_ctx, self.dir() + 'query_with_deep_nesting_complex_path_arr2.yaml')
class TestExecutionWithPermissions:
@classmethod
def dir(cls):
return "queries/remote_schemas/remote_relationships/"
@pytest.fixture(autouse=True)
def transact(self, hge_ctx, graphql_service):
print("In setup method")
hge_ctx.v1q_f(self.dir() + 'setup_with_permissions.yaml')
yield
hge_ctx.v1q_f(self.dir() + 'teardown.yaml')
def test_basic_relationship(self, hge_ctx):
hge_ctx.v1q_f(self.dir() + 'setup_remote_rel_basic.yaml')
check_query_f(hge_ctx, self.dir() + 'basic_relationship_with_permissions1.yaml')
check_query_f(hge_ctx, self.dir() + 'basic_relationship_with_permissions2.yaml')
# Test queries that combine several remote relationships, nested in
# different ways, variously filtering different bits using permissions.
def test_complex_multiple_joins(self, hge_ctx):
hge_ctx.v1q_f(self.dir() + 'setup_multiple_remote_rel.yaml')
check_query_f(hge_ctx, self.dir() + 'complex_multiple_joins.yaml')
@use_test_fixtures
class TestWithRelay:
@classmethod
def dir(cls):
return "queries/remote_schemas/remote_relationships/"
def test_with_relay_fail(self, hge_ctx):
hge_ctx.v1q_f(self.dir() + 'setup_remote_rel_basic.yaml')
check_query_f(hge_ctx, self.dir() + "with_relay.yaml")
@use_test_fixtures
class TestExecutionWithCustomization:
@classmethod
def dir(cls):
return "queries/remote_schemas/remote_relationships/schema_customization/"
def test_basic_relationship(self, hge_ctx):
hge_ctx.v1q_f(self.dir() + 'setup_remote_rel_basic.yaml')
check_query_f(hge_ctx, self.dir() + 'basic_relationship.yaml')
def test_nested_fields(self, hge_ctx):
hge_ctx.v1q_f(self.dir() + 'setup_remote_rel_nested_fields.yaml')
check_query_f(hge_ctx, self.dir() + 'basic_nested_fields.yaml')
class TestComputedFieldsInRemoteRelationship:
@classmethod
def dir(cls):
return "queries/remote_schemas/remote_relationships/"
@pytest.fixture(autouse=True)
def transact(self, hge_ctx, graphql_service):
print("In setup method")
hge_ctx.v1q_f(self.dir() + 'setup.yaml')
hge_ctx.v1q_f(self.dir() + 'setup_remote_rel_computed_fields.yaml')
yield
hge_ctx.v1q_f(self.dir() + 'teardown.yaml')
def test_remote_join_with_computed_field(self, hge_ctx):
check_query_f(hge_ctx, self.dir() + 'remote_join_with_computed_field.yaml')
def test_remote_join_with_computed_field_session(self, hge_ctx):
check_query_f(hge_ctx, self.dir() + 'remote_join_with_computed_field_session.yaml')
@use_test_fixtures
class TestRemoteRelationshipFieldType:
@classmethod
def dir(cls):
return "queries/remote_schemas/remote_relationships"
def test_remote_relationship_field_type(self, hge_ctx):
hge_ctx.v1q_f(self.dir() + '/setup_remote_rel_nested_args.yaml')
check_query_f(hge_ctx, self.dir() + '/remote_relationship_field_type.yaml')