Improve enums doc to favor python enum over dict
@@ -81,6 +81,21 @@ In database, the application may store those weights as integers from 0 to 2. No
Ariadne provides ``Enum`` utility class thats allows you to delegate this task to GraphQL server::
+ import enum
+
+ from ariadne import Enum
+
+ class PostWeight(enum.IntEnum):
+ STANDARD = 1
+ PINNED = 2
+ PROMOTED = 3
+
+ post_weight = Enum("PostWeight", PostWeight)
+
+Include the ``post_weight`` instance in list of ``resolvers`` passed to your GraphQL server, and it will automatically translate Enums between their GraphQL and Python values.
+
+Instead of ``Enum`` you may use ``dict``::
+
from ariadne import Enum
post_weight = Enum(
@@ -92,26 +107,4 @@ Ariadne provides ``Enum`` utility class thats allows you to delegate this task t
},
)
-Include the ``post_weight`` instance in list of ``resolvers`` passed to your GraphQL server, and it will automatically translate Enums between their GraphQL and Python values.
-
-Instead of ``dict`` you may use either ``enum.Enum`` or ``enum.IntEnum``::
-
- import enum
-
- from ariadne import Enum
-
- class PostWeight(enum.Enum):
- STANDARD = "standard"
- PINNED = "pin"
- PROMOTED = "promo"
-
- post_weight = Enum("PostWeight", PostWeight)
-
- # or using IntEnum
-
- class PostWeight(enum.IntEnum):
- STANDARD = 1
- PINNED = 2
- PROMOTED = 3
-
- post_weight = Enum("PostWeight", PostWeight)
+Both ``Enum`` and ``IntEnum`` are supported by ``ariadne.Enum``.
