graphql-python / graphql-python/graphene

Null Boolean Scalar

Aperta
#1,353 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
✨ enhancement
Lingua principale
Python
Stelle
8.2k
Fork
818
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

Im always frustrated when my model has a null able boolean field and the method `from graphene_django.types import construct_fields` returns a Boolean Scalar field which can only be True or False but not None

Some fields should not have a default for this types of boolean fields.

perhaps a scalar like this?

class NullBoolean(Scalar):
'''NullBoolean Scalar Description'''

@staticmethod
def serialize(dt):
return dt

@staticmethod
def parse_literal(node):
if isinstance(node, ast.StringValue):
if node.value == 'Yes':
return True
if node.value == 'No':
return False
return None

@staticmethod
def parse_value(value):
return value

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.