I'm using graphene-django
to build my API. I have a DjangoObjectType named StoreType
which represents the model Store. This model has a MultiSelectField named opening_days
that indicates what days in the week the store is open. To create new stores, I use this mutation:
class Weekdays(graphene.Enum):
MO = "Mo"
TU = "Tu"
WE = "We"
TH = "Th"
FR = "Fr"
SA = "Sa"
SU = "Su"
class CreateStore(graphene.Mutation):
store = graphene.Field(StoreType)
class Arguments:
opening_days = graphene.Argument(graphene.List(Weekdays))
def mutate(self, info, opening_days):
store = Store(opening_days=opening_days)
store.save()
return CreateStore(store=store)
The mutation works perfectly. But then, when I try to query a store, I get the error "Expected a value of type \"StoreOpeningDays\" but received: Monday, Tuesday",
which makes sense really, because this field saves the data as a single string with the values separated by commas. The issue is that graphene is expecting the list specified in graphene.List(Weekdays)
which is impossible to retrieve.
Any ideas on how to fix this? Thanks in advance!
StoreType
? If the data is being stored in the db as expected you should just need to create a custom resolver for theopening_days
field onStoreType
to return the correct type. – Mckoy