Skip to content

Allow alias on DSLMetaField #405

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

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions gql/dsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -924,12 +924,6 @@ def __init__(self, name: str):

super().__init__(name, self.meta_type, field)

def alias(self, alias: str) -> "DSLSelectableWithAlias":
"""
:meta private:
"""
return self


class DSLInlineFragment(DSLSelectable, DSLFragmentSelector):
"""DSLInlineFragment represents an inline fragment for the DSL code."""
Expand Down
24 changes: 19 additions & 5 deletions tests/starwars/test_dsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -870,11 +870,6 @@ def test_invalid_meta_field_selection(ds):
metafield = DSLMetaField("__typename")
assert metafield.name == "__typename"

# alias does not work
metafield.alias("test")

assert metafield.name == "__typename"

with pytest.raises(GraphQLError):
DSLMetaField("__invalid_meta_field")

Expand Down Expand Up @@ -936,3 +931,22 @@ def test_get_introspection_query_ast(option):
)

assert print_ast(gql(introspection_query)) == print_ast(dsl_introspection_query)


def test_typename_aliased(ds):
query = """
hero {
name
typenameField: __typename
}
""".strip()

query_dsl = ds.Query.hero.select(
ds.Character.name, typenameField=DSLMetaField("__typename")
)
assert query == str(query_dsl)

query_dsl = ds.Query.hero.select(
ds.Character.name, DSLMetaField("__typename").alias("typenameField")
)
assert query == str(query_dsl)