Table of Contents

Graphql Enum

code

import strawberry
from enum import Enum


@strawberry.enum
class IceCreamFlavour(Enum):
    VANILLA = "vanilla"
    STRAWBERRY = "strawberry"
    CHOCOLATE = "chocolate"


@strawberry.type
class EnumQuery:
    @strawberry.field
    def best_flavour(self) -> IceCreamFlavour:
        return IceCreamFlavour.STRAWBERRY

query

{ bestFlavour }

result

{
  "data": {
    "bestFlavour": "STRAWBERRY"
  }
}