fix: strawberry type things
This commit is contained in:
12 files changed
+146
-296
No files matched your search
@@ -1,3 +1,5 @@
|
||||
from typing import Annotated
|
||||
|
||||
import strawberry
|
||||
from django.conf import settings
|
||||
from django.contrib.auth import get_user_model
|
||||
@@ -29,7 +31,9 @@ class InsufficientFunds(Error): # noqa: N818
|
||||
amount_lacking: float
|
||||
|
||||
|
||||
CreateOrderResponse = strawberry.union("CreateOrderResponse", [CreateOrderSuccess, InsufficientFunds, FormErrors])
|
||||
CreateOrderResponse = Annotated[
|
||||
CreateOrderSuccess | InsufficientFunds | FormErrors, strawberry.union("CreateOrderResponse")
|
||||
]
|
||||
|
||||
|
||||
@strawberry.mutation
|
||||
@@ -95,7 +99,9 @@ class AboveMaxSaldo(Error): # noqa: N818
|
||||
above: float
|
||||
|
||||
|
||||
CreateDepositResponse = strawberry.union("CreateDepositResponse", [CreateDepositSuccess, AboveMaxSaldo, FormErrors])
|
||||
CreateDepositResponse = Annotated[
|
||||
CreateDepositSuccess | AboveMaxSaldo | FormErrors, strawberry.union("CreateDepositResponse")
|
||||
]
|
||||
|
||||
|
||||
@strawberry.mutation
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
import strawberry
|
||||
import strawberry_django
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.models import User as DjangoUser
|
||||
from django.db import transaction
|
||||
from strawberry_django import auto
|
||||
from strawberry import auto
|
||||
|
||||
from bbs import models
|
||||
from bbs.api.types.users import User
|
||||
|
||||
DjangoUser = get_user_model()
|
||||
|
||||
|
||||
@strawberry_django.input(DjangoUser)
|
||||
class UserInput:
|
||||
|
||||
@@ -6,4 +6,4 @@ from bbs.api.types.inventory import Transaction, TransactionOrdering
|
||||
|
||||
@strawberry.type
|
||||
class InventoryQueries:
|
||||
transaction_list: list[Transaction] = strawberry_django.field(pagination=True, order=TransactionOrdering)
|
||||
transaction_list: list[Transaction] = strawberry_django.field(pagination=True, ordering=TransactionOrdering)
|
||||
@@ -17,7 +17,7 @@ from bbs.api.types.shop import (
|
||||
class ShopQueries:
|
||||
all_products: list[Product] = strawberry_django.field()
|
||||
all_orders: list[Order] = strawberry_django.field()
|
||||
order_list: list[Order] = strawberry_django.field(pagination=True, order=OrderOrdering)
|
||||
order_list: list[Order] = strawberry_django.field(pagination=True, ordering=OrderOrdering)
|
||||
|
||||
@strawberry.field
|
||||
def order_stats(self) -> OrderStats:
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
import strawberry
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from strawberry.extensions import Extension
|
||||
from strawberry.extensions import SchemaExtension
|
||||
|
||||
from bbs.api.mutations.shop import ShopMutations
|
||||
from bbs.api.mutations.users import UsersMutations
|
||||
@@ -19,7 +19,7 @@ class Mutation(ShopMutations, UsersMutations):
|
||||
pass
|
||||
|
||||
|
||||
class HandleNotFound(Extension):
|
||||
class HandleNotFound(SchemaExtension):
|
||||
def on_request_end(self):
|
||||
result = self.execution_context.result
|
||||
if result.errors:
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
from typing import TYPE_CHECKING
|
||||
from typing import TYPE_CHECKING, Annotated
|
||||
|
||||
import strawberry
|
||||
import strawberry_django
|
||||
from strawberry_django import auto
|
||||
from strawberry import auto
|
||||
|
||||
from bbs import models
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from bbs.api.types.users import User
|
||||
from .users import User
|
||||
|
||||
|
||||
@strawberry_django.ordering.order(models.Transaction)
|
||||
@strawberry_django.order_type(models.Transaction)
|
||||
class TransactionOrdering:
|
||||
created: auto
|
||||
|
||||
@@ -17,6 +18,6 @@ class TransactionOrdering:
|
||||
@strawberry_django.type(models.Transaction)
|
||||
class Transaction:
|
||||
id: auto
|
||||
user: "User"
|
||||
user: Annotated["User", strawberry.lazy(".users")]
|
||||
amount: auto
|
||||
created: auto
|
||||
@@ -1,12 +1,17 @@
|
||||
from typing import TYPE_CHECKING, Annotated
|
||||
|
||||
import strawberry
|
||||
import strawberry_django
|
||||
from strawberry_django import auto
|
||||
from strawberry import auto
|
||||
|
||||
from bbs import models
|
||||
from bbs.api.types.utils import JSONScalar
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .users import User
|
||||
|
||||
@strawberry_django.filters.filter(models.Product)
|
||||
|
||||
@strawberry_django.filter_type(models.Product)
|
||||
class ProductFilter:
|
||||
id: auto
|
||||
active: auto
|
||||
@@ -23,7 +28,7 @@ class Product:
|
||||
user_counts: JSONScalar
|
||||
|
||||
|
||||
@strawberry_django.ordering.order(models.Order)
|
||||
@strawberry_django.order_type(models.Order)
|
||||
class OrderOrdering:
|
||||
created: auto
|
||||
|
||||
@@ -31,7 +36,7 @@ class OrderOrdering:
|
||||
@strawberry_django.type(models.Order)
|
||||
class Order:
|
||||
id: auto
|
||||
customer: strawberry.LazyType["User", "bbs.api.types.users"] # noqa: F821
|
||||
customer: Annotated["User", strawberry.lazy(".users")]
|
||||
order_sum: auto
|
||||
created: auto
|
||||
orderlines: list["OrderLine"]
|
||||
|
||||
@@ -3,14 +3,12 @@ from decimal import Decimal
|
||||
|
||||
import strawberry
|
||||
import strawberry_django
|
||||
from django.contrib.auth import get_user_model
|
||||
from strawberry_django import auto
|
||||
from django.contrib.auth.models import User as DjangoUser
|
||||
from strawberry import auto
|
||||
|
||||
from bbs import models
|
||||
from bbs.api.types.shop import Point, ProductOrderStat
|
||||
|
||||
UserModel = get_user_model()
|
||||
|
||||
|
||||
@strawberry.type
|
||||
class TopMonth:
|
||||
@@ -42,7 +40,7 @@ class UserProfile:
|
||||
]
|
||||
|
||||
|
||||
@strawberry_django.type(UserModel)
|
||||
@strawberry_django.type(DjangoUser)
|
||||
class User:
|
||||
id: auto
|
||||
first_name: auto
|
||||
|
||||
@@ -21,6 +21,7 @@ DATABASES = {
|
||||
TIME_ZONE = "Europe/Oslo"
|
||||
LANGUAGE_CODE = "nb"
|
||||
USE_I18N = True
|
||||
USE_TZ = True
|
||||
|
||||
SITE_ID = 1
|
||||
|
||||
|
||||
Reference in new issue
Block a user