Skip to content

Commit

Permalink
Use name hint when server is not providing custom scalar type name (#461
Browse files Browse the repository at this point in the history
)

Co-authored-by: Arun Aruljothi <arun@arunaruljothi.com>
  • Loading branch information
fantix and arunaruljothi committed Sep 22, 2023
1 parent 758a391 commit 6c6225e
Show file tree
Hide file tree
Showing 10 changed files with 565 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ jobs:
if: steps.release.outputs.version == 0
env:
LOOP_IMPL: ${{ matrix.loop }}
SERVER_VERSION: ${{ matrix.edgedb-version }}
run: |
if [ "${SERVER_VERSION}" = "nightly" ]; then
export EDGEDB_TEST_CODEGEN_ASSERT_SUFFIX=.assert4
fi
if [ "${LOOP_IMPL}" = "uvloop" ]; then
env USE_UVLOOP=1 python -m unittest -v tests.suite
else
Expand Down
2 changes: 1 addition & 1 deletion edgedb/codegen/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ def _generate_code(
rv = f"typing.Tuple[{elements}]"

elif isinstance(type_, describe.ScalarType):
rv = self._find_name(type_.name)
rv = self._find_name(type_.name or name_hint)
base_type_name = type_.base_type.name
if import_str := imports.get(base_type_name):
self._imports.add(import_str)
Expand Down
15 changes: 15 additions & 0 deletions tests/codegen/test-project2/generated_async_edgeql.py.assert
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# AUTOGENERATED FROM:
# 'scalar/custom_vector_input.edgeql'
# 'object/link_prop.edgeql'
# 'parpkg/subpkg/my_query.edgeql'
# 'argnames/query_one.edgeql'
Expand All @@ -21,6 +22,7 @@ import typing
import uuid


Input = typing.Sequence[float]
MyScalar = int


Expand Down Expand Up @@ -140,6 +142,19 @@ class SelectObjectResultParamsItem:
Default: str | None


async def custom_vector_input(
executor: edgedb.AsyncIOExecutor,
*,
input: Input | None,
) -> int | None:
return await executor.query_single(
"""\
select 42 filter exists <optional v3>$input;\
""",
input=input,
)


async def link_prop(
executor: edgedb.AsyncIOExecutor,
) -> list[LinkPropResult]:
Expand Down
Loading

0 comments on commit 6c6225e

Please sign in to comment.