Skip to content

Commit 5b7f52c

Browse files
Allow User-Defined Connection/Edge Types
1 parent 2d1fe15 commit 5b7f52c

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/strawberry_sqlalchemy_mapper/mapper.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ def __init__(
151151
extra_sqlalchemy_type_to_strawberry_type_map: Optional[
152152
Mapping[Type[TypeEngine], Type[Any]]
153153
] = None,
154+
edge_type: Type = None,
155+
connection_type: Type = None,
154156
) -> None:
155157
if model_to_type_name is None:
156158
model_to_type_name = self._default_model_to_type_name
@@ -172,6 +174,9 @@ def __init__(
172174
self._related_type_models = set()
173175
self._related_interface_models = set()
174176

177+
self.edge_type = edge_type
178+
self.connection_type = connection_type
179+
175180
@staticmethod
176181
def _default_model_to_type_name(model: Type[BaseModelType]) -> str:
177182
return model.__name__
@@ -211,6 +216,8 @@ def _edge_type_for(self, type_name: str) -> Type[Any]:
211216
Get or create a corresponding Edge model for the given type
212217
(to support future pagination)
213218
"""
219+
if self.edge_type is not None:
220+
return self.edge_type
214221
edge_name = f"{type_name}Edge"
215222
if edge_name not in self.edge_types:
216223
self.edge_types[edge_name] = edge_type = strawberry.type(
@@ -229,6 +236,8 @@ def _connection_type_for(self, type_name: str) -> Type[Any]:
229236
Get or create a corresponding Connection model for the given type
230237
(to support future pagination)
231238
"""
239+
if self.connection_type is not None:
240+
return self.connection_type[ForwardRef(type_name)]
232241
connection_name = f"{type_name}Connection"
233242
if connection_name not in self.connection_types:
234243
self.connection_types[connection_name] = connection_type = strawberry.type(

0 commit comments

Comments
 (0)