bootgraph 1.10.0.dev24599__tar.gz → 1.11.0.dev24752__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.10.0.dev24599
3
+ Version: 1.11.0.dev24752
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
  License: MIT
6
6
  Author: Matheus Doreto
@@ -11,6 +11,7 @@ from fastapi import Request, Response
11
11
  from graphql.error import GraphQLError
12
12
  from graphql.error.graphql_error import format_error as format_graphql_error
13
13
  from sqlalchemy.engine.base import Engine
14
+ from sqlalchemy.ext.asyncio import AsyncEngine
14
15
  from strawberry.fastapi import GraphQLRouter
15
16
  from strawberry.http import GraphQLHTTPResponse
16
17
  from strawberry.types import ExecutionResult
@@ -112,7 +113,7 @@ class GraphemyRouter(GraphQLRouter):
112
113
  permission_getter: Callable | None = None,
113
114
  dl_filter: Callable | None = None,
114
115
  query_filter: Callable | None = None,
115
- engine: Engine | Dict[str, Engine] = None,
116
+ engine: AsyncEngine | Engine | Dict[str, Engine] = None,
116
117
  extensions: list = None,
117
118
  enable_queries: bool = True,
118
119
  enable_put_mutations: bool = False,
@@ -169,11 +170,16 @@ class GraphemyRouter(GraphQLRouter):
169
170
  # model_mutation_fields = {}
170
171
  if cls_mutations:
171
172
  # Create a resolver that returns an instance of ModelMutations
172
- def model_mutations_resolver() -> cls_mutations:
173
- return cls_mutations()
173
+ def make_mutation_resolver(mutations):
174
+ def resolver() -> mutations:
175
+ return mutations()
176
+
177
+ return resolver
178
+
179
+ resolver = make_mutation_resolver(cls_mutations)
174
180
 
175
181
  # Create a Strawberry field for this query
176
- mutation_field = strawberry.field(description=f"Mutations for {cls.__queryname__}")(model_mutations_resolver)
182
+ mutation_field = strawberry.field(description=f"Mutations for {cls.__queryname__}")(resolver)
177
183
 
178
184
  need_mutation = False
179
185
  setattr(mutation, cls.__queryname__, mutation_field)
@@ -185,9 +191,15 @@ class GraphemyRouter(GraphQLRouter):
185
191
  )
186
192
 
187
193
  async def get_context(request: Request, response: Response) -> dict:
188
- context = {"engine": engine}
189
- if context_session:
190
- context = {"session": context_session(engine)}
194
+ if type(engine) == AsyncEngine:
195
+ context = {"engine": engine}
196
+ if context_session:
197
+ session_generator = context_session()
198
+ context = {"session": await anext(session_generator)}
199
+ else:
200
+ context = {"engine": engine}
201
+ if context_session:
202
+ context = {"session": context_session(engine)}
191
203
  if context_getter:
192
204
  context = await context_getter(request, response, context)
193
205
  for k, (func, return_class) in functions.items():
@@ -10,7 +10,8 @@ from typing import (
10
10
  get_origin,
11
11
  Type
12
12
  )
13
-
13
+ from sqlalchemy.orm import sessionmaker
14
+ from sqlalchemy.ext.asyncio import AsyncSession
14
15
  from sqlalchemy.orm import Mapped
15
16
  from sqlalchemy import ForeignKeyConstraint, func
16
17
  from sqlalchemy.inspection import inspect
@@ -895,6 +896,7 @@ def get_mutations(cls: "Graphemy"):
895
896
  """
896
897
  fields = {}
897
898
 
899
+ @strawberry.type
898
900
  class ModelMutations:
899
901
  pass
900
902
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "bootgraph"
3
- version = "v1.10.0.dev24599"
3
+ version = "v1.11.0.dev24752"
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"
@@ -51,6 +51,8 @@ jinja2 = "^3.1.2"
51
51
  mdx-include = "^1.4.2"
52
52
  mkdocstrings = "^0.26.1"
53
53
  mkdocstrings-python = "^1.11.1"
54
+ asyncpg = ">=0.29.0"
55
+ greenlet = ">=3.0.3"
54
56
 
55
57
  [build-system]
56
58
  requires = ["poetry-core"]