turms
turms copied to clipboard
Refactor/reduce code duplication in plugins
@jhnnsrs I think its time, that you take a look at this.
The PR contains the refactoring of EnumsPlugin, InputsPlugin and ObjectsPlugin.
I mainly focused on breaking down the large functions into smaller methods of each Plugin.
Some code duplication is eliminated, the remaining similarities should be pretty obvious by now (as a preparation for the next refactoring iteration).
There is a new module ast_generators
that contains all concrete AST-Generation logic that was (duplicated a lot) in every plugin before.
I have the feeling, that there also should be a stricter separation between the concerns:
- Schema Parsing (Main job of the Plugin)
- Registration (Which Objects/Enums/Inputs to include)
- AST-Generation (Translate GraphQL Type to pydantic Model + Plugin-specific types like Operations/Funcs)
- Custom Styling (influence ast-generation, not during class registration)
Currently, each plugin does almost everything. Only the styling is somehow part of the ClassRegistry, were it shouldn't belong IMHO.
Also, have a look at this test tests/plugins/test_objects.py::make_test_cases_union_field_value