-
-
Notifications
You must be signed in to change notification settings - Fork 536
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--- | ||
title: Object is not an Enum Error | ||
--- | ||
|
||
# Object is not an Enum Error | ||
|
||
## Description | ||
|
||
This error is thrown when applying `@strawberry.enum` to a non-enum object, for | ||
example the following code will throw this error: | ||
|
||
```python | ||
import strawberry | ||
|
||
|
||
# note the lack of @strawberry.enum here: | ||
class NotAnEnum: | ||
A = "A" | ||
|
||
|
||
@strawberry.type | ||
class Query: | ||
field: NotAnEnum | ||
|
||
|
||
schema = strawberry.Schema(query=Query) | ||
``` | ||
|
||
This happens because Strawberry expects all enums to be subclasses of `Enum`. | ||
|
||
## How to fix this error | ||
|
||
You can fix this error by making sure the class you're applying | ||
`@strawberry.enum` to is a subclass of `Enum`. For example, the following code | ||
will fix this error: | ||
|
||
```python | ||
import strawberry | ||
|
||
|
||
@strawberry.enum | ||
class NotAnEnum: | ||
A = "A" | ||
|
||
|
||
@strawberry.type | ||
class Query: | ||
field: NotAnEnum | ||
|
||
|
||
schema = strawberry.Schema(query=Query) | ||
``` |