Set default value to a List of Enum values
See original GitHub issueHi,
I’m having a hard time trying to set a default value to a List of enum values. Here’s how the code looks:
get_products = graphene.relay.ConnectionField(ProductConnection, dict(
statuses=graphene.List(ProductNode.status, default_value=[ProductStatus.DRAFT, ProductStatus.ACTIVE])
))
# Note that if I set:
# graphene.NonNull(graphene.Enum.from_enum(ProductStatus))
# instead of ProductNode.status I get the following error:
# AssertionError: Found different types with the same name in the schema: ProductStatus, ProductStatus.
class ProductStatus(str, enum.Enum):
DRAFT = "DRAFT"
ACTIVE = "ACTIVE"
DELETED = "DELETED"
class ProductNode(graphene.ObjectType):
status = graphene.NonNull(graphene.Enum.from_enum(ProductStatus))
class ProductConnection(NonNullConnection):
""" Paginated Product """
class Meta:
node = ProductNode
The schema generated:
{
"name": "statuses",
"description": null,
"type": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "ENUM",
"name": "ProductStatus",
"ofType": null
}
}
},
"defaultValue": null
},
What am I missing? 👀
Issue Analytics
- State:
- Created 4 years ago
- Comments:6
Top Results From Across the Web
Setting a Default Value for Enums in C - Jaliya's Blog
Enums can be very useful in cases like where you want to maintain a set of named constants. Imagine you have following values,...
Read more >ENUM - MariaDB Knowledge Base
An ENUM can also contain NULL and empty values. If the ENUM column is declared to permit NULL values, NULL becomes a valid...
Read more >MySQL 8.0 Reference Manual :: 11.3.5 The ENUM Type
An ENUM is a string object with a value chosen from a list of permitted values that ... in situations where a column...
Read more >Attaching Values to Java Enum - Baeldung
By defining a finite set of values, the enum is more type safe than ... Given those limitations, the enum value alone is...
Read more >C# Language Tutorial => Default value for enum == ZERO
The default value for an enum is zero. If an enum does not define an item with a value of zero, its default...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Can’t say if it’s intended behaviour or not, but I’m always defining an intermediate Graphene Enum before using it in fields. Ad for default values, I’m passing the enum value, rather than enum property
Which gives me the following schema:
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.