You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using the register_graphql function, all products in the SUBSCRIPTION_MODEL_REGISTRY will be automatically converted into GraphQL types.
44
+
When using the `register_graphql()` function, all products in the `SUBSCRIPTION_MODEL_REGISTRY` will be automatically converted into GraphQL types.
45
45
The registration process iterates through the list, starting from the deepest product block and working its way back up to the product level.
46
46
47
-
However, there is a potential issue when dealing with a ProductBlock that references itself, as it can lead to an infinite loop.
48
-
To handle this situation, you must manually create the GraphQL type for that ProductBlock and add it to the GRAPHQL_MODELS list.
47
+
However, there is a potential issue when dealing with a `ProductBlock` that references itself, as it leads to an error expecting the `ProductBlock` type to exist.
48
+
49
+
Here an example of the expected error with self referenced `ProductBlock`:
50
+
51
+
```
52
+
trawberry.experimental.pydantic.exceptions.UnregisteredTypeException: Cannot find a Strawberry Type for <class 'products.product_blocks.product_block_file.ProductBlock'> did you forget to register it?
53
+
```
54
+
55
+
To handle this situation, you must manually create the GraphQL type for that `ProductBlock` and add it to the `GRAPHQL_MODELS` list.
49
56
50
57
Here's an example of how to do it:
51
58
52
59
```python
60
+
# product_block_file.py
53
61
import strawberry
54
62
from typing import Annotated
55
63
from app.product_blocks import ProductBlock
@@ -60,7 +68,7 @@ from orchestrator.graphql import GRAPHQL_MODELS
By following this example, you can effectively create the necessary GraphQL type for ProductBlock and ensure proper registration with register_graphql. This will help you avoid any infinite loop scenarios and enable smooth integration of domain models with GraphQL.
81
+
By following this example, you can effectively create the necessary GraphQL type for `ProductBlock` and ensure proper registration with `register_graphql()`. This will help you avoid any `Cannot find a Strawberry Type` scenarios and enable smooth integration of domain models with GraphQL.
74
82
75
83
### Scalars for Auto Registration
76
84
77
-
When working with special types such as VlanRanges or IPv4Interface in the core module, scalar types are essential for the auto registration process.
78
-
Scalar types enable smooth integration of these special types into the GraphQL schema.
85
+
When working with special types such as `VlanRanges` or `IPv4Interface` in the core module, scalar types are essential for the auto registration process.
86
+
Scalar types enable smooth integration of these special types into the GraphQL schema, They need to be initialized before `register_graphql()`.
79
87
80
88
Here's an example of how to add a new scalar:
81
89
82
90
```python
83
91
import strawberry
84
92
from typing import NewType
85
-
from orchestrator.graphql importSCALAR_OVERRIDESs
93
+
from orchestrator.graphql importSCALAR_OVERRIDES
86
94
87
95
VlanRangesType = strawberry.scalar(
88
96
NewType("VlanRangesType", str),
@@ -97,7 +105,7 @@ SCALAR_OVERRIDES = {
97
105
}
98
106
```
99
107
100
-
You can find more examples of scalar usage in the `orchestrator-core/orchestrator/graphql/types.py` file.
108
+
You can find more examples of scalar usage in the `orchestrator/graphql/types.py` file.
101
109
For additional information on Scalars, please refer to the Strawberry documentation on Scalars: https://strawberry.rocks/docs/types/scalars.
102
110
103
111
By using scalar types for auto registration, you can seamlessly incorporate special types into your GraphQL schema, making it easier to work with complex data in the Orchestrator application.
0 commit comments