Skip to content

Commit

Permalink
Add Product.standardProduct field
Browse files Browse the repository at this point in the history
  • Loading branch information
pylipp committed Feb 4, 2025
1 parent e4dd7b3 commit de4011b
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ def resolve_product_base(product_obj, info):
return info.context["base_loader"].load(product_obj.base_id)


@product.field("standardProduct")
def resolve_product_standard_product(product_obj, info):
return info.context["standard_product_loader"].load(product_obj.standard_product_id)


@product.field("type")
def resolve_product_type(product_obj, _):
if product_obj.standard_product_id is None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ type Product {
category: ProductCategory!
sizeRange: SizeRange!
base: Base
" null for products of type [`Custom`]({{Types.ProductType}}) "
standardProduct: StandardProduct
price: Float
gender: ProductGender
comment: String
Expand Down
2 changes: 2 additions & 0 deletions back/boxtribute_server/graph_ql/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
SizeLoader,
SizeRangeLoader,
SizesForSizeRangeLoader,
StandardProductLoader,
TagsForBoxLoader,
TransferAgreementLoader,
UnitLoader,
Expand Down Expand Up @@ -53,6 +54,7 @@ async def run():
"size_loader": SizeLoader(),
"size_range_loader": SizeRangeLoader(),
"sizes_for_size_range_loader": SizesForSizeRangeLoader(),
"standard_product_loader": StandardProductLoader(),
"tags_for_box_loader": TagsForBoxLoader(),
"transfer_agreement_loader": TransferAgreementLoader(),
"units_for_dimension_loader": UnitsForDimensionLoader(),
Expand Down
6 changes: 6 additions & 0 deletions back/boxtribute_server/graph_ql/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from ..models.definitions.shipment_detail import ShipmentDetail
from ..models.definitions.size import Size
from ..models.definitions.size_range import SizeRange
from ..models.definitions.standard_product import StandardProduct
from ..models.definitions.tag import Tag
from ..models.definitions.tags_relation import TagsRelation
from ..models.definitions.transfer_agreement import TransferAgreement
Expand Down Expand Up @@ -115,6 +116,11 @@ def __init__(self):
super().__init__(SizeRange)


class StandardProductLoader(SimpleDataLoader):
def __init__(self):
super().__init__(StandardProduct)


class ShipmentLoader(DataLoader):
async def batch_load_fn(self, keys):
shipments = {
Expand Down
15 changes: 12 additions & 3 deletions back/test/endpoint_tests/test_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def test_product_query(
id
name
type
standardProduct {{ id }}
category {{ hasGender }}
sizeRange {{
id
Expand All @@ -48,6 +49,7 @@ def test_product_query(
"id": str(product_id),
"name": default_product["name"],
"type": ProductType.Custom.name,
"standardProduct": None,
"category": {"hasGender": True},
"sizeRange": {
"id": str(default_product["size_range"]),
Expand Down Expand Up @@ -86,10 +88,17 @@ def test_product_query(
}

query = f"""query {{
product(id: {disabled_standard_product["id"]}) {{ instockItemsCount }}
}}"""
product(id: {disabled_standard_product["id"]}) {{
instockItemsCount
type
standardProduct {{ id }}
}} }}"""
queried_product = assert_successful_request(read_only_client, query)
assert queried_product == {"instockItemsCount": 0}
assert queried_product == {
"instockItemsCount": 0,
"type": ProductType.StandardInstantiation.name,
"standardProduct": {"id": str(disabled_standard_product["standard_product"])},
}


@pytest.mark.parametrize(
Expand Down
2 changes: 1 addition & 1 deletion graphql/generated/graphql-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export type introspection_types = {
'PackingListEntryState': { name: 'PackingListEntryState'; enumValues: 'NotStarted' | 'PackingInProgress' | 'Packed'; };
'PageInfo': { kind: 'OBJECT'; name: 'PageInfo'; fields: { 'endCursor': { name: 'endCursor'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'String'; ofType: null; }; } }; 'hasNextPage': { name: 'hasNextPage'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Boolean'; ofType: null; }; } }; 'hasPreviousPage': { name: 'hasPreviousPage'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Boolean'; ofType: null; }; } }; 'startCursor': { name: 'startCursor'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'String'; ofType: null; }; } }; }; };
'PaginationInput': { kind: 'INPUT_OBJECT'; name: 'PaginationInput'; isOneOf: false; inputFields: [{ name: 'after'; type: { kind: 'SCALAR'; name: 'String'; ofType: null; }; defaultValue: null }, { name: 'first'; type: { kind: 'SCALAR'; name: 'Int'; ofType: null; }; defaultValue: null }, { name: 'before'; type: { kind: 'SCALAR'; name: 'String'; ofType: null; }; defaultValue: null }, { name: 'last'; type: { kind: 'SCALAR'; name: 'Int'; ofType: null; }; defaultValue: null }]; };
'Product': { kind: 'OBJECT'; name: 'Product'; fields: { 'base': { name: 'base'; type: { kind: 'OBJECT'; name: 'Base'; ofType: null; } }; 'category': { name: 'category'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'OBJECT'; name: 'ProductCategory'; ofType: null; }; } }; 'comment': { name: 'comment'; type: { kind: 'SCALAR'; name: 'String'; ofType: null; } }; 'createdBy': { name: 'createdBy'; type: { kind: 'OBJECT'; name: 'User'; ofType: null; } }; 'createdOn': { name: 'createdOn'; type: { kind: 'SCALAR'; name: 'Datetime'; ofType: null; } }; 'deletedOn': { name: 'deletedOn'; type: { kind: 'SCALAR'; name: 'Datetime'; ofType: null; } }; 'gender': { name: 'gender'; type: { kind: 'ENUM'; name: 'ProductGender'; ofType: null; } }; 'id': { name: 'id'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'ID'; ofType: null; }; } }; 'inShop': { name: 'inShop'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Boolean'; ofType: null; }; } }; 'instockItemsCount': { name: 'instockItemsCount'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Int'; ofType: null; }; } }; 'lastModifiedBy': { name: 'lastModifiedBy'; type: { kind: 'OBJECT'; name: 'User'; ofType: null; } }; 'lastModifiedOn': { name: 'lastModifiedOn'; type: { kind: 'SCALAR'; name: 'Datetime'; ofType: null; } }; 'name': { name: 'name'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'String'; ofType: null; }; } }; 'price': { name: 'price'; type: { kind: 'SCALAR'; name: 'Float'; ofType: null; } }; 'sizeRange': { name: 'sizeRange'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'OBJECT'; name: 'SizeRange'; ofType: null; }; } }; 'type': { name: 'type'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'ENUM'; name: 'ProductType'; ofType: null; }; } }; }; };
'Product': { kind: 'OBJECT'; name: 'Product'; fields: { 'base': { name: 'base'; type: { kind: 'OBJECT'; name: 'Base'; ofType: null; } }; 'category': { name: 'category'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'OBJECT'; name: 'ProductCategory'; ofType: null; }; } }; 'comment': { name: 'comment'; type: { kind: 'SCALAR'; name: 'String'; ofType: null; } }; 'createdBy': { name: 'createdBy'; type: { kind: 'OBJECT'; name: 'User'; ofType: null; } }; 'createdOn': { name: 'createdOn'; type: { kind: 'SCALAR'; name: 'Datetime'; ofType: null; } }; 'deletedOn': { name: 'deletedOn'; type: { kind: 'SCALAR'; name: 'Datetime'; ofType: null; } }; 'gender': { name: 'gender'; type: { kind: 'ENUM'; name: 'ProductGender'; ofType: null; } }; 'id': { name: 'id'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'ID'; ofType: null; }; } }; 'inShop': { name: 'inShop'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Boolean'; ofType: null; }; } }; 'instockItemsCount': { name: 'instockItemsCount'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Int'; ofType: null; }; } }; 'lastModifiedBy': { name: 'lastModifiedBy'; type: { kind: 'OBJECT'; name: 'User'; ofType: null; } }; 'lastModifiedOn': { name: 'lastModifiedOn'; type: { kind: 'SCALAR'; name: 'Datetime'; ofType: null; } }; 'name': { name: 'name'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'String'; ofType: null; }; } }; 'price': { name: 'price'; type: { kind: 'SCALAR'; name: 'Float'; ofType: null; } }; 'sizeRange': { name: 'sizeRange'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'OBJECT'; name: 'SizeRange'; ofType: null; }; } }; 'standardProduct': { name: 'standardProduct'; type: { kind: 'OBJECT'; name: 'StandardProduct'; ofType: null; } }; 'type': { name: 'type'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'ENUM'; name: 'ProductType'; ofType: null; }; } }; }; };
'ProductCategory': { kind: 'OBJECT'; name: 'ProductCategory'; fields: { 'hasGender': { name: 'hasGender'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Boolean'; ofType: null; }; } }; 'id': { name: 'id'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'ID'; ofType: null; }; } }; 'name': { name: 'name'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'String'; ofType: null; }; } }; 'products': { name: 'products'; type: { kind: 'OBJECT'; name: 'ProductPage'; ofType: null; } }; }; };
'ProductDimensionInfo': { kind: 'OBJECT'; name: 'ProductDimensionInfo'; fields: { 'gender': { name: 'gender'; type: { kind: 'ENUM'; name: 'ProductGender'; ofType: null; } }; 'id': { name: 'id'; type: { kind: 'SCALAR'; name: 'Int'; ofType: null; } }; 'name': { name: 'name'; type: { kind: 'SCALAR'; name: 'String'; ofType: null; } }; }; };
'ProductGender': { name: 'ProductGender'; enumValues: 'Men' | 'Women' | 'UnisexAdult' | 'UnisexKid' | 'UnisexBaby' | 'TeenGirl' | 'TeenBoy' | 'Girl' | 'Boy' | 'none'; };
Expand Down
2 changes: 2 additions & 0 deletions graphql/generated/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,8 @@ type Product {
category: ProductCategory!
sizeRange: SizeRange!
base: Base
" null for products of type [`Custom`]({{Types.ProductType}}) "
standardProduct: StandardProduct
price: Float
gender: ProductGender
comment: String
Expand Down

0 comments on commit de4011b

Please sign in to comment.