feat: models only mode#436
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
7e8fa95 to
b7da2c3
Compare
d91125e to
2a87a1d
Compare
* origin/main: feat: Allow to use custom client for fetching remote schema [AR-2] (mirumee#444) feat: add schema_paths for loading schema from local paths and installed packages AR-3 (mirumee#439) feat: Allow to use non-httpx HTTP clients in default clients [AR-1] (mirumee#440) remove: unnecessary lines fix fix: tests fix: use explicit UTF-8 encoding for ruff format subprocess (mirumee#422) (mirumee#428) fix: wrap long lines to satisfy ruff E501 docs: document multipart_uploads setting in README and configuration guide feat: add multipart_uploads setting to disable file upload support # Conflicts: # ariadne_codegen/client_generators/package.py
|
hi @DamianCzajkowski would you be able to review this PR? |
|
Hi @amin-farjadi, this feature will definitely be merged. We are currently discussing the features and the future of the codegen, so don’t worry; it will be merged this month. Thank you for contributing! |
Kwaidan00
left a comment
There was a problem hiding this comment.
Hi @amin-farjadi, thank you for your contribution! I left some comments about the overall implementation shape. Please review and let me know if you are planning to apply those changes.
| raise MissingConfiguration(f"Config has no [{tool_key}.{codegen_key}] section.") | ||
|
|
||
|
|
||
| def get_models_only_settings(config_dict: dict) -> ModelsOnlySettings: |
There was a problem hiding this comment.
Please correct me if I'm wrong, but this function is a copy of get_client_settings with the following changes:
- return typing
settings_fields_namesis set based onModelsOnlySettings- returned object is constructed as
ModelsOnlySettingsinstance
I believe there could be a single function which takes the model as parameter and is used for both the client settings and ModelsOnlySettings. Then, there could be two facade functions get_client_settings and get_models_only_settings that returns foo(config_dict, ModelsOnlySettings) or foo(config_dict, ClientSettings).
| base_client_import = generate_import_from( | ||
| names=["object"], from_="builtins", level=0 | ||
| ) | ||
| client_name = "Client" | ||
| base_client = "object" | ||
| async_client = True | ||
| base_client_file_path = "" | ||
| base_client_module_name = "" | ||
| client_file_name = "client" |
There was a problem hiding this comment.
You create a fake objects here just to satisfy the requirement to provide client_generator to PackageGenerator.
However, the strategy you implemented does not need to know anything about client at all - it's the mode without it.
This part of the code and multiple checks if not self.models_only in the generator methods suggest there could be a solution easier to maintain. There should be separate PackageGenerator subclasses: for the client mode and models only mode. Key concepts:
- most of the logic can be shared in the base class
generatemethod, as the most important function that describes the steps to perform, should be implemented in the subclassesadd_operationcould live in the base class, the "client mode" class can callsuper().add_operationand then call the additionalself.client_generator.add_method()_validate_unique_file_namescan live in the base class, but the subclasses should implement a method to return expected file names- similarly,
_copy_filescan live in the base class, but the subclasses can implement a method to return files to copy - finally, the
__init__can share most of the logic, but the "client mode" class can expect additional arguments likeclient_generatorand other client-related settings, unused for "models only" mode.
| default_optional_fields_to_none: bool = False | ||
| include_typename: bool = True | ||
| ignore_extra_fields: bool = True | ||
| multipart_uploads: bool = True |
There was a problem hiding this comment.
This specific key is used to decide if the base client should contain multipart uploads implementation or not. I think it's the typo to include it here.
|
|
||
|
|
||
| @dataclass | ||
| class ModelsOnlySettings(BaseSettings): |
There was a problem hiding this comment.
This model seems to contain a subset of fields defined in ClientSettings. Similarly, the __post_init__ is a shortened copy of ClientSettings.__post_init__.
I think better solution is to create a model e.g. GeneratorSettings(BaseSettings), it will contain the common set of fields and the common logic in __post_init__. Then, ClientSettings and ModelsOnlySettings should inherit GeneratorSettings and optionally add custom logic and additional fields.
| DirectiveLocation.ARGUMENT_DEFINITION, | ||
| DirectiveLocation.INPUT_FIELD_DEFINITION, | ||
| DirectiveLocation.ENUM_VALUE, | ||
| DirectiveLocation.DIRECTIVE_DEFINITION, |
| ) | ||
|
|
||
|
|
||
| class Upload: |
There was a problem hiding this comment.
This generated example shows the Upload class is not used anywhere (in the client mode, it is used in the client module). I think you can easily change your code to not include the Upload class by using base_model_no_upload.py instead of base_model.py.
| ), | ||
| "expected_client", | ||
| CLIENTS_PATH / "no_multipart_upload" / "expected_client", | ||
| ), |
There was a problem hiding this comment.
Why did you delete this test case?
Closes issue #418 and addresses comments on PR #419.