-
-
Notifications
You must be signed in to change notification settings - Fork 509
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
105 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING, Any, Callable, List, Optional, Sequence | ||
|
||
from strawberry.types.types import StrawberryObjectDefinition | ||
|
||
if TYPE_CHECKING: | ||
from dataclasses import Field | ||
|
||
from graphql import GraphQLAbstractType, GraphQLResolveInfo | ||
|
||
from strawberry.field import StrawberryField | ||
from strawberry.type import WithStrawberryObjectDefinition | ||
|
||
|
||
class TypeExtension: | ||
def on_field(self, field: Field | StrawberryField) -> Field | StrawberryField: | ||
"""Called for each field, _MUST_ return valid field""" | ||
return field | ||
|
||
def before_wrap_dataclass(self, cls: type) -> None: | ||
"""Called before class is wrapped as dataclass""" | ||
return | ||
|
||
def after_process(self, cls: type[WithStrawberryObjectDefinition]) -> type: | ||
"""Called after entire process finishes""" | ||
return cls | ||
|
||
def create_object_definition( | ||
self, | ||
origin: type[Any], | ||
name: str, | ||
is_input: bool, | ||
is_interface: bool, | ||
interfaces: List[StrawberryObjectDefinition], | ||
description: Optional[str], | ||
directives: Optional[Sequence[object]], | ||
extend: bool, | ||
fields: List[StrawberryField], | ||
is_type_of: Optional[Callable[[Any, GraphQLResolveInfo], bool]], | ||
resolve_type: Optional[ | ||
Callable[[Any, GraphQLResolveInfo, GraphQLAbstractType], str] | ||
], | ||
) -> StrawberryObjectDefinition: | ||
"""Hook for creation of StrawberryObjectDefinition for __strawberry_definition__ attr""" | ||
|
||
return StrawberryObjectDefinition( | ||
name=name, | ||
is_input=is_input, | ||
is_interface=is_interface, | ||
interfaces=interfaces, | ||
description=description, | ||
directives=directives, | ||
origin=origin, | ||
extend=extend, | ||
fields=fields, | ||
is_type_of=is_type_of, | ||
resolve_type=resolve_type, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters