Skip to content
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

Code Completion In Pycharm #205

Open
ashnap123 opened this issue May 24, 2022 · 7 comments
Open

Code Completion In Pycharm #205

ashnap123 opened this issue May 24, 2022 · 7 comments
Assignees

Comments

@ashnap123
Copy link

This is a great library and almost exactly what I've been looking for. Do you know if there is a way to make code completion work in PyCharm for the auto generated schema? A functioning autocomplete would make this an zero fiction way to interact with graphql APIs.

@barbieri
Copy link
Member

could you elaborate? You mean completion when building the query (creating an operation) or interpreting the results?

@barbieri barbieri self-assigned this May 24, 2022
@ashnap123
Copy link
Author

Ideally both, but I think most value would come from code completion when building operations.

@ashnap123
Copy link
Author

ashnap123 commented May 24, 2022

When generating the schema would it be enough to add type hints?

Replacing:

class MarketingBudget(sgqlc.types.Type):
    __schema__ = shopify_schema
    __field_names__ = ('budget_type', 'total')
    budget_type = sgqlc.types.Field(sgqlc.types.non_null(MarketingBudgetBudgetType), graphql_name='budgetType')

With:

class MarketingBudget(sgqlc.types.Type):
    __schema__ = shopify_schema
    __field_names__ = ('budget_type', 'total')
    budget_type: MarketingBudgetBudgetType = sgqlc.types.Field(sgqlc.types.non_null(MarketingBudgetBudgetType), graphql_name='budgetType')

Although I am not familiar with the details or differences between Type and Field classes. But this is similar to how dataclasses work.

@barbieri
Copy link
Member

this is unfeasible as it is. I'd need to check if we can make sgqlc.types.Field into a generic that returns a wrapped type... but in reality we abuse metaclasses (just like dataclasses do), we'd need to write a specific mypy support.

This is one of the weakest spots of typechecking in python... if you do metaclasses transformations (like in my case it will get a class attribute and create ANOTHER instance attribute based on that... but it's not the same (one is a description, the other is a value based on that description). And Python ecosystem is full of metaclasses to save typing and autogenerate code (ex: all ORMs, such as Django...)

AFAIU dataclasses and similar are manually crafted in the type checking... but for not-so-famous projects we're hopeless :-(

@ashnap123
Copy link
Author

Thanks for taking time to think about this. If it's ever implemented I will definitely use this library in future.

@barbieri
Copy link
Member

yeah, I feel your pain... at work I'm using mostly TypeScript and when I have to go typeless it's a major issue. OTOH in TypeScript such things are a bit easier to write, since there is no "metaclass" stuff are derived from object mapping and one can easily do something like "for each object key, if the value type is X, do something, if it's Y, do another thing"...

@barbieri
Copy link
Member

btw, stay tuned in #129, it's almost the same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants