graphql-python/gql

DSLMetaField alias doesn't work

Dazix opened this issue · 2 comments

Dazix commented

Hi, I tried to use DSL module for generating dynamic queries and found out that I can't set alias for DSLMetaField.

Describe the bug
The DSLMetaField field cannot be aliased.
Actually, I'm not sure if this is really a bug because this behavior is covered by the test, but I think there is no reason to disallow aliasing DSLMetaField. The aliasing method is there, but it just doesn't work as it should, and you know, it's a bit confusing... it should generate the alias correctly, or throw an error when used, for example.
In current implementation it must be "hacked" to get alias work...

typename_field = DSLMetaField("__typename")
typename_field.ast_field.alias = NameNode(value="typename")

To Reproduce
Steps to reproduce the behavior:

ds.Query.hero.select(ds.Character.name, DSLMetaField("__typename").alias('typenameField'))

creates

hero {
    name
    __typename
}

Expected behavior
Example above should generate

hero {
    name
    typenameField: __typename
}

I don't really know why it was not allowed...
The PR #405 should fix this.

Dazix commented

Great, looks good. Thanks for a quick update 👍