Skip to content

Commit

Permalink
Merge pull request #148 from evo-company/fix-union-ref-sdl-encode-for…
Browse files Browse the repository at this point in the history
…-federation

[fix] add missing UnionRef to federation sdl generation
  • Loading branch information
kindermax authored Apr 18, 2024
2 parents 56516f4 + ca60f9b commit 7b1fddf
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 16 deletions.
14 changes: 7 additions & 7 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ services:
dev:
<<: *base
image: hiku-dev

docs:
<<: *base
image: hiku-docs
Expand All @@ -41,23 +41,23 @@ services:
examples-federation:
<<: *examples-base
command: python3 examples/graphql_federation.py

examples-federation-v2:
<<: *examples-base
command: python3 examples/graphql_federation_v2.py

examples-flask:
<<: *examples-base
command: python3 examples/graphql_flask.py
command: python3 examples/graphql_flask.py

examples-aiohttp:
<<: *examples-base
command: python3 examples/graphql_aiohttp.py

federation-compatibility-server:
<<: *examples-base
entrypoint: pdm run python examples/federation-compatibility/server.py

test-base: &test-base
<<: *base
image: hiku-tests
Expand Down
3 changes: 3 additions & 0 deletions hiku/federation/sdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from hiku.scalar import ScalarMeta
from hiku.types import (
EnumRefMeta,
UnionRefMeta,
IDMeta,
IntegerMeta,
MappingMeta,
Expand Down Expand Up @@ -101,6 +102,8 @@ def _encode(
return val.__type_name__
elif isinstance(val, EnumRefMeta):
return val.__type_name__
elif isinstance(val, UnionRefMeta):
return val.__type_name__
elif isinstance(val, ScalarMeta):
return val.__type_name__
elif isinstance(val, IntegerMeta):
Expand Down
8 changes: 4 additions & 4 deletions lets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ commands:
description: Build docker image for test
depends: [_build-base]
cmd: docker build -t hiku-tests -f Dockerfile --target tests .

_build-dev:
description: Build docker image for dev
depends: [_build-base]
Expand All @@ -53,7 +53,7 @@ commands:
description: Run tests
depends: [_build-tests]
cmd: [docker-compose, run, --rm, test]

test-tox:
description: Run tests using tox
depends: [_build-tests]
Expand All @@ -68,7 +68,7 @@ commands:
description: Run flake8
depends: [_build-dev]
cmd: docker-compose run --rm dev pdm run flake

black:
description: Run flake8
depends: [_build-dev]
Expand All @@ -83,7 +83,7 @@ commands:
description: Run federation app from examples
depends: [_build-examples]
cmd: docker-compose up examples-federation

examples-federation-v2:
description: Run federation 2 app from examples
depends: [_build-examples]
Expand Down
14 changes: 13 additions & 1 deletion tests/test_federation/test_sdl_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
Field,
Link,
Option,
Root, Union,
Root,
Union,
)
from hiku.types import (
Record,
Integer,
String,
TypeRef,
Optional,
UnionRef,
)
from hiku.graph import apply

Expand Down Expand Up @@ -61,6 +63,15 @@ def execute(graph, query_string):
Option('id', Integer),
],
),
Link(
'bucket',
UnionRef['Bucket'],
link_resolver,
requires=None,
options=[
Option('id', Integer),
],
),
]),
], data_types={
'Status': Record[{
Expand Down Expand Up @@ -97,6 +108,7 @@ def execute(graph, query_string):
extend type Query {
order(id: Int!): Order
bucket(id: Int!): Bucket!
}
scalar Any
Expand Down
19 changes: 16 additions & 3 deletions tests/test_federation/test_sdl_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@
Field,
Link,
Option,
Root, Union,
Root,
Union,
)
from hiku.types import (
Boolean, EnumRef, Record,
Boolean,
EnumRef,
Record,
Integer,
String,
TypeRef,
Optional,
UnionRef,
)
from hiku.scalar import Scalar
from hiku.graph import apply
Expand Down Expand Up @@ -86,6 +90,15 @@ def serialize(cls, value: Any) -> int:
Option('id', Integer),
],
),
Link(
'bucket',
UnionRef['Bucket'],
link_resolver,
requires=None,
options=[
Option('id', Integer),
],
),
]),
], data_types={
'Status': Record[{
Expand Down Expand Up @@ -153,6 +166,7 @@ def serialize(cls, value: Any) -> int:
extend type Query {
order(id: Int!): Order
bucket(id: Int!): Bucket!
}
%s
scalar Any
Expand Down Expand Up @@ -205,5 +219,4 @@ def test_print_introspected_graph_sdl():
])

sdl = print_sdl(INTROSPECTED_GRAPH)

assert sdl.strip() == textwrap.dedent(expected).strip()
2 changes: 1 addition & 1 deletion tests_pg/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def db_dsn_fixture(request):
db_dsn = 'postgresql://postgres:postgres@{}:5432/{}'.format(host, name)

pg_engine = sqlalchemy.create_engine(pg_dsn)
pg_engine.raw_connection()\
pg_engine.raw_connection() \
.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
pg_engine.execute('CREATE DATABASE {0}'.format(name))
pg_engine.dispose()
Expand Down

0 comments on commit 7b1fddf

Please sign in to comment.