Skip to content

Commit

Permalink
add a filter for rebuild calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Minister944 committed Feb 26, 2024
1 parent 4f0a3a3 commit 5b6cb6d
Show file tree
Hide file tree
Showing 60 changed files with 47 additions and 96 deletions.
13 changes: 9 additions & 4 deletions ariadne_codegen/client_generators/result_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ class GetQueryAQueryA(BaseModel):


GetQueryA.model_rebuild()
GetQueryAQueryA.model_rebuild()
3 changes: 0 additions & 3 deletions tests/main/clients/custom_config_file/expected_client/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,3 @@

class Test(BaseModel):
test_query: str = Field(alias="testQuery")


Test.model_rebuild()
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ class GetQueryAQueryA(BaseModel):


GetQueryA.model_rebuild()
GetQueryAQueryA.model_rebuild()
1 change: 0 additions & 1 deletion tests/main/clients/custom_scalars/expected_client/get_a.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ class GetATestQuery(BaseModel):


GetA.model_rebuild()
GetATestQuery.model_rebuild()
1 change: 0 additions & 1 deletion tests/main/clients/example/expected_client/create_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ class CreateUserUserCreate(BaseModel):


CreateUser.model_rebuild()
CreateUserUserCreate.model_rebuild()
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,3 @@

class GetUsersCounter(BaseModel):
users_counter: int = Field(alias="usersCounter")


GetUsersCounter.model_rebuild()
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@ class ListAllUsersUsersLocation(BaseModel):

ListAllUsers.model_rebuild()
ListAllUsersUsers.model_rebuild()
ListAllUsersUsersLocation.model_rebuild()
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@ class ListUsersByCountryUsers(BasicUser, UserPersonalData):


ListUsersByCountry.model_rebuild()
ListUsersByCountryUsers.model_rebuild()
3 changes: 0 additions & 3 deletions tests/main/clients/example/expected_client/upload_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,3 @@

class UploadFile(BaseModel):
file_upload: bool = Field(alias="fileUpload")


UploadFile.model_rebuild()
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ class FragmentsWithMixinsQueryB(FragmentB, CommonMixin):


FragmentsWithMixins.model_rebuild()
FragmentsWithMixinsQueryA.model_rebuild()
FragmentsWithMixinsQueryB.model_rebuild()
FragmentsWithMixins.model_rebuild()
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ class GetQueryAQueryA(BaseModel, MixinA, CommonMixin):


GetQueryA.model_rebuild()
GetQueryAQueryA.model_rebuild()
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,3 @@

class GetQueryAWithFragment(GetQueryAFragment):
pass


GetQueryAWithFragment.model_rebuild()
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ class GetQueryBQueryB(BaseModel, MixinB, CommonMixin):


GetQueryB.model_rebuild()
GetQueryBQueryB.model_rebuild()
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ class QueryWithFragmentOnSubInterfaceQueryInterfaceInterfaceA(FragmentA):


