graphql-python / graphql-python/graphene

Null Boolean Scalar

Open
#1,353 0 comments 0 reactions 0 assignees View on GitHub
✨ enhancement
Dominant language
Python
Stars
8.2k
Forks
818
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.