Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix custom function calls on the HTTP interface #4998

Merged
merged 1 commit into from Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion edb/server/protocol/edgeql_ext.pyx
Expand Up @@ -125,7 +125,7 @@ async def handle_request(
db,
query,
variables=variables or {},
globals_=globals_ or {},
globals_=globals_,
)
except Exception as ex:
if debug.flags.server:
Expand Down
21 changes: 10 additions & 11 deletions edb/server/protocol/execute.pyx
Expand Up @@ -400,7 +400,7 @@ async def parse_execute_json(
query: str,
*,
variables: Mapping[str, Any] = immutables.Map(),
globals_: Mapping[str, Any] = immutables.Map(),
globals_: Optional[Mapping[str, Any]] = None,
output_format: compiler.OutputFormat = compiler.OutputFormat.JSON,
query_cache_enabled: Optional[bool] = None,
) -> bytes:
Expand Down Expand Up @@ -443,20 +443,19 @@ async def execute_json(
dbv: dbview.DatabaseConnectionView,
compiled: dbview.CompiledQuery,
variables: Mapping[str, Any] = immutables.Map(),
globals_: Mapping[str, Any] = immutables.Map(),
globals_: Optional[Mapping[str, Any]] = None,
*,
fe_conn: Optional[frontend.AbstractFrontendConnection] = None,
use_prep_stmt: bint = False,
) -> bytes:
if globals_:
dbv.set_globals(immutables.Map({
"__::__edb_json_globals__": config.SettingValue(
name="__::__edb_json_globals__",
value=_encode_json_value(globals_),
source='global',
scope=qltypes.ConfigScope.GLOBAL,
)
}))
dbv.set_globals(immutables.Map({
"__::__edb_json_globals__": config.SettingValue(
name="__::__edb_json_globals__",
value=_encode_json_value(globals_),
source='global',
scope=qltypes.ConfigScope.GLOBAL,
)
}))

qug = compiled.query_unit_group

Expand Down
14 changes: 10 additions & 4 deletions tests/schemas/graphql.esdl
Expand Up @@ -162,8 +162,14 @@ function get_glob() -> optional str using (global test_global_str);

alias GlobalTest := {
gstr := global test_global_str,
garray := global test_global_array,
gid := global test_global_id,
gdef := global test_global_def,
gdef2 := global test_global_def2,
garray := global test_global_array,
gid := global test_global_id,
gdef := global test_global_def,
gdef2 := global test_global_def2,
};

function id_func(s: str) -> str using (s);

alias FuncTest := {
fstr := id_func('test'),
};
20 changes: 20 additions & 0 deletions tests/test_http_edgeql.py
Expand Up @@ -327,3 +327,23 @@ def test_http_edgeql_query_globals_03(self):
globals={'default::test_global_str': 'foo'},
use_http_post=use_http_post,
)

def test_http_edgeql_query_globals_04(self):
Q = r'''select get_glob()'''

for use_http_post in [True, False]:
self.assert_edgeql_query_result(
Q,
[],
use_http_post=use_http_post,
)

def test_http_edgeql_query_func_01(self):
Q = r'''select id_func('foo')'''

for use_http_post in [True, False]:
self.assert_edgeql_query_result(
Q,
['foo'],
use_http_post=use_http_post,
)
14 changes: 14 additions & 0 deletions tests/test_http_graphql_query.py
Expand Up @@ -4136,6 +4136,20 @@ def test_graphql_globals_01(self):
use_http_post=use_http_post,
)

def test_graphql_func_01(self):
Q = r'''query { FuncTest { fstr } }'''

for use_http_post in [True, False]:
self.assert_graphql_query_result(
Q,
{
"FuncTest": [{
'fstr': 'test',
}]
},
use_http_post=use_http_post,
)


class TestGraphQLInit(tb.GraphQLTestCase):
"""Test GraphQL initialization on an empty database."""
Expand Down