QueryWithFragmentOnSubInterface.model_rebuild()
QueryWithFragmentOnSubInterface.model_rebuild()
QueryWithFragmentOnSubInterfaceQueryInterfaceBaseInterface.model_rebuild()
QueryWithFragmentOnSubInterfaceQueryInterfaceBaseInterface.model_rebuild()
QueryWithFragmentOnSubInterfaceQueryInterfaceInterfaceA.model_rebuild()
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class QueryWithFragmentOnSubInterfaceWithInlineFragmentQueryInterfaceTypeA(BaseM
another: str


QueryWithFragmentOnSubInterfaceWithInlineFragment.model_rebuild()
QueryWithFragmentOnSubInterfaceWithInlineFragment.model_rebuild()
QueryWithFragmentOnSubInterfaceWithInlineFragment.model_rebuild()
QueryWithFragmentOnSubInterfaceWithInlineFragmentQueryInterfaceBaseInterface.model_rebuild()
QueryWithFragmentOnSubInterfaceWithInlineFragmentQueryInterfaceInterfaceA.model_rebuild()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ class InterfaceCQueryI(BaseModel):

InterfaceC.model_rebuild()
InterfaceCQueryI.model_rebuild()
InterfaceCQueryI.model_rebuild()
InterfaceCQueryI.model_rebuild()
InterfaceCQueryI.model_rebuild()
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ class InterfaceWithTypenameQueryI(BaseModel):

InterfaceWithTypename.model_rebuild()
InterfaceWithTypenameQueryI.model_rebuild()
InterfaceWithTypenameQueryI.model_rebuild()
InterfaceWithTypenameQueryI.model_rebuild()
InterfaceWithTypenameQueryI.model_rebuild()
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,3 @@

class QueryWithFragmentOnQueryWithInterface(FragmentOnQueryWithInterface):
pass


QueryWithFragmentOnQueryWithInterface.model_rebuild()
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,3 @@

class QueryWithFragmentOnQueryWithUnion(FragmentOnQueryWithUnion):
pass


QueryWithFragmentOnQueryWithUnion.model_rebuild()
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ class ExampleQuery1ExampleQuery(MinimalA):


ExampleQuery1.model_rebuild()
ExampleQuery1ExampleQuery.model_rebuild()
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ class ExampleQuery2ExampleQuery(FullA):


ExampleQuery2.model_rebuild()
ExampleQuery2ExampleQuery.model_rebuild()
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ class ExampleQuery3ExampleQuery(CompleteA):


ExampleQuery3.model_rebuild()
ExampleQuery3ExampleQuery.model_rebuild()
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,3 @@

class GetA(BaseModel):
a: str


GetA.model_rebuild()
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,3 @@

class GetA2(BaseModel):
a: str


GetA2.model_rebuild()
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,3 @@

class GetB(BaseModel):
b: str


GetB.model_rebuild()
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,3 @@

class GetD(BaseModel):
d: str


GetD.model_rebuild()
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,3 @@

class GetE(BaseModel):
e: str


GetE.model_rebuild()
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ class GetFF(BaseModel):


GetF.model_rebuild()
GetFF.model_rebuild()
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ class GetGG(FragmentG):


GetG.model_rebuild()
GetGG.model_rebuild()
3 changes: 0 additions & 3 deletions tests/main/clients/operations/expected_client/c_mutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,3 @@

class CMutation(BaseModel):
const_mutation: int = Field(alias="constMutation")


CMutation.model_rebuild()
3 changes: 0 additions & 3 deletions tests/main/clients/operations/expected_client/c_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,3 @@

class CQuery(BaseModel):
const_query: str = Field(alias="constQuery")


CQuery.model_rebuild()
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,3 @@

class CSubscription(BaseModel):
const_subscription: float = Field(alias="constSubscription")


CSubscription.model_rebuild()
1 change: 0 additions & 1 deletion tests/main/clients/operations/expected_client/get_a.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ class GetAAValueB(BaseModel):

GetA.model_rebuild()
GetAA.model_rebuild()
GetAAValueB.model_rebuild()
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ class GetAWithFragmentAValueB(FragmentB):

GetAWithFragment.model_rebuild()
GetAWithFragmentA.model_rebuild()
GetAWithFragmentAValueB.model_rebuild()
1 change: 0 additions & 1 deletion tests/main/clients/operations/expected_client/get_s.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ class GetSS(BaseModel):


GetS.model_rebuild()
GetSS.model_rebuild()
2 changes: 2 additions & 0 deletions tests/main/clients/operations/expected_client/get_xyz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 0 additions & 3 deletions tests/main/clients/remote_schema/expected_client/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,3 @@

class Test(BaseModel):
test_query: Optional[int] = Field(alias="testQuery")


Test.model_rebuild()
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class GetAnimalByNameAnimalByNameDog(BaseModel):
puppies: int


GetAnimalByName.model_rebuild()
GetAnimalByName.model_rebuild()
GetAnimalByName.model_rebuild()
GetAnimalByNameAnimalByNameAnimal.model_rebuild()
GetAnimalByNameAnimalByNameCat.model_rebuild()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,3 @@

class GetAnimalFragmentWithExtra(ListAnimalsFragment):
list_string: List[str] = Field(alias="listString")


GetAnimalFragmentWithExtra.model_rebuild()
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ class GetAuthenticatedUserMe(BaseModel):


GetAuthenticatedUser.model_rebuild()
GetAuthenticatedUserMe.model_rebuild()
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,3 @@ class GetComplexScalar(BaseModel):
just_complex_scalar: Annotated[
ComplexScalar, BeforeValidator(parse_complex_scalar)
] = Field(alias="justComplexScalar")


GetComplexScalar.model_rebuild()
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,3 @@

class GetSimpleScalar(BaseModel):
just_simple_scalar: SimpleScalar = Field(alias="justSimpleScalar")


GetSimpleScalar.model_rebuild()
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class ListAnimalsListAnimalsDog(BaseModel):
puppies: int


ListAnimals.model_rebuild()
ListAnimals.model_rebuild()
ListAnimals.model_rebuild()
ListAnimalsListAnimalsAnimal.model_rebuild()
ListAnimalsListAnimalsCat.model_rebuild()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,3 @@ class ListStrings1(BaseModel):
optional_list_optional_string: Optional[List[Optional[str]]] = Field(
alias="optionalListOptionalString"
)


ListStrings1.model_rebuild()
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,3 @@

class ListStrings2(BaseModel):
optional_list_string: Optional[List[str]] = Field(alias="optionalListString")


ListStrings2.model_rebuild()
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,3 @@

class ListStrings3(BaseModel):
list_optional_string: List[Optional[str]] = Field(alias="listOptionalString")


ListStrings3.model_rebuild()
Loading

0 comments on commit 5b6cb6d

Please sign in to comment.