From ebd40d033b34f8f8df41cdbe3713c15e1b14cf07 Mon Sep 17 00:00:00 2001 From: Minister944 Date: Fri, 23 Feb 2024 11:39:17 +0100 Subject: [PATCH 1/9] add model_rebuild_calls for result_types.py --- ariadne_codegen/client_generators/result_types.py | 13 +++++++++++-- .../expected_client/get_query_a.py | 4 ++++ .../custom_config_file/expected_client/test.py | 3 +++ .../expected_client/get_query_a.py | 4 ++++ .../clients/custom_scalars/expected_client/get_a.py | 4 ++++ .../clients/example/expected_client/create_user.py | 4 ++++ .../example/expected_client/get_users_counter.py | 3 +++ .../example/expected_client/list_all_users.py | 5 +++++ .../expected_client/list_users_by_country.py | 4 ++++ .../clients/example/expected_client/upload_file.py | 3 +++ .../expected_client/fragments_with_mixins.py | 5 +++++ .../extended_models/expected_client/get_query_a.py | 4 ++++ .../expected_client/get_query_a_with_fragment.py | 3 +++ .../extended_models/expected_client/get_query_b.py | 4 ++++ .../query_with_fragment_on_sub_interface.py | 5 +++++ ...ragment_on_sub_interface_with_inline_fragment.py | 6 ++++++ .../query_with_fragment_on_union_member.py | 5 +++++ .../inline_fragments/expected_client/interface_a.py | 6 ++++++ .../inline_fragments/expected_client/interface_b.py | 5 +++++ .../inline_fragments/expected_client/interface_c.py | 4 ++++ .../expected_client/interface_with_typename.py | 4 ++++ .../expected_client/list_interface.py | 6 ++++++ .../inline_fragments/expected_client/list_union.py | 6 ++++++ .../query_with_fragment_on_interface.py | 6 ++++++ .../query_with_fragment_on_query_with_interface.py | 3 +++ .../query_with_fragment_on_query_with_union.py | 3 +++ .../expected_client/query_with_fragment_on_union.py | 6 ++++++ .../inline_fragments/expected_client/union_a.py | 6 ++++++ .../inline_fragments/expected_client/union_b.py | 6 ++++++ .../expected_client/example_query_1.py | 4 ++++ .../expected_client/example_query_2.py | 4 ++++ .../expected_client/example_query_3.py | 4 ++++ .../expected_client/get_a.py | 3 +++ .../expected_client/get_a_2.py | 3 +++ .../expected_client/get_b.py | 3 +++ .../expected_client/get_d.py | 3 +++ .../expected_client/get_e.py | 3 +++ .../expected_client/get_f.py | 4 ++++ .../expected_client/get_g.py | 4 ++++ .../operations/expected_client/c_mutation.py | 3 +++ .../clients/operations/expected_client/c_query.py | 3 +++ .../operations/expected_client/c_subscription.py | 3 +++ .../clients/operations/expected_client/get_a.py | 5 +++++ .../expected_client/get_a_with_fragment.py | 5 +++++ .../clients/operations/expected_client/get_s.py | 4 ++++ .../clients/operations/expected_client/get_xyz.py | 6 ++++++ .../clients/remote_schema/expected_client/test.py | 3 +++ .../expected_client/get_animal_by_name.py | 6 ++++++ .../get_animal_fragment_with_extra.py | 3 +++ .../expected_client/get_authenticated_user.py | 4 ++++ .../expected_client/get_complex_scalar.py | 3 +++ .../expected_client/get_simple_scalar.py | 3 +++ .../shorter_results/expected_client/list_animals.py | 6 ++++++ .../expected_client/list_strings_1.py | 3 +++ .../expected_client/list_strings_2.py | 3 +++ .../expected_client/list_strings_3.py | 3 +++ .../expected_client/list_strings_4.py | 3 +++ .../shorter_results/expected_client/list_type_a.py | 4 ++++ .../expected_client/subscribe_strings.py | 3 +++ .../expected_client/unwrap_fragment.py | 3 +++ 60 files changed, 252 insertions(+), 2 deletions(-) diff --git a/ariadne_codegen/client_generators/result_types.py b/ariadne_codegen/client_generators/result_types.py index 745a45fa..697ee3f4 100644 --- a/ariadne_codegen/client_generators/result_types.py +++ b/ariadne_codegen/client_generators/result_types.py @@ -38,6 +38,8 @@ generate_module, generate_pass, generate_pydantic_field, + generate_method_call, + generate_expr, ) from ..exceptions import NotSupported, ParsingError from ..plugins.manager import PluginManager @@ -61,6 +63,7 @@ TYPENAME_FIELD_NAME, TYPING_MODULE, UNION, + MODEL_REBUILD_METHOD, ) from .result_fields import FieldContext, is_union, parse_operation_field from .scalars import ScalarData, generate_scalar_imports @@ -152,8 +155,14 @@ def _get_operation_type_name(self, definition: ExecutableDefinitionNode) -> str: raise NotSupported(f"Not supported operation type: {definition}") def generate(self) -> ast.Module: - module_body = cast(List[ast.stmt], self._imports) + cast( - List[ast.stmt], self._class_defs + model_rebuild_calls = [ + generate_expr(generate_method_call(class_def.name, MODEL_REBUILD_METHOD)) + for class_def in self._class_defs + ] + module_body = ( + cast(List[ast.stmt], self._imports) + + cast(List[ast.stmt], self._class_defs) + + cast(List[ast.stmt], model_rebuild_calls) ) module = generate_module(module_body) diff --git a/tests/main/clients/custom_base_client/expected_client/get_query_a.py b/tests/main/clients/custom_base_client/expected_client/get_query_a.py index c268666c..a577cb40 100644 --- a/tests/main/clients/custom_base_client/expected_client/get_query_a.py +++ b/tests/main/clients/custom_base_client/expected_client/get_query_a.py @@ -9,3 +9,7 @@ class GetQueryA(BaseModel): class GetQueryAQueryA(BaseModel): field_a: int = Field(alias="fieldA") + + +GetQueryA.model_rebuild() +GetQueryAQueryA.model_rebuild() diff --git a/tests/main/clients/custom_config_file/expected_client/test.py b/tests/main/clients/custom_config_file/expected_client/test.py index add3b3b6..f44774b9 100644 --- a/tests/main/clients/custom_config_file/expected_client/test.py +++ b/tests/main/clients/custom_config_file/expected_client/test.py @@ -5,3 +5,6 @@ class Test(BaseModel): test_query: str = Field(alias="testQuery") + + +Test.model_rebuild() diff --git a/tests/main/clients/custom_files_names/expected_client/get_query_a.py b/tests/main/clients/custom_files_names/expected_client/get_query_a.py index c268666c..a577cb40 100644 --- a/tests/main/clients/custom_files_names/expected_client/get_query_a.py +++ b/tests/main/clients/custom_files_names/expected_client/get_query_a.py @@ -9,3 +9,7 @@ class GetQueryA(BaseModel): class GetQueryAQueryA(BaseModel): field_a: int = Field(alias="fieldA") + + +GetQueryA.model_rebuild() +GetQueryAQueryA.model_rebuild() diff --git a/tests/main/clients/custom_scalars/expected_client/get_a.py b/tests/main/clients/custom_scalars/expected_client/get_a.py index 3c0ff16a..d1170bf0 100644 --- a/tests/main/clients/custom_scalars/expected_client/get_a.py +++ b/tests/main/clients/custom_scalars/expected_client/get_a.py @@ -16,3 +16,7 @@ class GetATestQuery(BaseModel): code: Annotated[Code, BeforeValidator(parse_code)] id: int other: Any + + +GetA.model_rebuild() +GetATestQuery.model_rebuild() diff --git a/tests/main/clients/example/expected_client/create_user.py b/tests/main/clients/example/expected_client/create_user.py index 2a7283e6..07d3a975 100644 --- a/tests/main/clients/example/expected_client/create_user.py +++ b/tests/main/clients/example/expected_client/create_user.py @@ -11,3 +11,7 @@ class CreateUser(BaseModel): class CreateUserUserCreate(BaseModel): id: str + + +CreateUser.model_rebuild() +CreateUserUserCreate.model_rebuild() diff --git a/tests/main/clients/example/expected_client/get_users_counter.py b/tests/main/clients/example/expected_client/get_users_counter.py index 6dd3c72b..1348b678 100644 --- a/tests/main/clients/example/expected_client/get_users_counter.py +++ b/tests/main/clients/example/expected_client/get_users_counter.py @@ -5,3 +5,6 @@ class GetUsersCounter(BaseModel): users_counter: int = Field(alias="usersCounter") + + +GetUsersCounter.model_rebuild() diff --git a/tests/main/clients/example/expected_client/list_all_users.py b/tests/main/clients/example/expected_client/list_all_users.py index 88a4d687..879f5081 100644 --- a/tests/main/clients/example/expected_client/list_all_users.py +++ b/tests/main/clients/example/expected_client/list_all_users.py @@ -19,3 +19,8 @@ class ListAllUsersUsers(BaseModel): class ListAllUsersUsersLocation(BaseModel): country: Optional[str] + + +ListAllUsers.model_rebuild() +ListAllUsersUsers.model_rebuild() +ListAllUsersUsersLocation.model_rebuild() diff --git a/tests/main/clients/example/expected_client/list_users_by_country.py b/tests/main/clients/example/expected_client/list_users_by_country.py index 14523c56..0fc7069f 100644 --- a/tests/main/clients/example/expected_client/list_users_by_country.py +++ b/tests/main/clients/example/expected_client/list_users_by_country.py @@ -13,3 +13,7 @@ class ListUsersByCountry(BaseModel): class ListUsersByCountryUsers(BasicUser, UserPersonalData): favourite_color: Optional[Color] = Field(alias="favouriteColor") + + +ListUsersByCountry.model_rebuild() +ListUsersByCountryUsers.model_rebuild() diff --git a/tests/main/clients/example/expected_client/upload_file.py b/tests/main/clients/example/expected_client/upload_file.py index 2afaaca3..42d32e4b 100644 --- a/tests/main/clients/example/expected_client/upload_file.py +++ b/tests/main/clients/example/expected_client/upload_file.py @@ -5,3 +5,6 @@ class UploadFile(BaseModel): file_upload: bool = Field(alias="fileUpload") + + +UploadFile.model_rebuild() diff --git a/tests/main/clients/extended_models/expected_client/fragments_with_mixins.py b/tests/main/clients/extended_models/expected_client/fragments_with_mixins.py index 6f4a2181..e4677144 100644 --- a/tests/main/clients/extended_models/expected_client/fragments_with_mixins.py +++ b/tests/main/clients/extended_models/expected_client/fragments_with_mixins.py @@ -16,3 +16,8 @@ class FragmentsWithMixinsQueryA(FragmentA, CommonMixin): class FragmentsWithMixinsQueryB(FragmentB, CommonMixin): pass + + +FragmentsWithMixins.model_rebuild() +FragmentsWithMixinsQueryA.model_rebuild() +FragmentsWithMixinsQueryB.model_rebuild() diff --git a/tests/main/clients/extended_models/expected_client/get_query_a.py b/tests/main/clients/extended_models/expected_client/get_query_a.py index 2da9a414..3e2cd5f5 100644 --- a/tests/main/clients/extended_models/expected_client/get_query_a.py +++ b/tests/main/clients/extended_models/expected_client/get_query_a.py @@ -11,3 +11,7 @@ class GetQueryA(BaseModel): class GetQueryAQueryA(BaseModel, MixinA, CommonMixin): field_a: int = Field(alias="fieldA") + + +GetQueryA.model_rebuild() +GetQueryAQueryA.model_rebuild() diff --git a/tests/main/clients/extended_models/expected_client/get_query_a_with_fragment.py b/tests/main/clients/extended_models/expected_client/get_query_a_with_fragment.py index e8f4cebe..1f390847 100644 --- a/tests/main/clients/extended_models/expected_client/get_query_a_with_fragment.py +++ b/tests/main/clients/extended_models/expected_client/get_query_a_with_fragment.py @@ -3,3 +3,6 @@ class GetQueryAWithFragment(GetQueryAFragment): pass + + +GetQueryAWithFragment.model_rebuild() diff --git a/tests/main/clients/extended_models/expected_client/get_query_b.py b/tests/main/clients/extended_models/expected_client/get_query_b.py index 0d01bc1a..bc377611 100644 --- a/tests/main/clients/extended_models/expected_client/get_query_b.py +++ b/tests/main/clients/extended_models/expected_client/get_query_b.py @@ -11,3 +11,7 @@ class GetQueryB(BaseModel): class GetQueryBQueryB(BaseModel, MixinB, CommonMixin): field_b: str = Field(alias="fieldB") + + +GetQueryB.model_rebuild() +GetQueryBQueryB.model_rebuild() diff --git a/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_sub_interface.py b/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_sub_interface.py index 0afd988c..bf1d9b0f 100644 --- a/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_sub_interface.py +++ b/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_sub_interface.py @@ -19,3 +19,8 @@ class QueryWithFragmentOnSubInterfaceQueryInterfaceBaseInterface(BaseModel): class QueryWithFragmentOnSubInterfaceQueryInterfaceInterfaceA(FragmentA): typename__: Literal["InterfaceA"] = Field(alias="__typename") + + +QueryWithFragmentOnSubInterface.model_rebuild() +QueryWithFragmentOnSubInterfaceQueryInterfaceBaseInterface.model_rebuild() +QueryWithFragmentOnSubInterfaceQueryInterfaceInterfaceA.model_rebuild() diff --git a/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_sub_interface_with_inline_fragment.py b/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_sub_interface_with_inline_fragment.py index f4f96174..7ac39fed 100644 --- a/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_sub_interface_with_inline_fragment.py +++ b/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_sub_interface_with_inline_fragment.py @@ -32,3 +32,9 @@ class QueryWithFragmentOnSubInterfaceWithInlineFragmentQueryInterfaceTypeA(BaseM id: str value_a: str = Field(alias="valueA") another: str + + +QueryWithFragmentOnSubInterfaceWithInlineFragment.model_rebuild() +QueryWithFragmentOnSubInterfaceWithInlineFragmentQueryInterfaceBaseInterface.model_rebuild() +QueryWithFragmentOnSubInterfaceWithInlineFragmentQueryInterfaceInterfaceA.model_rebuild() +QueryWithFragmentOnSubInterfaceWithInlineFragmentQueryInterfaceTypeA.model_rebuild() diff --git a/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_union_member.py b/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_union_member.py index 02a0211a..e84e11e4 100644 --- a/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_union_member.py +++ b/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_union_member.py @@ -19,3 +19,8 @@ class QueryWithFragmentOnUnionMemberQueryUnionTypeA(BaseModel): class QueryWithFragmentOnUnionMemberQueryUnionTypeB(FragmentB): typename__: Literal["TypeB"] = Field(alias="__typename") + + +QueryWithFragmentOnUnionMember.model_rebuild() +QueryWithFragmentOnUnionMemberQueryUnionTypeA.model_rebuild() +QueryWithFragmentOnUnionMemberQueryUnionTypeB.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/interface_a.py b/tests/main/clients/inline_fragments/expected_client/interface_a.py index 3f098919..adbd6d5b 100644 --- a/tests/main/clients/inline_fragments/expected_client/interface_a.py +++ b/tests/main/clients/inline_fragments/expected_client/interface_a.py @@ -26,3 +26,9 @@ class InterfaceAQueryITypeB(BaseModel): typename__: Literal["TypeB"] = Field(alias="__typename") id: str field_b: str = Field(alias="fieldB") + + +InterfaceA.model_rebuild() +InterfaceAQueryIInterface.model_rebuild() +InterfaceAQueryITypeA.model_rebuild() +InterfaceAQueryITypeB.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/interface_b.py b/tests/main/clients/inline_fragments/expected_client/interface_b.py index 63bf5052..cb599b73 100644 --- a/tests/main/clients/inline_fragments/expected_client/interface_b.py +++ b/tests/main/clients/inline_fragments/expected_client/interface_b.py @@ -20,3 +20,8 @@ class InterfaceBQueryITypeA(BaseModel): typename__: Literal["TypeA"] = Field(alias="__typename") id: str field_a: str = Field(alias="fieldA") + + +InterfaceB.model_rebuild() +InterfaceBQueryIInterface.model_rebuild() +InterfaceBQueryITypeA.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/interface_c.py b/tests/main/clients/inline_fragments/expected_client/interface_c.py index 700597a0..e9b205d6 100644 --- a/tests/main/clients/inline_fragments/expected_client/interface_c.py +++ b/tests/main/clients/inline_fragments/expected_client/interface_c.py @@ -14,3 +14,7 @@ class InterfaceCQueryI(BaseModel): alias="__typename" ) id: str + + +InterfaceC.model_rebuild() +InterfaceCQueryI.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/interface_with_typename.py b/tests/main/clients/inline_fragments/expected_client/interface_with_typename.py index 1c5a9110..d51fabe3 100644 --- a/tests/main/clients/inline_fragments/expected_client/interface_with_typename.py +++ b/tests/main/clients/inline_fragments/expected_client/interface_with_typename.py @@ -14,3 +14,7 @@ class InterfaceWithTypenameQueryI(BaseModel): alias="__typename" ) id: str + + +InterfaceWithTypename.model_rebuild() +InterfaceWithTypenameQueryI.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/list_interface.py b/tests/main/clients/inline_fragments/expected_client/list_interface.py index a3e0583b..ad9fde2d 100644 --- a/tests/main/clients/inline_fragments/expected_client/list_interface.py +++ b/tests/main/clients/inline_fragments/expected_client/list_interface.py @@ -33,3 +33,9 @@ class ListInterfaceQueryListITypeB(BaseModel): typename__: Literal["TypeB"] = Field(alias="__typename") id: str field_b: str = Field(alias="fieldB") + + +ListInterface.model_rebuild() +ListInterfaceQueryListIInterface.model_rebuild() +ListInterfaceQueryListITypeA.model_rebuild() +ListInterfaceQueryListITypeB.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/list_union.py b/tests/main/clients/inline_fragments/expected_client/list_union.py index 17295a7e..fe2d6b3e 100644 --- a/tests/main/clients/inline_fragments/expected_client/list_union.py +++ b/tests/main/clients/inline_fragments/expected_client/list_union.py @@ -32,3 +32,9 @@ class ListUnionQueryListUTypeB(BaseModel): class ListUnionQueryListUTypeC(BaseModel): typename__: Literal["TypeC"] = Field(alias="__typename") + + +ListUnion.model_rebuild() +ListUnionQueryListUTypeA.model_rebuild() +ListUnionQueryListUTypeB.model_rebuild() +ListUnionQueryListUTypeC.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_interface.py b/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_interface.py index a454ce84..7ba0e795 100644 --- a/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_interface.py +++ b/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_interface.py @@ -28,3 +28,9 @@ class QueryWithFragmentOnInterfaceQueryITypeB(BaseModel): typename__: Literal["TypeB"] = Field(alias="__typename") id: str field_b: str = Field(alias="fieldB") + + +QueryWithFragmentOnInterface.model_rebuild() +QueryWithFragmentOnInterfaceQueryIInterface.model_rebuild() +QueryWithFragmentOnInterfaceQueryITypeA.model_rebuild() +QueryWithFragmentOnInterfaceQueryITypeB.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_query_with_interface.py b/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_query_with_interface.py index c4705560..b2989694 100644 --- a/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_query_with_interface.py +++ b/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_query_with_interface.py @@ -3,3 +3,6 @@ class QueryWithFragmentOnQueryWithInterface(FragmentOnQueryWithInterface): pass + + +QueryWithFragmentOnQueryWithInterface.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_query_with_union.py b/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_query_with_union.py index 1f2b1d54..94d1318e 100644 --- a/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_query_with_union.py +++ b/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_query_with_union.py @@ -3,3 +3,6 @@ class QueryWithFragmentOnQueryWithUnion(FragmentOnQueryWithUnion): pass + + +QueryWithFragmentOnQueryWithUnion.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_union.py b/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_union.py index 36b9d85a..5057e490 100644 --- a/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_union.py +++ b/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_union.py @@ -27,3 +27,9 @@ class QueryWithFragmentOnUnionQueryUTypeB(BaseModel): class QueryWithFragmentOnUnionQueryUTypeC(BaseModel): typename__: Literal["TypeC"] = Field(alias="__typename") + + +QueryWithFragmentOnUnion.model_rebuild() +QueryWithFragmentOnUnionQueryUTypeA.model_rebuild() +QueryWithFragmentOnUnionQueryUTypeB.model_rebuild() +QueryWithFragmentOnUnionQueryUTypeC.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/union_a.py b/tests/main/clients/inline_fragments/expected_client/union_a.py index ae379c11..bc0cbd2e 100644 --- a/tests/main/clients/inline_fragments/expected_client/union_a.py +++ b/tests/main/clients/inline_fragments/expected_client/union_a.py @@ -25,3 +25,9 @@ class UnionAQueryUTypeB(BaseModel): class UnionAQueryUTypeC(BaseModel): typename__: Literal["TypeC"] = Field(alias="__typename") + + +UnionA.model_rebuild() +UnionAQueryUTypeA.model_rebuild() +UnionAQueryUTypeB.model_rebuild() +UnionAQueryUTypeC.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/union_b.py b/tests/main/clients/inline_fragments/expected_client/union_b.py index 5200a741..983f1239 100644 --- a/tests/main/clients/inline_fragments/expected_client/union_b.py +++ b/tests/main/clients/inline_fragments/expected_client/union_b.py @@ -23,3 +23,9 @@ class UnionBQueryUTypeB(BaseModel): class UnionBQueryUTypeC(BaseModel): typename__: Literal["TypeC"] = Field(alias="__typename") + + +UnionB.model_rebuild() +UnionBQueryUTypeA.model_rebuild() +UnionBQueryUTypeB.model_rebuild() +UnionBQueryUTypeC.model_rebuild() diff --git a/tests/main/clients/multiple_fragments/expected_client/example_query_1.py b/tests/main/clients/multiple_fragments/expected_client/example_query_1.py index 07f203e9..4a8e7935 100644 --- a/tests/main/clients/multiple_fragments/expected_client/example_query_1.py +++ b/tests/main/clients/multiple_fragments/expected_client/example_query_1.py @@ -10,3 +10,7 @@ class ExampleQuery1(BaseModel): class ExampleQuery1ExampleQuery(MinimalA): value: str + + +ExampleQuery1.model_rebuild() +ExampleQuery1ExampleQuery.model_rebuild() diff --git a/tests/main/clients/multiple_fragments/expected_client/example_query_2.py b/tests/main/clients/multiple_fragments/expected_client/example_query_2.py index 9c8ecd4c..f874deee 100644 --- a/tests/main/clients/multiple_fragments/expected_client/example_query_2.py +++ b/tests/main/clients/multiple_fragments/expected_client/example_query_2.py @@ -10,3 +10,7 @@ class ExampleQuery2(BaseModel): class ExampleQuery2ExampleQuery(FullA): pass + + +ExampleQuery2.model_rebuild() +ExampleQuery2ExampleQuery.model_rebuild() diff --git a/tests/main/clients/multiple_fragments/expected_client/example_query_3.py b/tests/main/clients/multiple_fragments/expected_client/example_query_3.py index bb399416..5e96b22b 100644 --- a/tests/main/clients/multiple_fragments/expected_client/example_query_3.py +++ b/tests/main/clients/multiple_fragments/expected_client/example_query_3.py @@ -10,3 +10,7 @@ class ExampleQuery3(BaseModel): class ExampleQuery3ExampleQuery(CompleteA): pass + + +ExampleQuery3.model_rebuild() +ExampleQuery3ExampleQuery.model_rebuild() diff --git a/tests/main/clients/only_used_inputs_and_enums/expected_client/get_a.py b/tests/main/clients/only_used_inputs_and_enums/expected_client/get_a.py index 4aa89ddc..a5f6dea3 100644 --- a/tests/main/clients/only_used_inputs_and_enums/expected_client/get_a.py +++ b/tests/main/clients/only_used_inputs_and_enums/expected_client/get_a.py @@ -3,3 +3,6 @@ class GetA(BaseModel): a: str + + +GetA.model_rebuild() diff --git a/tests/main/clients/only_used_inputs_and_enums/expected_client/get_a_2.py b/tests/main/clients/only_used_inputs_and_enums/expected_client/get_a_2.py index 1a9211e4..aac160e3 100644 --- a/tests/main/clients/only_used_inputs_and_enums/expected_client/get_a_2.py +++ b/tests/main/clients/only_used_inputs_and_enums/expected_client/get_a_2.py @@ -3,3 +3,6 @@ class GetA2(BaseModel): a: str + + +GetA2.model_rebuild() diff --git a/tests/main/clients/only_used_inputs_and_enums/expected_client/get_b.py b/tests/main/clients/only_used_inputs_and_enums/expected_client/get_b.py index d6d8adf8..9de75751 100644 --- a/tests/main/clients/only_used_inputs_and_enums/expected_client/get_b.py +++ b/tests/main/clients/only_used_inputs_and_enums/expected_client/get_b.py @@ -3,3 +3,6 @@ class GetB(BaseModel): b: str + + +GetB.model_rebuild() diff --git a/tests/main/clients/only_used_inputs_and_enums/expected_client/get_d.py b/tests/main/clients/only_used_inputs_and_enums/expected_client/get_d.py index cb77066b..ad513404 100644 --- a/tests/main/clients/only_used_inputs_and_enums/expected_client/get_d.py +++ b/tests/main/clients/only_used_inputs_and_enums/expected_client/get_d.py @@ -3,3 +3,6 @@ class GetD(BaseModel): d: str + + +GetD.model_rebuild() diff --git a/tests/main/clients/only_used_inputs_and_enums/expected_client/get_e.py b/tests/main/clients/only_used_inputs_and_enums/expected_client/get_e.py index 30a4e661..659db1fd 100644 --- a/tests/main/clients/only_used_inputs_and_enums/expected_client/get_e.py +++ b/tests/main/clients/only_used_inputs_and_enums/expected_client/get_e.py @@ -3,3 +3,6 @@ class GetE(BaseModel): e: str + + +GetE.model_rebuild() diff --git a/tests/main/clients/only_used_inputs_and_enums/expected_client/get_f.py b/tests/main/clients/only_used_inputs_and_enums/expected_client/get_f.py index be43abb2..c0ddbd7e 100644 --- a/tests/main/clients/only_used_inputs_and_enums/expected_client/get_f.py +++ b/tests/main/clients/only_used_inputs_and_enums/expected_client/get_f.py @@ -8,3 +8,7 @@ class GetF(BaseModel): class GetFF(BaseModel): val: EnumF + + +GetF.model_rebuild() +GetFF.model_rebuild() diff --git a/tests/main/clients/only_used_inputs_and_enums/expected_client/get_g.py b/tests/main/clients/only_used_inputs_and_enums/expected_client/get_g.py index 2bf69471..e06cf16b 100644 --- a/tests/main/clients/only_used_inputs_and_enums/expected_client/get_g.py +++ b/tests/main/clients/only_used_inputs_and_enums/expected_client/get_g.py @@ -8,3 +8,7 @@ class GetG(BaseModel): class GetGG(FragmentG): pass + + +GetG.model_rebuild() +GetGG.model_rebuild() diff --git a/tests/main/clients/operations/expected_client/c_mutation.py b/tests/main/clients/operations/expected_client/c_mutation.py index 184a6e07..c54181ad 100644 --- a/tests/main/clients/operations/expected_client/c_mutation.py +++ b/tests/main/clients/operations/expected_client/c_mutation.py @@ -5,3 +5,6 @@ class CMutation(BaseModel): const_mutation: int = Field(alias="constMutation") + + +CMutation.model_rebuild() diff --git a/tests/main/clients/operations/expected_client/c_query.py b/tests/main/clients/operations/expected_client/c_query.py index 99534708..6e091385 100644 --- a/tests/main/clients/operations/expected_client/c_query.py +++ b/tests/main/clients/operations/expected_client/c_query.py @@ -5,3 +5,6 @@ class CQuery(BaseModel): const_query: str = Field(alias="constQuery") + + +CQuery.model_rebuild() diff --git a/tests/main/clients/operations/expected_client/c_subscription.py b/tests/main/clients/operations/expected_client/c_subscription.py index 2db7b506..1fb73975 100644 --- a/tests/main/clients/operations/expected_client/c_subscription.py +++ b/tests/main/clients/operations/expected_client/c_subscription.py @@ -5,3 +5,6 @@ class CSubscription(BaseModel): const_subscription: float = Field(alias="constSubscription") + + +CSubscription.model_rebuild() diff --git a/tests/main/clients/operations/expected_client/get_a.py b/tests/main/clients/operations/expected_client/get_a.py index 099ce5f4..e6fd0abe 100644 --- a/tests/main/clients/operations/expected_client/get_a.py +++ b/tests/main/clients/operations/expected_client/get_a.py @@ -14,3 +14,8 @@ class GetAA(BaseModel): class GetAAValueB(BaseModel): value: str + + +GetA.model_rebuild() +GetAA.model_rebuild() +GetAAValueB.model_rebuild() diff --git a/tests/main/clients/operations/expected_client/get_a_with_fragment.py b/tests/main/clients/operations/expected_client/get_a_with_fragment.py index c812c167..cc006f37 100644 --- a/tests/main/clients/operations/expected_client/get_a_with_fragment.py +++ b/tests/main/clients/operations/expected_client/get_a_with_fragment.py @@ -15,3 +15,8 @@ class GetAWithFragmentA(BaseModel): class GetAWithFragmentAValueB(FragmentB): pass + + +GetAWithFragment.model_rebuild() +GetAWithFragmentA.model_rebuild() +GetAWithFragmentAValueB.model_rebuild() diff --git a/tests/main/clients/operations/expected_client/get_s.py b/tests/main/clients/operations/expected_client/get_s.py index 4c52cfcf..4aa1746f 100644 --- a/tests/main/clients/operations/expected_client/get_s.py +++ b/tests/main/clients/operations/expected_client/get_s.py @@ -7,3 +7,7 @@ class GetS(BaseModel): class GetSS(BaseModel): id: int + + +GetS.model_rebuild() +GetSS.model_rebuild() diff --git a/tests/main/clients/operations/expected_client/get_xyz.py b/tests/main/clients/operations/expected_client/get_xyz.py index 80d4d363..2ca5da60 100644 --- a/tests/main/clients/operations/expected_client/get_xyz.py +++ b/tests/main/clients/operations/expected_client/get_xyz.py @@ -23,3 +23,9 @@ class GetXYZXyzTypeY(FragmentY): class GetXYZXyzTypeZ(BaseModel): typename__: Literal["TypeZ"] = Field(alias="__typename") + + +GetXYZ.model_rebuild() +GetXYZXyzTypeX.model_rebuild() +GetXYZXyzTypeY.model_rebuild() +GetXYZXyzTypeZ.model_rebuild() diff --git a/tests/main/clients/remote_schema/expected_client/test.py b/tests/main/clients/remote_schema/expected_client/test.py index facaa9a9..71819d90 100644 --- a/tests/main/clients/remote_schema/expected_client/test.py +++ b/tests/main/clients/remote_schema/expected_client/test.py @@ -7,3 +7,6 @@ class Test(BaseModel): test_query: Optional[int] = Field(alias="testQuery") + + +Test.model_rebuild() diff --git a/tests/main/clients/shorter_results/expected_client/get_animal_by_name.py b/tests/main/clients/shorter_results/expected_client/get_animal_by_name.py index f048ec23..1da2cfa1 100644 --- a/tests/main/clients/shorter_results/expected_client/get_animal_by_name.py +++ b/tests/main/clients/shorter_results/expected_client/get_animal_by_name.py @@ -28,3 +28,9 @@ class GetAnimalByNameAnimalByNameDog(BaseModel): typename__: Literal["Dog"] = Field(alias="__typename") name: str puppies: int + + +GetAnimalByName.model_rebuild() +GetAnimalByNameAnimalByNameAnimal.model_rebuild() +GetAnimalByNameAnimalByNameCat.model_rebuild() +GetAnimalByNameAnimalByNameDog.model_rebuild() diff --git a/tests/main/clients/shorter_results/expected_client/get_animal_fragment_with_extra.py b/tests/main/clients/shorter_results/expected_client/get_animal_fragment_with_extra.py index f7412926..3419f74c 100644 --- a/tests/main/clients/shorter_results/expected_client/get_animal_fragment_with_extra.py +++ b/tests/main/clients/shorter_results/expected_client/get_animal_fragment_with_extra.py @@ -7,3 +7,6 @@ class GetAnimalFragmentWithExtra(ListAnimalsFragment): list_string: List[str] = Field(alias="listString") + + +GetAnimalFragmentWithExtra.model_rebuild() diff --git a/tests/main/clients/shorter_results/expected_client/get_authenticated_user.py b/tests/main/clients/shorter_results/expected_client/get_authenticated_user.py index 5ca6ff5b..f932f338 100644 --- a/tests/main/clients/shorter_results/expected_client/get_authenticated_user.py +++ b/tests/main/clients/shorter_results/expected_client/get_authenticated_user.py @@ -8,3 +8,7 @@ class GetAuthenticatedUser(BaseModel): class GetAuthenticatedUserMe(BaseModel): id: str username: str + + +GetAuthenticatedUser.model_rebuild() +GetAuthenticatedUserMe.model_rebuild() diff --git a/tests/main/clients/shorter_results/expected_client/get_complex_scalar.py b/tests/main/clients/shorter_results/expected_client/get_complex_scalar.py index 78563772..0a14bb8b 100644 --- a/tests/main/clients/shorter_results/expected_client/get_complex_scalar.py +++ b/tests/main/clients/shorter_results/expected_client/get_complex_scalar.py @@ -10,3 +10,6 @@ class GetComplexScalar(BaseModel): just_complex_scalar: Annotated[ ComplexScalar, BeforeValidator(parse_complex_scalar) ] = Field(alias="justComplexScalar") + + +GetComplexScalar.model_rebuild() diff --git a/tests/main/clients/shorter_results/expected_client/get_simple_scalar.py b/tests/main/clients/shorter_results/expected_client/get_simple_scalar.py index 365f7eaa..64a3e8bf 100644 --- a/tests/main/clients/shorter_results/expected_client/get_simple_scalar.py +++ b/tests/main/clients/shorter_results/expected_client/get_simple_scalar.py @@ -6,3 +6,6 @@ class GetSimpleScalar(BaseModel): just_simple_scalar: SimpleScalar = Field(alias="justSimpleScalar") + + +GetSimpleScalar.model_rebuild() diff --git a/tests/main/clients/shorter_results/expected_client/list_animals.py b/tests/main/clients/shorter_results/expected_client/list_animals.py index 93776d69..b20ccda2 100644 --- a/tests/main/clients/shorter_results/expected_client/list_animals.py +++ b/tests/main/clients/shorter_results/expected_client/list_animals.py @@ -33,3 +33,9 @@ class ListAnimalsListAnimalsDog(BaseModel): typename__: Literal["Dog"] = Field(alias="__typename") name: str puppies: int + + +ListAnimals.model_rebuild() +ListAnimalsListAnimalsAnimal.model_rebuild() +ListAnimalsListAnimalsCat.model_rebuild() +ListAnimalsListAnimalsDog.model_rebuild() diff --git a/tests/main/clients/shorter_results/expected_client/list_strings_1.py b/tests/main/clients/shorter_results/expected_client/list_strings_1.py index fd8c06de..030d52e3 100644 --- a/tests/main/clients/shorter_results/expected_client/list_strings_1.py +++ b/tests/main/clients/shorter_results/expected_client/list_strings_1.py @@ -9,3 +9,6 @@ class ListStrings1(BaseModel): optional_list_optional_string: Optional[List[Optional[str]]] = Field( alias="optionalListOptionalString" ) + + +ListStrings1.model_rebuild() diff --git a/tests/main/clients/shorter_results/expected_client/list_strings_2.py b/tests/main/clients/shorter_results/expected_client/list_strings_2.py index d91ec117..c5dd179d 100644 --- a/tests/main/clients/shorter_results/expected_client/list_strings_2.py +++ b/tests/main/clients/shorter_results/expected_client/list_strings_2.py @@ -7,3 +7,6 @@ class ListStrings2(BaseModel): optional_list_string: Optional[List[str]] = Field(alias="optionalListString") + + +ListStrings2.model_rebuild() diff --git a/tests/main/clients/shorter_results/expected_client/list_strings_3.py b/tests/main/clients/shorter_results/expected_client/list_strings_3.py index 88f6e2cf..7ac7acdb 100644 --- a/tests/main/clients/shorter_results/expected_client/list_strings_3.py +++ b/tests/main/clients/shorter_results/expected_client/list_strings_3.py @@ -7,3 +7,6 @@ class ListStrings3(BaseModel): list_optional_string: List[Optional[str]] = Field(alias="listOptionalString") + + +ListStrings3.model_rebuild() diff --git a/tests/main/clients/shorter_results/expected_client/list_strings_4.py b/tests/main/clients/shorter_results/expected_client/list_strings_4.py index 15872b23..692bc3dc 100644 --- a/tests/main/clients/shorter_results/expected_client/list_strings_4.py +++ b/tests/main/clients/shorter_results/expected_client/list_strings_4.py @@ -7,3 +7,6 @@ class ListStrings4(BaseModel): list_string: List[str] = Field(alias="listString") + + +ListStrings4.model_rebuild() diff --git a/tests/main/clients/shorter_results/expected_client/list_type_a.py b/tests/main/clients/shorter_results/expected_client/list_type_a.py index e53cbd00..7694cb20 100644 --- a/tests/main/clients/shorter_results/expected_client/list_type_a.py +++ b/tests/main/clients/shorter_results/expected_client/list_type_a.py @@ -13,3 +13,7 @@ class ListTypeA(BaseModel): class ListTypeAListOptionalTypeA(BaseModel): id: int + + +ListTypeA.model_rebuild() +ListTypeAListOptionalTypeA.model_rebuild() diff --git a/tests/main/clients/shorter_results/expected_client/subscribe_strings.py b/tests/main/clients/shorter_results/expected_client/subscribe_strings.py index a1a42d4f..b1f6f337 100644 --- a/tests/main/clients/shorter_results/expected_client/subscribe_strings.py +++ b/tests/main/clients/shorter_results/expected_client/subscribe_strings.py @@ -7,3 +7,6 @@ class SubscribeStrings(BaseModel): optional_list_string: Optional[List[str]] = Field(alias="optionalListString") + + +SubscribeStrings.model_rebuild() diff --git a/tests/main/clients/shorter_results/expected_client/unwrap_fragment.py b/tests/main/clients/shorter_results/expected_client/unwrap_fragment.py index 82d63022..806f7f52 100644 --- a/tests/main/clients/shorter_results/expected_client/unwrap_fragment.py +++ b/tests/main/clients/shorter_results/expected_client/unwrap_fragment.py @@ -3,3 +3,6 @@ class UnwrapFragment(FragmentWithSingleField): pass + + +UnwrapFragment.model_rebuild() From 4f0a3a36f2cac72962a1edb2900e72e760420067 Mon Sep 17 00:00:00 2001 From: Minister944 Date: Fri, 23 Feb 2024 12:19:10 +0100 Subject: [PATCH 2/9] fix isort --- ariadne_codegen/client_generators/result_types.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ariadne_codegen/client_generators/result_types.py b/ariadne_codegen/client_generators/result_types.py index 697ee3f4..677c5078 100644 --- a/ariadne_codegen/client_generators/result_types.py +++ b/ariadne_codegen/client_generators/result_types.py @@ -34,12 +34,12 @@ generate_ann_assign, generate_class_def, generate_constant, + generate_expr, generate_import_from, + generate_method_call, generate_module, generate_pass, generate_pydantic_field, - generate_method_call, - generate_expr, ) from ..exceptions import NotSupported, ParsingError from ..plugins.manager import PluginManager @@ -57,13 +57,13 @@ MIXIN_FROM_NAME, MIXIN_IMPORT_NAME, MIXIN_NAME, + MODEL_REBUILD_METHOD, OPTIONAL, PYDANTIC_MODULE, TYPENAME_ALIAS, TYPENAME_FIELD_NAME, TYPING_MODULE, UNION, - MODEL_REBUILD_METHOD, ) from .result_fields import FieldContext, is_union, parse_operation_field from .scalars import ScalarData, generate_scalar_imports From 5b6cb6dba2965817b1c8a39a4fcd70ff93c1259b Mon Sep 17 00:00:00 2001 From: Minister944 Date: Mon, 26 Feb 2024 14:54:35 +0100 Subject: [PATCH 3/9] add a filter for rebuild calls --- ariadne_codegen/client_generators/result_types.py | 13 +++++++++---- .../expected_client/get_query_a.py | 1 - .../custom_config_file/expected_client/test.py | 3 --- .../expected_client/get_query_a.py | 1 - .../clients/custom_scalars/expected_client/get_a.py | 1 - .../clients/example/expected_client/create_user.py | 1 - .../example/expected_client/get_users_counter.py | 3 --- .../example/expected_client/list_all_users.py | 1 - .../expected_client/list_users_by_country.py | 1 - .../clients/example/expected_client/upload_file.py | 3 --- .../expected_client/fragments_with_mixins.py | 3 +-- .../extended_models/expected_client/get_query_a.py | 1 - .../expected_client/get_query_a_with_fragment.py | 3 --- .../extended_models/expected_client/get_query_b.py | 1 - .../query_with_fragment_on_sub_interface.py | 2 ++ ...ragment_on_sub_interface_with_inline_fragment.py | 2 ++ .../query_with_fragment_on_union_member.py | 1 + .../inline_fragments/expected_client/interface_a.py | 3 +++ .../inline_fragments/expected_client/interface_b.py | 3 +++ .../inline_fragments/expected_client/interface_c.py | 3 +++ .../expected_client/interface_with_typename.py | 3 +++ .../expected_client/list_interface.py | 3 +++ .../inline_fragments/expected_client/list_union.py | 2 ++ .../query_with_fragment_on_interface.py | 3 +++ .../query_with_fragment_on_query_with_interface.py | 3 --- .../query_with_fragment_on_query_with_union.py | 3 --- .../expected_client/query_with_fragment_on_union.py | 2 ++ .../inline_fragments/expected_client/union_a.py | 2 ++ .../inline_fragments/expected_client/union_b.py | 2 ++ .../expected_client/example_query_1.py | 1 - .../expected_client/example_query_2.py | 1 - .../expected_client/example_query_3.py | 1 - .../expected_client/get_a.py | 3 --- .../expected_client/get_a_2.py | 3 --- .../expected_client/get_b.py | 3 --- .../expected_client/get_d.py | 3 --- .../expected_client/get_e.py | 3 --- .../expected_client/get_f.py | 1 - .../expected_client/get_g.py | 1 - .../operations/expected_client/c_mutation.py | 3 --- .../clients/operations/expected_client/c_query.py | 3 --- .../operations/expected_client/c_subscription.py | 3 --- .../clients/operations/expected_client/get_a.py | 1 - .../expected_client/get_a_with_fragment.py | 1 - .../clients/operations/expected_client/get_s.py | 1 - .../clients/operations/expected_client/get_xyz.py | 2 ++ .../clients/remote_schema/expected_client/test.py | 3 --- .../expected_client/get_animal_by_name.py | 2 ++ .../get_animal_fragment_with_extra.py | 3 --- .../expected_client/get_authenticated_user.py | 1 - .../expected_client/get_complex_scalar.py | 3 --- .../expected_client/get_simple_scalar.py | 3 --- .../shorter_results/expected_client/list_animals.py | 2 ++ .../expected_client/list_strings_1.py | 3 --- .../expected_client/list_strings_2.py | 3 --- .../expected_client/list_strings_3.py | 3 --- .../expected_client/list_strings_4.py | 3 --- .../shorter_results/expected_client/list_type_a.py | 1 - .../expected_client/subscribe_strings.py | 3 --- .../expected_client/unwrap_fragment.py | 3 --- 60 files changed, 47 insertions(+), 96 deletions(-) diff --git a/ariadne_codegen/client_generators/result_types.py b/ariadne_codegen/client_generators/result_types.py index 677c5078..232a79da 100644 --- a/ariadne_codegen/client_generators/result_types.py +++ b/ariadne_codegen/client_generators/result_types.py @@ -155,10 +155,15 @@ def _get_operation_type_name(self, definition: ExecutableDefinitionNode) -> str: raise NotSupported(f"Not supported operation type: {definition}") def generate(self) -> ast.Module: - model_rebuild_calls = [ - generate_expr(generate_method_call(class_def.name, MODEL_REBUILD_METHOD)) - for class_def in self._class_defs - ] + model_rebuild_calls = [] + for class_def in self._class_defs: + for node in ast.walk(class_def): + if isinstance(node, ast.Name) and '"' in node.id: + call_expr = generate_expr( + generate_method_call(class_def.name, MODEL_REBUILD_METHOD) + ) + model_rebuild_calls.append(call_expr) + module_body = ( cast(List[ast.stmt], self._imports) + cast(List[ast.stmt], self._class_defs) diff --git a/tests/main/clients/custom_base_client/expected_client/get_query_a.py b/tests/main/clients/custom_base_client/expected_client/get_query_a.py index a577cb40..e6806e58 100644 --- a/tests/main/clients/custom_base_client/expected_client/get_query_a.py +++ b/tests/main/clients/custom_base_client/expected_client/get_query_a.py @@ -12,4 +12,3 @@ class GetQueryAQueryA(BaseModel): GetQueryA.model_rebuild() -GetQueryAQueryA.model_rebuild() diff --git a/tests/main/clients/custom_config_file/expected_client/test.py b/tests/main/clients/custom_config_file/expected_client/test.py index f44774b9..add3b3b6 100644 --- a/tests/main/clients/custom_config_file/expected_client/test.py +++ b/tests/main/clients/custom_config_file/expected_client/test.py @@ -5,6 +5,3 @@ class Test(BaseModel): test_query: str = Field(alias="testQuery") - - -Test.model_rebuild() diff --git a/tests/main/clients/custom_files_names/expected_client/get_query_a.py b/tests/main/clients/custom_files_names/expected_client/get_query_a.py index a577cb40..e6806e58 100644 --- a/tests/main/clients/custom_files_names/expected_client/get_query_a.py +++ b/tests/main/clients/custom_files_names/expected_client/get_query_a.py @@ -12,4 +12,3 @@ class GetQueryAQueryA(BaseModel): GetQueryA.model_rebuild() -GetQueryAQueryA.model_rebuild() diff --git a/tests/main/clients/custom_scalars/expected_client/get_a.py b/tests/main/clients/custom_scalars/expected_client/get_a.py index d1170bf0..aac01ee5 100644 --- a/tests/main/clients/custom_scalars/expected_client/get_a.py +++ b/tests/main/clients/custom_scalars/expected_client/get_a.py @@ -19,4 +19,3 @@ class GetATestQuery(BaseModel): GetA.model_rebuild() -GetATestQuery.model_rebuild() diff --git a/tests/main/clients/example/expected_client/create_user.py b/tests/main/clients/example/expected_client/create_user.py index 07d3a975..aefb94f0 100644 --- a/tests/main/clients/example/expected_client/create_user.py +++ b/tests/main/clients/example/expected_client/create_user.py @@ -14,4 +14,3 @@ class CreateUserUserCreate(BaseModel): CreateUser.model_rebuild() -CreateUserUserCreate.model_rebuild() diff --git a/tests/main/clients/example/expected_client/get_users_counter.py b/tests/main/clients/example/expected_client/get_users_counter.py index 1348b678..6dd3c72b 100644 --- a/tests/main/clients/example/expected_client/get_users_counter.py +++ b/tests/main/clients/example/expected_client/get_users_counter.py @@ -5,6 +5,3 @@ class GetUsersCounter(BaseModel): users_counter: int = Field(alias="usersCounter") - - -GetUsersCounter.model_rebuild() diff --git a/tests/main/clients/example/expected_client/list_all_users.py b/tests/main/clients/example/expected_client/list_all_users.py index 879f5081..0427e2e3 100644 --- a/tests/main/clients/example/expected_client/list_all_users.py +++ b/tests/main/clients/example/expected_client/list_all_users.py @@ -23,4 +23,3 @@ class ListAllUsersUsersLocation(BaseModel): ListAllUsers.model_rebuild() ListAllUsersUsers.model_rebuild() -ListAllUsersUsersLocation.model_rebuild() diff --git a/tests/main/clients/example/expected_client/list_users_by_country.py b/tests/main/clients/example/expected_client/list_users_by_country.py index 0fc7069f..ec3f18f1 100644 --- a/tests/main/clients/example/expected_client/list_users_by_country.py +++ b/tests/main/clients/example/expected_client/list_users_by_country.py @@ -16,4 +16,3 @@ class ListUsersByCountryUsers(BasicUser, UserPersonalData): ListUsersByCountry.model_rebuild() -ListUsersByCountryUsers.model_rebuild() diff --git a/tests/main/clients/example/expected_client/upload_file.py b/tests/main/clients/example/expected_client/upload_file.py index 42d32e4b..2afaaca3 100644 --- a/tests/main/clients/example/expected_client/upload_file.py +++ b/tests/main/clients/example/expected_client/upload_file.py @@ -5,6 +5,3 @@ class UploadFile(BaseModel): file_upload: bool = Field(alias="fileUpload") - - -UploadFile.model_rebuild() diff --git a/tests/main/clients/extended_models/expected_client/fragments_with_mixins.py b/tests/main/clients/extended_models/expected_client/fragments_with_mixins.py index e4677144..b5d9509a 100644 --- a/tests/main/clients/extended_models/expected_client/fragments_with_mixins.py +++ b/tests/main/clients/extended_models/expected_client/fragments_with_mixins.py @@ -19,5 +19,4 @@ class FragmentsWithMixinsQueryB(FragmentB, CommonMixin): FragmentsWithMixins.model_rebuild() -FragmentsWithMixinsQueryA.model_rebuild() -FragmentsWithMixinsQueryB.model_rebuild() +FragmentsWithMixins.model_rebuild() diff --git a/tests/main/clients/extended_models/expected_client/get_query_a.py b/tests/main/clients/extended_models/expected_client/get_query_a.py index 3e2cd5f5..4bf0e073 100644 --- a/tests/main/clients/extended_models/expected_client/get_query_a.py +++ b/tests/main/clients/extended_models/expected_client/get_query_a.py @@ -14,4 +14,3 @@ class GetQueryAQueryA(BaseModel, MixinA, CommonMixin): GetQueryA.model_rebuild() -GetQueryAQueryA.model_rebuild() diff --git a/tests/main/clients/extended_models/expected_client/get_query_a_with_fragment.py b/tests/main/clients/extended_models/expected_client/get_query_a_with_fragment.py index 1f390847..e8f4cebe 100644 --- a/tests/main/clients/extended_models/expected_client/get_query_a_with_fragment.py +++ b/tests/main/clients/extended_models/expected_client/get_query_a_with_fragment.py @@ -3,6 +3,3 @@ class GetQueryAWithFragment(GetQueryAFragment): pass - - -GetQueryAWithFragment.model_rebuild() diff --git a/tests/main/clients/extended_models/expected_client/get_query_b.py b/tests/main/clients/extended_models/expected_client/get_query_b.py index bc377611..968c548d 100644 --- a/tests/main/clients/extended_models/expected_client/get_query_b.py +++ b/tests/main/clients/extended_models/expected_client/get_query_b.py @@ -14,4 +14,3 @@ class GetQueryBQueryB(BaseModel, MixinB, CommonMixin): GetQueryB.model_rebuild() -GetQueryBQueryB.model_rebuild() diff --git a/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_sub_interface.py b/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_sub_interface.py index bf1d9b0f..7e249b23 100644 --- a/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_sub_interface.py +++ b/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_sub_interface.py @@ -22,5 +22,7 @@ class QueryWithFragmentOnSubInterfaceQueryInterfaceInterfaceA(FragmentA): QueryWithFragmentOnSubInterface.model_rebuild() +QueryWithFragmentOnSubInterface.model_rebuild() +QueryWithFragmentOnSubInterfaceQueryInterfaceBaseInterface.model_rebuild() QueryWithFragmentOnSubInterfaceQueryInterfaceBaseInterface.model_rebuild() QueryWithFragmentOnSubInterfaceQueryInterfaceInterfaceA.model_rebuild() diff --git a/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_sub_interface_with_inline_fragment.py b/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_sub_interface_with_inline_fragment.py index 7ac39fed..2afbda5c 100644 --- a/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_sub_interface_with_inline_fragment.py +++ b/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_sub_interface_with_inline_fragment.py @@ -34,6 +34,8 @@ class QueryWithFragmentOnSubInterfaceWithInlineFragmentQueryInterfaceTypeA(BaseM another: str +QueryWithFragmentOnSubInterfaceWithInlineFragment.model_rebuild() +QueryWithFragmentOnSubInterfaceWithInlineFragment.model_rebuild() QueryWithFragmentOnSubInterfaceWithInlineFragment.model_rebuild() QueryWithFragmentOnSubInterfaceWithInlineFragmentQueryInterfaceBaseInterface.model_rebuild() QueryWithFragmentOnSubInterfaceWithInlineFragmentQueryInterfaceInterfaceA.model_rebuild() diff --git a/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_union_member.py b/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_union_member.py index e84e11e4..1e54fa09 100644 --- a/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_union_member.py +++ b/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_union_member.py @@ -21,6 +21,7 @@ class QueryWithFragmentOnUnionMemberQueryUnionTypeB(FragmentB): typename__: Literal["TypeB"] = Field(alias="__typename") +QueryWithFragmentOnUnionMember.model_rebuild() QueryWithFragmentOnUnionMember.model_rebuild() QueryWithFragmentOnUnionMemberQueryUnionTypeA.model_rebuild() QueryWithFragmentOnUnionMemberQueryUnionTypeB.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/interface_a.py b/tests/main/clients/inline_fragments/expected_client/interface_a.py index adbd6d5b..1f33e0ed 100644 --- a/tests/main/clients/inline_fragments/expected_client/interface_a.py +++ b/tests/main/clients/inline_fragments/expected_client/interface_a.py @@ -29,6 +29,9 @@ class InterfaceAQueryITypeB(BaseModel): InterfaceA.model_rebuild() +InterfaceA.model_rebuild() +InterfaceA.model_rebuild() +InterfaceAQueryIInterface.model_rebuild() InterfaceAQueryIInterface.model_rebuild() InterfaceAQueryITypeA.model_rebuild() InterfaceAQueryITypeB.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/interface_b.py b/tests/main/clients/inline_fragments/expected_client/interface_b.py index cb599b73..7c44499b 100644 --- a/tests/main/clients/inline_fragments/expected_client/interface_b.py +++ b/tests/main/clients/inline_fragments/expected_client/interface_b.py @@ -23,5 +23,8 @@ class InterfaceBQueryITypeA(BaseModel): InterfaceB.model_rebuild() +InterfaceB.model_rebuild() +InterfaceBQueryIInterface.model_rebuild() +InterfaceBQueryIInterface.model_rebuild() InterfaceBQueryIInterface.model_rebuild() InterfaceBQueryITypeA.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/interface_c.py b/tests/main/clients/inline_fragments/expected_client/interface_c.py index e9b205d6..727f86d4 100644 --- a/tests/main/clients/inline_fragments/expected_client/interface_c.py +++ b/tests/main/clients/inline_fragments/expected_client/interface_c.py @@ -18,3 +18,6 @@ class InterfaceCQueryI(BaseModel): InterfaceC.model_rebuild() InterfaceCQueryI.model_rebuild() +InterfaceCQueryI.model_rebuild() +InterfaceCQueryI.model_rebuild() +InterfaceCQueryI.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/interface_with_typename.py b/tests/main/clients/inline_fragments/expected_client/interface_with_typename.py index d51fabe3..429c2065 100644 --- a/tests/main/clients/inline_fragments/expected_client/interface_with_typename.py +++ b/tests/main/clients/inline_fragments/expected_client/interface_with_typename.py @@ -18,3 +18,6 @@ class InterfaceWithTypenameQueryI(BaseModel): InterfaceWithTypename.model_rebuild() InterfaceWithTypenameQueryI.model_rebuild() +InterfaceWithTypenameQueryI.model_rebuild() +InterfaceWithTypenameQueryI.model_rebuild() +InterfaceWithTypenameQueryI.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/list_interface.py b/tests/main/clients/inline_fragments/expected_client/list_interface.py index ad9fde2d..7825e330 100644 --- a/tests/main/clients/inline_fragments/expected_client/list_interface.py +++ b/tests/main/clients/inline_fragments/expected_client/list_interface.py @@ -36,6 +36,9 @@ class ListInterfaceQueryListITypeB(BaseModel): ListInterface.model_rebuild() +ListInterface.model_rebuild() +ListInterface.model_rebuild() +ListInterfaceQueryListIInterface.model_rebuild() ListInterfaceQueryListIInterface.model_rebuild() ListInterfaceQueryListITypeA.model_rebuild() ListInterfaceQueryListITypeB.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/list_union.py b/tests/main/clients/inline_fragments/expected_client/list_union.py index fe2d6b3e..f6bc00fa 100644 --- a/tests/main/clients/inline_fragments/expected_client/list_union.py +++ b/tests/main/clients/inline_fragments/expected_client/list_union.py @@ -34,6 +34,8 @@ class ListUnionQueryListUTypeC(BaseModel): typename__: Literal["TypeC"] = Field(alias="__typename") +ListUnion.model_rebuild() +ListUnion.model_rebuild() ListUnion.model_rebuild() ListUnionQueryListUTypeA.model_rebuild() ListUnionQueryListUTypeB.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_interface.py b/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_interface.py index 7ba0e795..2d9fb54e 100644 --- a/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_interface.py +++ b/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_interface.py @@ -31,6 +31,9 @@ class QueryWithFragmentOnInterfaceQueryITypeB(BaseModel): QueryWithFragmentOnInterface.model_rebuild() +QueryWithFragmentOnInterface.model_rebuild() +QueryWithFragmentOnInterface.model_rebuild() +QueryWithFragmentOnInterfaceQueryIInterface.model_rebuild() QueryWithFragmentOnInterfaceQueryIInterface.model_rebuild() QueryWithFragmentOnInterfaceQueryITypeA.model_rebuild() QueryWithFragmentOnInterfaceQueryITypeB.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_query_with_interface.py b/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_query_with_interface.py index b2989694..c4705560 100644 --- a/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_query_with_interface.py +++ b/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_query_with_interface.py @@ -3,6 +3,3 @@ class QueryWithFragmentOnQueryWithInterface(FragmentOnQueryWithInterface): pass - - -QueryWithFragmentOnQueryWithInterface.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_query_with_union.py b/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_query_with_union.py index 94d1318e..1f2b1d54 100644 --- a/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_query_with_union.py +++ b/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_query_with_union.py @@ -3,6 +3,3 @@ class QueryWithFragmentOnQueryWithUnion(FragmentOnQueryWithUnion): pass - - -QueryWithFragmentOnQueryWithUnion.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_union.py b/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_union.py index 5057e490..f67ada57 100644 --- a/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_union.py +++ b/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_union.py @@ -29,6 +29,8 @@ class QueryWithFragmentOnUnionQueryUTypeC(BaseModel): typename__: Literal["TypeC"] = Field(alias="__typename") +QueryWithFragmentOnUnion.model_rebuild() +QueryWithFragmentOnUnion.model_rebuild() QueryWithFragmentOnUnion.model_rebuild() QueryWithFragmentOnUnionQueryUTypeA.model_rebuild() QueryWithFragmentOnUnionQueryUTypeB.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/union_a.py b/tests/main/clients/inline_fragments/expected_client/union_a.py index bc0cbd2e..ab440876 100644 --- a/tests/main/clients/inline_fragments/expected_client/union_a.py +++ b/tests/main/clients/inline_fragments/expected_client/union_a.py @@ -27,6 +27,8 @@ class UnionAQueryUTypeC(BaseModel): typename__: Literal["TypeC"] = Field(alias="__typename") +UnionA.model_rebuild() +UnionA.model_rebuild() UnionA.model_rebuild() UnionAQueryUTypeA.model_rebuild() UnionAQueryUTypeB.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/union_b.py b/tests/main/clients/inline_fragments/expected_client/union_b.py index 983f1239..362c0c56 100644 --- a/tests/main/clients/inline_fragments/expected_client/union_b.py +++ b/tests/main/clients/inline_fragments/expected_client/union_b.py @@ -25,6 +25,8 @@ class UnionBQueryUTypeC(BaseModel): typename__: Literal["TypeC"] = Field(alias="__typename") +UnionB.model_rebuild() +UnionB.model_rebuild() UnionB.model_rebuild() UnionBQueryUTypeA.model_rebuild() UnionBQueryUTypeB.model_rebuild() diff --git a/tests/main/clients/multiple_fragments/expected_client/example_query_1.py b/tests/main/clients/multiple_fragments/expected_client/example_query_1.py index 4a8e7935..6cfa755e 100644 --- a/tests/main/clients/multiple_fragments/expected_client/example_query_1.py +++ b/tests/main/clients/multiple_fragments/expected_client/example_query_1.py @@ -13,4 +13,3 @@ class ExampleQuery1ExampleQuery(MinimalA): ExampleQuery1.model_rebuild() -ExampleQuery1ExampleQuery.model_rebuild() diff --git a/tests/main/clients/multiple_fragments/expected_client/example_query_2.py b/tests/main/clients/multiple_fragments/expected_client/example_query_2.py index f874deee..8f82051f 100644 --- a/tests/main/clients/multiple_fragments/expected_client/example_query_2.py +++ b/tests/main/clients/multiple_fragments/expected_client/example_query_2.py @@ -13,4 +13,3 @@ class ExampleQuery2ExampleQuery(FullA): ExampleQuery2.model_rebuild() -ExampleQuery2ExampleQuery.model_rebuild() diff --git a/tests/main/clients/multiple_fragments/expected_client/example_query_3.py b/tests/main/clients/multiple_fragments/expected_client/example_query_3.py index 5e96b22b..d4ccc2ab 100644 --- a/tests/main/clients/multiple_fragments/expected_client/example_query_3.py +++ b/tests/main/clients/multiple_fragments/expected_client/example_query_3.py @@ -13,4 +13,3 @@ class ExampleQuery3ExampleQuery(CompleteA): ExampleQuery3.model_rebuild() -ExampleQuery3ExampleQuery.model_rebuild() diff --git a/tests/main/clients/only_used_inputs_and_enums/expected_client/get_a.py b/tests/main/clients/only_used_inputs_and_enums/expected_client/get_a.py index a5f6dea3..4aa89ddc 100644 --- a/tests/main/clients/only_used_inputs_and_enums/expected_client/get_a.py +++ b/tests/main/clients/only_used_inputs_and_enums/expected_client/get_a.py @@ -3,6 +3,3 @@ class GetA(BaseModel): a: str - - -GetA.model_rebuild() diff --git a/tests/main/clients/only_used_inputs_and_enums/expected_client/get_a_2.py b/tests/main/clients/only_used_inputs_and_enums/expected_client/get_a_2.py index aac160e3..1a9211e4 100644 --- a/tests/main/clients/only_used_inputs_and_enums/expected_client/get_a_2.py +++ b/tests/main/clients/only_used_inputs_and_enums/expected_client/get_a_2.py @@ -3,6 +3,3 @@ class GetA2(BaseModel): a: str - - -GetA2.model_rebuild() diff --git a/tests/main/clients/only_used_inputs_and_enums/expected_client/get_b.py b/tests/main/clients/only_used_inputs_and_enums/expected_client/get_b.py index 9de75751..d6d8adf8 100644 --- a/tests/main/clients/only_used_inputs_and_enums/expected_client/get_b.py +++ b/tests/main/clients/only_used_inputs_and_enums/expected_client/get_b.py @@ -3,6 +3,3 @@ class GetB(BaseModel): b: str - - -GetB.model_rebuild() diff --git a/tests/main/clients/only_used_inputs_and_enums/expected_client/get_d.py b/tests/main/clients/only_used_inputs_and_enums/expected_client/get_d.py index ad513404..cb77066b 100644 --- a/tests/main/clients/only_used_inputs_and_enums/expected_client/get_d.py +++ b/tests/main/clients/only_used_inputs_and_enums/expected_client/get_d.py @@ -3,6 +3,3 @@ class GetD(BaseModel): d: str - - -GetD.model_rebuild() diff --git a/tests/main/clients/only_used_inputs_and_enums/expected_client/get_e.py b/tests/main/clients/only_used_inputs_and_enums/expected_client/get_e.py index 659db1fd..30a4e661 100644 --- a/tests/main/clients/only_used_inputs_and_enums/expected_client/get_e.py +++ b/tests/main/clients/only_used_inputs_and_enums/expected_client/get_e.py @@ -3,6 +3,3 @@ class GetE(BaseModel): e: str - - -GetE.model_rebuild() diff --git a/tests/main/clients/only_used_inputs_and_enums/expected_client/get_f.py b/tests/main/clients/only_used_inputs_and_enums/expected_client/get_f.py index c0ddbd7e..9639064c 100644 --- a/tests/main/clients/only_used_inputs_and_enums/expected_client/get_f.py +++ b/tests/main/clients/only_used_inputs_and_enums/expected_client/get_f.py @@ -11,4 +11,3 @@ class GetFF(BaseModel): GetF.model_rebuild() -GetFF.model_rebuild() diff --git a/tests/main/clients/only_used_inputs_and_enums/expected_client/get_g.py b/tests/main/clients/only_used_inputs_and_enums/expected_client/get_g.py index e06cf16b..fb3434c5 100644 --- a/tests/main/clients/only_used_inputs_and_enums/expected_client/get_g.py +++ b/tests/main/clients/only_used_inputs_and_enums/expected_client/get_g.py @@ -11,4 +11,3 @@ class GetGG(FragmentG): GetG.model_rebuild() -GetGG.model_rebuild() diff --git a/tests/main/clients/operations/expected_client/c_mutation.py b/tests/main/clients/operations/expected_client/c_mutation.py index c54181ad..184a6e07 100644 --- a/tests/main/clients/operations/expected_client/c_mutation.py +++ b/tests/main/clients/operations/expected_client/c_mutation.py @@ -5,6 +5,3 @@ class CMutation(BaseModel): const_mutation: int = Field(alias="constMutation") - - -CMutation.model_rebuild() diff --git a/tests/main/clients/operations/expected_client/c_query.py b/tests/main/clients/operations/expected_client/c_query.py index 6e091385..99534708 100644 --- a/tests/main/clients/operations/expected_client/c_query.py +++ b/tests/main/clients/operations/expected_client/c_query.py @@ -5,6 +5,3 @@ class CQuery(BaseModel): const_query: str = Field(alias="constQuery") - - -CQuery.model_rebuild() diff --git a/tests/main/clients/operations/expected_client/c_subscription.py b/tests/main/clients/operations/expected_client/c_subscription.py index 1fb73975..2db7b506 100644 --- a/tests/main/clients/operations/expected_client/c_subscription.py +++ b/tests/main/clients/operations/expected_client/c_subscription.py @@ -5,6 +5,3 @@ class CSubscription(BaseModel): const_subscription: float = Field(alias="constSubscription") - - -CSubscription.model_rebuild() diff --git a/tests/main/clients/operations/expected_client/get_a.py b/tests/main/clients/operations/expected_client/get_a.py index e6fd0abe..7006c19a 100644 --- a/tests/main/clients/operations/expected_client/get_a.py +++ b/tests/main/clients/operations/expected_client/get_a.py @@ -18,4 +18,3 @@ class GetAAValueB(BaseModel): GetA.model_rebuild() GetAA.model_rebuild() -GetAAValueB.model_rebuild() diff --git a/tests/main/clients/operations/expected_client/get_a_with_fragment.py b/tests/main/clients/operations/expected_client/get_a_with_fragment.py index cc006f37..6b4abe51 100644 --- a/tests/main/clients/operations/expected_client/get_a_with_fragment.py +++ b/tests/main/clients/operations/expected_client/get_a_with_fragment.py @@ -19,4 +19,3 @@ class GetAWithFragmentAValueB(FragmentB): GetAWithFragment.model_rebuild() GetAWithFragmentA.model_rebuild() -GetAWithFragmentAValueB.model_rebuild() diff --git a/tests/main/clients/operations/expected_client/get_s.py b/tests/main/clients/operations/expected_client/get_s.py index 4aa1746f..b4360fce 100644 --- a/tests/main/clients/operations/expected_client/get_s.py +++ b/tests/main/clients/operations/expected_client/get_s.py @@ -10,4 +10,3 @@ class GetSS(BaseModel): GetS.model_rebuild() -GetSS.model_rebuild() diff --git a/tests/main/clients/operations/expected_client/get_xyz.py b/tests/main/clients/operations/expected_client/get_xyz.py index 2ca5da60..14ec7495 100644 --- a/tests/main/clients/operations/expected_client/get_xyz.py +++ b/tests/main/clients/operations/expected_client/get_xyz.py @@ -25,6 +25,8 @@ class GetXYZXyzTypeZ(BaseModel): typename__: Literal["TypeZ"] = Field(alias="__typename") +GetXYZ.model_rebuild() +GetXYZ.model_rebuild() GetXYZ.model_rebuild() GetXYZXyzTypeX.model_rebuild() GetXYZXyzTypeY.model_rebuild() diff --git a/tests/main/clients/remote_schema/expected_client/test.py b/tests/main/clients/remote_schema/expected_client/test.py index 71819d90..facaa9a9 100644 --- a/tests/main/clients/remote_schema/expected_client/test.py +++ b/tests/main/clients/remote_schema/expected_client/test.py @@ -7,6 +7,3 @@ class Test(BaseModel): test_query: Optional[int] = Field(alias="testQuery") - - -Test.model_rebuild() diff --git a/tests/main/clients/shorter_results/expected_client/get_animal_by_name.py b/tests/main/clients/shorter_results/expected_client/get_animal_by_name.py index 1da2cfa1..1b67f7e4 100644 --- a/tests/main/clients/shorter_results/expected_client/get_animal_by_name.py +++ b/tests/main/clients/shorter_results/expected_client/get_animal_by_name.py @@ -30,6 +30,8 @@ class GetAnimalByNameAnimalByNameDog(BaseModel): puppies: int +GetAnimalByName.model_rebuild() +GetAnimalByName.model_rebuild() GetAnimalByName.model_rebuild() GetAnimalByNameAnimalByNameAnimal.model_rebuild() GetAnimalByNameAnimalByNameCat.model_rebuild() diff --git a/tests/main/clients/shorter_results/expected_client/get_animal_fragment_with_extra.py b/tests/main/clients/shorter_results/expected_client/get_animal_fragment_with_extra.py index 3419f74c..f7412926 100644 --- a/tests/main/clients/shorter_results/expected_client/get_animal_fragment_with_extra.py +++ b/tests/main/clients/shorter_results/expected_client/get_animal_fragment_with_extra.py @@ -7,6 +7,3 @@ class GetAnimalFragmentWithExtra(ListAnimalsFragment): list_string: List[str] = Field(alias="listString") - - -GetAnimalFragmentWithExtra.model_rebuild() diff --git a/tests/main/clients/shorter_results/expected_client/get_authenticated_user.py b/tests/main/clients/shorter_results/expected_client/get_authenticated_user.py index f932f338..ce0e2cf7 100644 --- a/tests/main/clients/shorter_results/expected_client/get_authenticated_user.py +++ b/tests/main/clients/shorter_results/expected_client/get_authenticated_user.py @@ -11,4 +11,3 @@ class GetAuthenticatedUserMe(BaseModel): GetAuthenticatedUser.model_rebuild() -GetAuthenticatedUserMe.model_rebuild() diff --git a/tests/main/clients/shorter_results/expected_client/get_complex_scalar.py b/tests/main/clients/shorter_results/expected_client/get_complex_scalar.py index 0a14bb8b..78563772 100644 --- a/tests/main/clients/shorter_results/expected_client/get_complex_scalar.py +++ b/tests/main/clients/shorter_results/expected_client/get_complex_scalar.py @@ -10,6 +10,3 @@ class GetComplexScalar(BaseModel): just_complex_scalar: Annotated[ ComplexScalar, BeforeValidator(parse_complex_scalar) ] = Field(alias="justComplexScalar") - - -GetComplexScalar.model_rebuild() diff --git a/tests/main/clients/shorter_results/expected_client/get_simple_scalar.py b/tests/main/clients/shorter_results/expected_client/get_simple_scalar.py index 64a3e8bf..365f7eaa 100644 --- a/tests/main/clients/shorter_results/expected_client/get_simple_scalar.py +++ b/tests/main/clients/shorter_results/expected_client/get_simple_scalar.py @@ -6,6 +6,3 @@ class GetSimpleScalar(BaseModel): just_simple_scalar: SimpleScalar = Field(alias="justSimpleScalar") - - -GetSimpleScalar.model_rebuild() diff --git a/tests/main/clients/shorter_results/expected_client/list_animals.py b/tests/main/clients/shorter_results/expected_client/list_animals.py index b20ccda2..b770c667 100644 --- a/tests/main/clients/shorter_results/expected_client/list_animals.py +++ b/tests/main/clients/shorter_results/expected_client/list_animals.py @@ -35,6 +35,8 @@ class ListAnimalsListAnimalsDog(BaseModel): puppies: int +ListAnimals.model_rebuild() +ListAnimals.model_rebuild() ListAnimals.model_rebuild() ListAnimalsListAnimalsAnimal.model_rebuild() ListAnimalsListAnimalsCat.model_rebuild() diff --git a/tests/main/clients/shorter_results/expected_client/list_strings_1.py b/tests/main/clients/shorter_results/expected_client/list_strings_1.py index 030d52e3..fd8c06de 100644 --- a/tests/main/clients/shorter_results/expected_client/list_strings_1.py +++ b/tests/main/clients/shorter_results/expected_client/list_strings_1.py @@ -9,6 +9,3 @@ class ListStrings1(BaseModel): optional_list_optional_string: Optional[List[Optional[str]]] = Field( alias="optionalListOptionalString" ) - - -ListStrings1.model_rebuild() diff --git a/tests/main/clients/shorter_results/expected_client/list_strings_2.py b/tests/main/clients/shorter_results/expected_client/list_strings_2.py index c5dd179d..d91ec117 100644 --- a/tests/main/clients/shorter_results/expected_client/list_strings_2.py +++ b/tests/main/clients/shorter_results/expected_client/list_strings_2.py @@ -7,6 +7,3 @@ class ListStrings2(BaseModel): optional_list_string: Optional[List[str]] = Field(alias="optionalListString") - - -ListStrings2.model_rebuild() diff --git a/tests/main/clients/shorter_results/expected_client/list_strings_3.py b/tests/main/clients/shorter_results/expected_client/list_strings_3.py index 7ac7acdb..88f6e2cf 100644 --- a/tests/main/clients/shorter_results/expected_client/list_strings_3.py +++ b/tests/main/clients/shorter_results/expected_client/list_strings_3.py @@ -7,6 +7,3 @@ class ListStrings3(BaseModel): list_optional_string: List[Optional[str]] = Field(alias="listOptionalString") - - -ListStrings3.model_rebuild() diff --git a/tests/main/clients/shorter_results/expected_client/list_strings_4.py b/tests/main/clients/shorter_results/expected_client/list_strings_4.py index 692bc3dc..15872b23 100644 --- a/tests/main/clients/shorter_results/expected_client/list_strings_4.py +++ b/tests/main/clients/shorter_results/expected_client/list_strings_4.py @@ -7,6 +7,3 @@ class ListStrings4(BaseModel): list_string: List[str] = Field(alias="listString") - - -ListStrings4.model_rebuild() diff --git a/tests/main/clients/shorter_results/expected_client/list_type_a.py b/tests/main/clients/shorter_results/expected_client/list_type_a.py index 7694cb20..9e2c8f04 100644 --- a/tests/main/clients/shorter_results/expected_client/list_type_a.py +++ b/tests/main/clients/shorter_results/expected_client/list_type_a.py @@ -16,4 +16,3 @@ class ListTypeAListOptionalTypeA(BaseModel): ListTypeA.model_rebuild() -ListTypeAListOptionalTypeA.model_rebuild() diff --git a/tests/main/clients/shorter_results/expected_client/subscribe_strings.py b/tests/main/clients/shorter_results/expected_client/subscribe_strings.py index b1f6f337..a1a42d4f 100644 --- a/tests/main/clients/shorter_results/expected_client/subscribe_strings.py +++ b/tests/main/clients/shorter_results/expected_client/subscribe_strings.py @@ -7,6 +7,3 @@ class SubscribeStrings(BaseModel): optional_list_string: Optional[List[str]] = Field(alias="optionalListString") - - -SubscribeStrings.model_rebuild() diff --git a/tests/main/clients/shorter_results/expected_client/unwrap_fragment.py b/tests/main/clients/shorter_results/expected_client/unwrap_fragment.py index 806f7f52..82d63022 100644 --- a/tests/main/clients/shorter_results/expected_client/unwrap_fragment.py +++ b/tests/main/clients/shorter_results/expected_client/unwrap_fragment.py @@ -3,6 +3,3 @@ class UnwrapFragment(FragmentWithSingleField): pass - - -UnwrapFragment.model_rebuild() From 0d7a09972c6aba13f628ab8c8fdbbd438d6dd10f Mon Sep 17 00:00:00 2001 From: Minister944 Date: Mon, 26 Feb 2024 16:20:04 +0100 Subject: [PATCH 4/9] Refactor ResultTypesGenerator for clarity and maintainability --- .../client_generators/result_types.py | 23 ++++++++++++------- .../expected_client/fragments_with_mixins.py | 1 - .../query_with_fragment_on_sub_interface.py | 2 -- ...t_on_sub_interface_with_inline_fragment.py | 2 -- .../query_with_fragment_on_union_member.py | 1 - .../expected_client/interface_a.py | 3 --- .../expected_client/interface_b.py | 3 --- .../expected_client/interface_c.py | 3 --- .../interface_with_typename.py | 3 --- .../expected_client/list_interface.py | 3 --- .../expected_client/list_union.py | 2 -- .../query_with_fragment_on_interface.py | 3 --- .../query_with_fragment_on_union.py | 2 -- .../expected_client/union_a.py | 2 -- .../expected_client/union_b.py | 2 -- .../operations/expected_client/get_xyz.py | 2 -- .../expected_client/get_animal_by_name.py | 2 -- .../expected_client/list_animals.py | 2 -- 18 files changed, 15 insertions(+), 46 deletions(-) diff --git a/ariadne_codegen/client_generators/result_types.py b/ariadne_codegen/client_generators/result_types.py index 232a79da..398d5171 100644 --- a/ariadne_codegen/client_generators/result_types.py +++ b/ariadne_codegen/client_generators/result_types.py @@ -155,14 +155,11 @@ def _get_operation_type_name(self, definition: ExecutableDefinitionNode) -> str: raise NotSupported(f"Not supported operation type: {definition}") def generate(self) -> ast.Module: - model_rebuild_calls = [] - for class_def in self._class_defs: - for node in ast.walk(class_def): - if isinstance(node, ast.Name) and '"' in node.id: - call_expr = generate_expr( - generate_method_call(class_def.name, MODEL_REBUILD_METHOD) - ) - model_rebuild_calls.append(call_expr) + model_rebuild_calls = [ + generate_expr(generate_method_call(class_def.name, MODEL_REBUILD_METHOD)) + for class_def in self._class_defs + if self.include_model_rebuild(class_def) + ] module_body = ( cast(List[ast.stmt], self._imports) @@ -177,6 +174,16 @@ def generate(self) -> ast.Module: ) return module + def include_model_rebuild(self, class_def: ast.ClassDef) -> List[ast.Expr]: + model_rebuild_calls = [] + for node in ast.walk(class_def): + if isinstance(node, ast.Name) and '"' in node.id: + call_expr = generate_expr( + generate_method_call(class_def.name, MODEL_REBUILD_METHOD) + ) + model_rebuild_calls.append(call_expr) + return model_rebuild_calls + def get_imports(self) -> List[ast.ImportFrom]: return self._imports diff --git a/tests/main/clients/extended_models/expected_client/fragments_with_mixins.py b/tests/main/clients/extended_models/expected_client/fragments_with_mixins.py index b5d9509a..19bcfd0c 100644 --- a/tests/main/clients/extended_models/expected_client/fragments_with_mixins.py +++ b/tests/main/clients/extended_models/expected_client/fragments_with_mixins.py @@ -19,4 +19,3 @@ class FragmentsWithMixinsQueryB(FragmentB, CommonMixin): FragmentsWithMixins.model_rebuild() -FragmentsWithMixins.model_rebuild() diff --git a/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_sub_interface.py b/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_sub_interface.py index 7e249b23..bf1d9b0f 100644 --- a/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_sub_interface.py +++ b/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_sub_interface.py @@ -22,7 +22,5 @@ class QueryWithFragmentOnSubInterfaceQueryInterfaceInterfaceA(FragmentA): QueryWithFragmentOnSubInterface.model_rebuild() -QueryWithFragmentOnSubInterface.model_rebuild() -QueryWithFragmentOnSubInterfaceQueryInterfaceBaseInterface.model_rebuild() QueryWithFragmentOnSubInterfaceQueryInterfaceBaseInterface.model_rebuild() QueryWithFragmentOnSubInterfaceQueryInterfaceInterfaceA.model_rebuild() diff --git a/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_sub_interface_with_inline_fragment.py b/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_sub_interface_with_inline_fragment.py index 2afbda5c..7ac39fed 100644 --- a/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_sub_interface_with_inline_fragment.py +++ b/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_sub_interface_with_inline_fragment.py @@ -34,8 +34,6 @@ class QueryWithFragmentOnSubInterfaceWithInlineFragmentQueryInterfaceTypeA(BaseM another: str -QueryWithFragmentOnSubInterfaceWithInlineFragment.model_rebuild() -QueryWithFragmentOnSubInterfaceWithInlineFragment.model_rebuild() QueryWithFragmentOnSubInterfaceWithInlineFragment.model_rebuild() QueryWithFragmentOnSubInterfaceWithInlineFragmentQueryInterfaceBaseInterface.model_rebuild() QueryWithFragmentOnSubInterfaceWithInlineFragmentQueryInterfaceInterfaceA.model_rebuild() diff --git a/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_union_member.py b/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_union_member.py index 1e54fa09..e84e11e4 100644 --- a/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_union_member.py +++ b/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_union_member.py @@ -21,7 +21,6 @@ class QueryWithFragmentOnUnionMemberQueryUnionTypeB(FragmentB): typename__: Literal["TypeB"] = Field(alias="__typename") -QueryWithFragmentOnUnionMember.model_rebuild() QueryWithFragmentOnUnionMember.model_rebuild() QueryWithFragmentOnUnionMemberQueryUnionTypeA.model_rebuild() QueryWithFragmentOnUnionMemberQueryUnionTypeB.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/interface_a.py b/tests/main/clients/inline_fragments/expected_client/interface_a.py index 1f33e0ed..adbd6d5b 100644 --- a/tests/main/clients/inline_fragments/expected_client/interface_a.py +++ b/tests/main/clients/inline_fragments/expected_client/interface_a.py @@ -29,9 +29,6 @@ class InterfaceAQueryITypeB(BaseModel): InterfaceA.model_rebuild() -InterfaceA.model_rebuild() -InterfaceA.model_rebuild() -InterfaceAQueryIInterface.model_rebuild() InterfaceAQueryIInterface.model_rebuild() InterfaceAQueryITypeA.model_rebuild() InterfaceAQueryITypeB.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/interface_b.py b/tests/main/clients/inline_fragments/expected_client/interface_b.py index 7c44499b..cb599b73 100644 --- a/tests/main/clients/inline_fragments/expected_client/interface_b.py +++ b/tests/main/clients/inline_fragments/expected_client/interface_b.py @@ -23,8 +23,5 @@ class InterfaceBQueryITypeA(BaseModel): InterfaceB.model_rebuild() -InterfaceB.model_rebuild() -InterfaceBQueryIInterface.model_rebuild() -InterfaceBQueryIInterface.model_rebuild() InterfaceBQueryIInterface.model_rebuild() InterfaceBQueryITypeA.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/interface_c.py b/tests/main/clients/inline_fragments/expected_client/interface_c.py index 727f86d4..e9b205d6 100644 --- a/tests/main/clients/inline_fragments/expected_client/interface_c.py +++ b/tests/main/clients/inline_fragments/expected_client/interface_c.py @@ -18,6 +18,3 @@ class InterfaceCQueryI(BaseModel): InterfaceC.model_rebuild() InterfaceCQueryI.model_rebuild() -InterfaceCQueryI.model_rebuild() -InterfaceCQueryI.model_rebuild() -InterfaceCQueryI.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/interface_with_typename.py b/tests/main/clients/inline_fragments/expected_client/interface_with_typename.py index 429c2065..d51fabe3 100644 --- a/tests/main/clients/inline_fragments/expected_client/interface_with_typename.py +++ b/tests/main/clients/inline_fragments/expected_client/interface_with_typename.py @@ -18,6 +18,3 @@ class InterfaceWithTypenameQueryI(BaseModel): InterfaceWithTypename.model_rebuild() InterfaceWithTypenameQueryI.model_rebuild() -InterfaceWithTypenameQueryI.model_rebuild() -InterfaceWithTypenameQueryI.model_rebuild() -InterfaceWithTypenameQueryI.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/list_interface.py b/tests/main/clients/inline_fragments/expected_client/list_interface.py index 7825e330..ad9fde2d 100644 --- a/tests/main/clients/inline_fragments/expected_client/list_interface.py +++ b/tests/main/clients/inline_fragments/expected_client/list_interface.py @@ -36,9 +36,6 @@ class ListInterfaceQueryListITypeB(BaseModel): ListInterface.model_rebuild() -ListInterface.model_rebuild() -ListInterface.model_rebuild() -ListInterfaceQueryListIInterface.model_rebuild() ListInterfaceQueryListIInterface.model_rebuild() ListInterfaceQueryListITypeA.model_rebuild() ListInterfaceQueryListITypeB.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/list_union.py b/tests/main/clients/inline_fragments/expected_client/list_union.py index f6bc00fa..fe2d6b3e 100644 --- a/tests/main/clients/inline_fragments/expected_client/list_union.py +++ b/tests/main/clients/inline_fragments/expected_client/list_union.py @@ -34,8 +34,6 @@ class ListUnionQueryListUTypeC(BaseModel): typename__: Literal["TypeC"] = Field(alias="__typename") -ListUnion.model_rebuild() -ListUnion.model_rebuild() ListUnion.model_rebuild() ListUnionQueryListUTypeA.model_rebuild() ListUnionQueryListUTypeB.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_interface.py b/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_interface.py index 2d9fb54e..7ba0e795 100644 --- a/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_interface.py +++ b/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_interface.py @@ -31,9 +31,6 @@ class QueryWithFragmentOnInterfaceQueryITypeB(BaseModel): QueryWithFragmentOnInterface.model_rebuild() -QueryWithFragmentOnInterface.model_rebuild() -QueryWithFragmentOnInterface.model_rebuild() -QueryWithFragmentOnInterfaceQueryIInterface.model_rebuild() QueryWithFragmentOnInterfaceQueryIInterface.model_rebuild() QueryWithFragmentOnInterfaceQueryITypeA.model_rebuild() QueryWithFragmentOnInterfaceQueryITypeB.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_union.py b/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_union.py index f67ada57..5057e490 100644 --- a/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_union.py +++ b/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_union.py @@ -29,8 +29,6 @@ class QueryWithFragmentOnUnionQueryUTypeC(BaseModel): typename__: Literal["TypeC"] = Field(alias="__typename") -QueryWithFragmentOnUnion.model_rebuild() -QueryWithFragmentOnUnion.model_rebuild() QueryWithFragmentOnUnion.model_rebuild() QueryWithFragmentOnUnionQueryUTypeA.model_rebuild() QueryWithFragmentOnUnionQueryUTypeB.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/union_a.py b/tests/main/clients/inline_fragments/expected_client/union_a.py index ab440876..bc0cbd2e 100644 --- a/tests/main/clients/inline_fragments/expected_client/union_a.py +++ b/tests/main/clients/inline_fragments/expected_client/union_a.py @@ -27,8 +27,6 @@ class UnionAQueryUTypeC(BaseModel): typename__: Literal["TypeC"] = Field(alias="__typename") -UnionA.model_rebuild() -UnionA.model_rebuild() UnionA.model_rebuild() UnionAQueryUTypeA.model_rebuild() UnionAQueryUTypeB.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/union_b.py b/tests/main/clients/inline_fragments/expected_client/union_b.py index 362c0c56..983f1239 100644 --- a/tests/main/clients/inline_fragments/expected_client/union_b.py +++ b/tests/main/clients/inline_fragments/expected_client/union_b.py @@ -25,8 +25,6 @@ class UnionBQueryUTypeC(BaseModel): typename__: Literal["TypeC"] = Field(alias="__typename") -UnionB.model_rebuild() -UnionB.model_rebuild() UnionB.model_rebuild() UnionBQueryUTypeA.model_rebuild() UnionBQueryUTypeB.model_rebuild() diff --git a/tests/main/clients/operations/expected_client/get_xyz.py b/tests/main/clients/operations/expected_client/get_xyz.py index 14ec7495..2ca5da60 100644 --- a/tests/main/clients/operations/expected_client/get_xyz.py +++ b/tests/main/clients/operations/expected_client/get_xyz.py @@ -25,8 +25,6 @@ class GetXYZXyzTypeZ(BaseModel): typename__: Literal["TypeZ"] = Field(alias="__typename") -GetXYZ.model_rebuild() -GetXYZ.model_rebuild() GetXYZ.model_rebuild() GetXYZXyzTypeX.model_rebuild() GetXYZXyzTypeY.model_rebuild() diff --git a/tests/main/clients/shorter_results/expected_client/get_animal_by_name.py b/tests/main/clients/shorter_results/expected_client/get_animal_by_name.py index 1b67f7e4..1da2cfa1 100644 --- a/tests/main/clients/shorter_results/expected_client/get_animal_by_name.py +++ b/tests/main/clients/shorter_results/expected_client/get_animal_by_name.py @@ -30,8 +30,6 @@ class GetAnimalByNameAnimalByNameDog(BaseModel): puppies: int -GetAnimalByName.model_rebuild() -GetAnimalByName.model_rebuild() GetAnimalByName.model_rebuild() GetAnimalByNameAnimalByNameAnimal.model_rebuild() GetAnimalByNameAnimalByNameCat.model_rebuild() diff --git a/tests/main/clients/shorter_results/expected_client/list_animals.py b/tests/main/clients/shorter_results/expected_client/list_animals.py index b770c667..b20ccda2 100644 --- a/tests/main/clients/shorter_results/expected_client/list_animals.py +++ b/tests/main/clients/shorter_results/expected_client/list_animals.py @@ -35,8 +35,6 @@ class ListAnimalsListAnimalsDog(BaseModel): puppies: int -ListAnimals.model_rebuild() -ListAnimals.model_rebuild() ListAnimals.model_rebuild() ListAnimalsListAnimalsAnimal.model_rebuild() ListAnimalsListAnimalsCat.model_rebuild() From 8703ea898e4277284aae93feae5d8044d8bfffff Mon Sep 17 00:00:00 2001 From: Minister944 Date: Mon, 26 Feb 2024 16:25:18 +0100 Subject: [PATCH 5/9] Refactor include_model_rebuild for improved readability --- ariadne_codegen/client_generators/result_types.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/ariadne_codegen/client_generators/result_types.py b/ariadne_codegen/client_generators/result_types.py index 398d5171..a8dbb241 100644 --- a/ariadne_codegen/client_generators/result_types.py +++ b/ariadne_codegen/client_generators/result_types.py @@ -174,15 +174,11 @@ def generate(self) -> ast.Module: ) return module - def include_model_rebuild(self, class_def: ast.ClassDef) -> List[ast.Expr]: - model_rebuild_calls = [] + def include_model_rebuild(self, class_def: ast.ClassDef) -> bool: for node in ast.walk(class_def): if isinstance(node, ast.Name) and '"' in node.id: - call_expr = generate_expr( - generate_method_call(class_def.name, MODEL_REBUILD_METHOD) - ) - model_rebuild_calls.append(call_expr) - return model_rebuild_calls + return True + return False def get_imports(self) -> List[ast.ImportFrom]: return self._imports From 3b20eff2c7c84052498f4f5224ea7a914750230d Mon Sep 17 00:00:00 2001 From: Minister944 Date: Tue, 27 Feb 2024 11:18:51 +0100 Subject: [PATCH 6/9] add ast.NodeVisitor to include_model_rebuild --- .../client_generators/result_types.py | 21 +++++++++++++++---- .../query_with_fragment_on_sub_interface.py | 2 -- ...t_on_sub_interface_with_inline_fragment.py | 3 --- .../query_with_fragment_on_union_member.py | 2 -- .../expected_client/interface_a.py | 3 --- .../expected_client/interface_b.py | 2 -- .../expected_client/interface_c.py | 1 - .../interface_with_typename.py | 1 - .../expected_client/list_interface.py | 3 --- .../expected_client/list_union.py | 3 --- .../query_with_fragment_on_interface.py | 3 --- .../query_with_fragment_on_union.py | 3 --- .../expected_client/union_a.py | 3 --- .../expected_client/union_b.py | 3 --- .../operations/expected_client/get_xyz.py | 3 --- .../expected_client/get_animal_by_name.py | 3 --- .../expected_client/list_animals.py | 3 --- 17 files changed, 17 insertions(+), 45 deletions(-) diff --git a/ariadne_codegen/client_generators/result_types.py b/ariadne_codegen/client_generators/result_types.py index a8dbb241..874b0e3a 100644 --- a/ariadne_codegen/client_generators/result_types.py +++ b/ariadne_codegen/client_generators/result_types.py @@ -175,10 +175,23 @@ def generate(self) -> ast.Module: return module def include_model_rebuild(self, class_def: ast.ClassDef) -> bool: - for node in ast.walk(class_def): - if isinstance(node, ast.Name) and '"' in node.id: - return True - return False + class NameVisitor(ast.NodeVisitor): + def __init__(self): + self.found_name_with_quote = False + + def visit_Name(self, node): + if '"' in node.id: + self.found_name_with_quote = True + self.generic_visit(node) + + def visit_Subscript(self, node): + if isinstance(node.value, ast.Name) and node.value.id == "Literal": + return + self.generic_visit(node) + + visitor = NameVisitor() + visitor.visit(class_def) + return visitor.found_name_with_quote def get_imports(self) -> List[ast.ImportFrom]: return self._imports diff --git a/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_sub_interface.py b/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_sub_interface.py index bf1d9b0f..1dfe885a 100644 --- a/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_sub_interface.py +++ b/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_sub_interface.py @@ -22,5 +22,3 @@ class QueryWithFragmentOnSubInterfaceQueryInterfaceInterfaceA(FragmentA): QueryWithFragmentOnSubInterface.model_rebuild() -QueryWithFragmentOnSubInterfaceQueryInterfaceBaseInterface.model_rebuild() -QueryWithFragmentOnSubInterfaceQueryInterfaceInterfaceA.model_rebuild() diff --git a/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_sub_interface_with_inline_fragment.py b/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_sub_interface_with_inline_fragment.py index 7ac39fed..6c587c08 100644 --- a/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_sub_interface_with_inline_fragment.py +++ b/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_sub_interface_with_inline_fragment.py @@ -35,6 +35,3 @@ class QueryWithFragmentOnSubInterfaceWithInlineFragmentQueryInterfaceTypeA(BaseM QueryWithFragmentOnSubInterfaceWithInlineFragment.model_rebuild() -QueryWithFragmentOnSubInterfaceWithInlineFragmentQueryInterfaceBaseInterface.model_rebuild() -QueryWithFragmentOnSubInterfaceWithInlineFragmentQueryInterfaceInterfaceA.model_rebuild() -QueryWithFragmentOnSubInterfaceWithInlineFragmentQueryInterfaceTypeA.model_rebuild() diff --git a/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_union_member.py b/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_union_member.py index e84e11e4..06d1fcb2 100644 --- a/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_union_member.py +++ b/tests/main/clients/fragments_on_abstract_types/expected_client/query_with_fragment_on_union_member.py @@ -22,5 +22,3 @@ class QueryWithFragmentOnUnionMemberQueryUnionTypeB(FragmentB): QueryWithFragmentOnUnionMember.model_rebuild() -QueryWithFragmentOnUnionMemberQueryUnionTypeA.model_rebuild() -QueryWithFragmentOnUnionMemberQueryUnionTypeB.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/interface_a.py b/tests/main/clients/inline_fragments/expected_client/interface_a.py index adbd6d5b..b5201480 100644 --- a/tests/main/clients/inline_fragments/expected_client/interface_a.py +++ b/tests/main/clients/inline_fragments/expected_client/interface_a.py @@ -29,6 +29,3 @@ class InterfaceAQueryITypeB(BaseModel): InterfaceA.model_rebuild() -InterfaceAQueryIInterface.model_rebuild() -InterfaceAQueryITypeA.model_rebuild() -InterfaceAQueryITypeB.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/interface_b.py b/tests/main/clients/inline_fragments/expected_client/interface_b.py index cb599b73..c6216857 100644 --- a/tests/main/clients/inline_fragments/expected_client/interface_b.py +++ b/tests/main/clients/inline_fragments/expected_client/interface_b.py @@ -23,5 +23,3 @@ class InterfaceBQueryITypeA(BaseModel): InterfaceB.model_rebuild() -InterfaceBQueryIInterface.model_rebuild() -InterfaceBQueryITypeA.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/interface_c.py b/tests/main/clients/inline_fragments/expected_client/interface_c.py index e9b205d6..3e7cdff3 100644 --- a/tests/main/clients/inline_fragments/expected_client/interface_c.py +++ b/tests/main/clients/inline_fragments/expected_client/interface_c.py @@ -17,4 +17,3 @@ class InterfaceCQueryI(BaseModel): InterfaceC.model_rebuild() -InterfaceCQueryI.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/interface_with_typename.py b/tests/main/clients/inline_fragments/expected_client/interface_with_typename.py index d51fabe3..91dbc66c 100644 --- a/tests/main/clients/inline_fragments/expected_client/interface_with_typename.py +++ b/tests/main/clients/inline_fragments/expected_client/interface_with_typename.py @@ -17,4 +17,3 @@ class InterfaceWithTypenameQueryI(BaseModel): InterfaceWithTypename.model_rebuild() -InterfaceWithTypenameQueryI.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/list_interface.py b/tests/main/clients/inline_fragments/expected_client/list_interface.py index ad9fde2d..4f43ddab 100644 --- a/tests/main/clients/inline_fragments/expected_client/list_interface.py +++ b/tests/main/clients/inline_fragments/expected_client/list_interface.py @@ -36,6 +36,3 @@ class ListInterfaceQueryListITypeB(BaseModel): ListInterface.model_rebuild() -ListInterfaceQueryListIInterface.model_rebuild() -ListInterfaceQueryListITypeA.model_rebuild() -ListInterfaceQueryListITypeB.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/list_union.py b/tests/main/clients/inline_fragments/expected_client/list_union.py index fe2d6b3e..678a912f 100644 --- a/tests/main/clients/inline_fragments/expected_client/list_union.py +++ b/tests/main/clients/inline_fragments/expected_client/list_union.py @@ -35,6 +35,3 @@ class ListUnionQueryListUTypeC(BaseModel): ListUnion.model_rebuild() -ListUnionQueryListUTypeA.model_rebuild() -ListUnionQueryListUTypeB.model_rebuild() -ListUnionQueryListUTypeC.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_interface.py b/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_interface.py index 7ba0e795..4757f397 100644 --- a/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_interface.py +++ b/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_interface.py @@ -31,6 +31,3 @@ class QueryWithFragmentOnInterfaceQueryITypeB(BaseModel): QueryWithFragmentOnInterface.model_rebuild() -QueryWithFragmentOnInterfaceQueryIInterface.model_rebuild() -QueryWithFragmentOnInterfaceQueryITypeA.model_rebuild() -QueryWithFragmentOnInterfaceQueryITypeB.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_union.py b/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_union.py index 5057e490..f682c2be 100644 --- a/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_union.py +++ b/tests/main/clients/inline_fragments/expected_client/query_with_fragment_on_union.py @@ -30,6 +30,3 @@ class QueryWithFragmentOnUnionQueryUTypeC(BaseModel): QueryWithFragmentOnUnion.model_rebuild() -QueryWithFragmentOnUnionQueryUTypeA.model_rebuild() -QueryWithFragmentOnUnionQueryUTypeB.model_rebuild() -QueryWithFragmentOnUnionQueryUTypeC.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/union_a.py b/tests/main/clients/inline_fragments/expected_client/union_a.py index bc0cbd2e..c501f23f 100644 --- a/tests/main/clients/inline_fragments/expected_client/union_a.py +++ b/tests/main/clients/inline_fragments/expected_client/union_a.py @@ -28,6 +28,3 @@ class UnionAQueryUTypeC(BaseModel): UnionA.model_rebuild() -UnionAQueryUTypeA.model_rebuild() -UnionAQueryUTypeB.model_rebuild() -UnionAQueryUTypeC.model_rebuild() diff --git a/tests/main/clients/inline_fragments/expected_client/union_b.py b/tests/main/clients/inline_fragments/expected_client/union_b.py index 983f1239..b012085c 100644 --- a/tests/main/clients/inline_fragments/expected_client/union_b.py +++ b/tests/main/clients/inline_fragments/expected_client/union_b.py @@ -26,6 +26,3 @@ class UnionBQueryUTypeC(BaseModel): UnionB.model_rebuild() -UnionBQueryUTypeA.model_rebuild() -UnionBQueryUTypeB.model_rebuild() -UnionBQueryUTypeC.model_rebuild() diff --git a/tests/main/clients/operations/expected_client/get_xyz.py b/tests/main/clients/operations/expected_client/get_xyz.py index 2ca5da60..dee88334 100644 --- a/tests/main/clients/operations/expected_client/get_xyz.py +++ b/tests/main/clients/operations/expected_client/get_xyz.py @@ -26,6 +26,3 @@ class GetXYZXyzTypeZ(BaseModel): GetXYZ.model_rebuild() -GetXYZXyzTypeX.model_rebuild() -GetXYZXyzTypeY.model_rebuild() -GetXYZXyzTypeZ.model_rebuild() diff --git a/tests/main/clients/shorter_results/expected_client/get_animal_by_name.py b/tests/main/clients/shorter_results/expected_client/get_animal_by_name.py index 1da2cfa1..e97e12ac 100644 --- a/tests/main/clients/shorter_results/expected_client/get_animal_by_name.py +++ b/tests/main/clients/shorter_results/expected_client/get_animal_by_name.py @@ -31,6 +31,3 @@ class GetAnimalByNameAnimalByNameDog(BaseModel): GetAnimalByName.model_rebuild() -GetAnimalByNameAnimalByNameAnimal.model_rebuild() -GetAnimalByNameAnimalByNameCat.model_rebuild() -GetAnimalByNameAnimalByNameDog.model_rebuild() diff --git a/tests/main/clients/shorter_results/expected_client/list_animals.py b/tests/main/clients/shorter_results/expected_client/list_animals.py index b20ccda2..bcab1c45 100644 --- a/tests/main/clients/shorter_results/expected_client/list_animals.py +++ b/tests/main/clients/shorter_results/expected_client/list_animals.py @@ -36,6 +36,3 @@ class ListAnimalsListAnimalsDog(BaseModel): ListAnimals.model_rebuild() -ListAnimalsListAnimalsAnimal.model_rebuild() -ListAnimalsListAnimalsCat.model_rebuild() -ListAnimalsListAnimalsDog.model_rebuild() From ac92bd1f7d818d5cde79e389318d1761787e29f4 Mon Sep 17 00:00:00 2001 From: Minister944 Date: Tue, 27 Feb 2024 11:28:21 +0100 Subject: [PATCH 7/9] disable=C0103 --- ariadne_codegen/client_generators/result_types.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ariadne_codegen/client_generators/result_types.py b/ariadne_codegen/client_generators/result_types.py index 874b0e3a..2d86e2eb 100644 --- a/ariadne_codegen/client_generators/result_types.py +++ b/ariadne_codegen/client_generators/result_types.py @@ -179,14 +179,15 @@ class NameVisitor(ast.NodeVisitor): def __init__(self): self.found_name_with_quote = False - def visit_Name(self, node): + def visit_Name(self, node): # pylint: disable=C0103 if '"' in node.id: self.found_name_with_quote = True self.generic_visit(node) - def visit_Subscript(self, node): + def visit_Subscript(self, node): # pylint: disable=C0103 if isinstance(node.value, ast.Name) and node.value.id == "Literal": return + self.generic_visit(node) visitor = NameVisitor() From d59f72949304951d803cd820a8ebfc62af7db855 Mon Sep 17 00:00:00 2001 From: Minister944 Date: Tue, 27 Feb 2024 12:16:02 +0100 Subject: [PATCH 8/9] refactore code --- .../client_generators/result_types.py | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/ariadne_codegen/client_generators/result_types.py b/ariadne_codegen/client_generators/result_types.py index 2d86e2eb..0a64d74b 100644 --- a/ariadne_codegen/client_generators/result_types.py +++ b/ariadne_codegen/client_generators/result_types.py @@ -175,21 +175,6 @@ def generate(self) -> ast.Module: return module def include_model_rebuild(self, class_def: ast.ClassDef) -> bool: - class NameVisitor(ast.NodeVisitor): - def __init__(self): - self.found_name_with_quote = False - - def visit_Name(self, node): # pylint: disable=C0103 - if '"' in node.id: - self.found_name_with_quote = True - self.generic_visit(node) - - def visit_Subscript(self, node): # pylint: disable=C0103 - if isinstance(node.value, ast.Name) and node.value.id == "Literal": - return - - self.generic_visit(node) - visitor = NameVisitor() visitor.visit(class_def) return visitor.found_name_with_quote @@ -591,3 +576,19 @@ def enter_field(node: FieldNode, *_args: Any) -> FieldNode: copied_node = deepcopy(node) visit(copied_node, RemoveMixinVisitor()) return copied_node + + +class NameVisitor(ast.NodeVisitor): + def __init__(self): + self.found_name_with_quote = False + + def visit_Name(self, node): # pylint: disable=C0103 + if '"' in node.id: + self.found_name_with_quote = True + self.generic_visit(node) + + def visit_Subscript(self, node): # pylint: disable=C0103 + if isinstance(node.value, ast.Name) and node.value.id == "Literal": + return + + self.generic_visit(node) From 6cf3077ad56cee8761574a69f765d6a61713f467 Mon Sep 17 00:00:00 2001 From: Minister944 Date: Tue, 27 Feb 2024 16:52:56 +0100 Subject: [PATCH 9/9] rename class --- ariadne_codegen/client_generators/result_types.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ariadne_codegen/client_generators/result_types.py b/ariadne_codegen/client_generators/result_types.py index 0a64d74b..6820e5a3 100644 --- a/ariadne_codegen/client_generators/result_types.py +++ b/ariadne_codegen/client_generators/result_types.py @@ -175,7 +175,7 @@ def generate(self) -> ast.Module: return module def include_model_rebuild(self, class_def: ast.ClassDef) -> bool: - visitor = NameVisitor() + visitor = ClassDefNamesVisitor() visitor.visit(class_def) return visitor.found_name_with_quote @@ -578,7 +578,7 @@ def enter_field(node: FieldNode, *_args: Any) -> FieldNode: return copied_node -class NameVisitor(ast.NodeVisitor): +class ClassDefNamesVisitor(ast.NodeVisitor): def __init__(self): self.found_name_with_quote = False