bootgraph 1.9.0.dev24128__tar.gz → 1.9.0.dev24129__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: bootgraph
3
- Version: 1.9.0.dev24128
3
+ Version: 1.9.0.dev24129
4
4
  Summary: A Python library for integrating SQLModel and Strawberry, providing a seamless GraphQL integration with FastAPI and advanced features for database interactions.
5
5
  Home-page: https://github.com/MDoreto/graphemy
6
6
  License: MIT
@@ -69,6 +69,8 @@ class Dl:
69
69
 
70
70
  source: str | list[str]
71
71
  target: str | list[str]
72
+ extract_from_nested_dl: str | None = None
73
+ return_class: str | None = None
72
74
  foreign_key: bool | None = None
73
75
 
74
76
  def __init__(
@@ -76,6 +78,8 @@ class Dl:
76
78
  source: str | list[str],
77
79
  target: str | list[str],
78
80
  foreign_key: bool = None,
81
+ extract_from_nested_dl: str | None = None,
82
+ return_class: str | None = None,
79
83
  ):
80
84
  if type(source) != type(target):
81
85
  raise "source and target must have same type"
@@ -90,6 +94,8 @@ class Dl:
90
94
  self.source = source
91
95
  self.target = target
92
96
  self.foreign_key = foreign_key
97
+ self.extract_from_nested_dl = extract_from_nested_dl
98
+ self.return_class = return_class
93
99
 
94
100
 
95
101
  class GraphemyDataLoader(DataLoader):
@@ -7,7 +7,8 @@ from typing import (
7
7
  TypeVar,
8
8
  Union,
9
9
  get_args,
10
- get_origin, Type,
10
+ get_origin,
11
+ Type
11
12
  )
12
13
 
13
14
  from sqlalchemy.orm import Mapped
@@ -322,7 +323,7 @@ def get_dl_function(
322
323
 
323
324
  # Define the return type using Strawberry's lazy type resolution
324
325
  return_type = Annotated[
325
- f"{class_type}", # Schema
326
+ f"{class_type}" if not field_value.return_class else field_value.return_class,
326
327
  strawberry.lazy("bootgraph.router"),
327
328
  ]
328
329
  if is_list:
@@ -355,7 +356,15 @@ def get_dl_function(
355
356
  if isinstance(field_value.source, list)
356
357
  else getattr(self, field_value.source)
357
358
  )
358
- return await info.context[dl_name].load(source_value, {"filters": filter_args})
359
+ resp = await info.context[dl_name].load(source_value, {"filters": filter_args})
360
+ if field_value.extract_from_nested_dl:
361
+ if isinstance(resp, list):
362
+ # If the response is a list, apply getattr to each item
363
+ return [await getattr(item, field_value.extract_from_nested_dl)(info) for item in resp]
364
+ else:
365
+ # Single object
366
+ return await getattr(resp, field_value.extract_from_nested_dl)(info)
367
+ return resp
359
368
 
360
369
  # Customize the function attributes for introspection or other purposes
361
370
  loader_func.__name__ = field_name
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "bootgraph"
3
- version = "v1.9.0.dev24128"
3
+ version = "v1.9.0.dev24129"
4
4
  description = "A Python library for integrating SQLModel and Strawberry, providing a seamless GraphQL integration with FastAPI and advanced features for database interactions."
5
5
  authors = ["Matheus Doreto <matheusdoreto.md@gmail.com>", "Pavel Mulin <mulin.pasha@gmail.com>"]
6
6
  readme = "README.md"