Skip to content

Set name of query dynamically #9

Description

@iwconfig

I'd like to be able to change the name of the class as it's represented in the query.

Example:

class HeroAndDroid(NamedTuple):
    hero: Hero
    droid: Droid

and instead of

print(GQL(QUERY | HeroAndDroid).query)

# 'query HeroAndDroid{hero{name}droid{name}}'

I'd like to do something like

print(GQL(QUERY | HeroAndDroid * AS * 'asdf').query)

# 'query asdf{hero{name}droid{name}}'

or

print(GQL(QUERY | HeroAndDroid * AS * ANONYMOUS).query)

# 'query {hero{name}droid{name}}'

Of course I can do it like this

#RENAME = lambda cls, name: type(name, (cls,), {})
RENAME = lambda cls, name: (setattr(cls, '__name__', name), cls)[-1]

print(GQL(QUERY | RENAME(HeroAndDroid, 'I_Prefer_This_Name')).query)

# 'query I_Prefer_This_Name{hero{name}droid{name}}'

but I think using the AS function for this is much more suitable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions