Skip to content

Unable to return Null/None in a custom Scalar type #255

@McPo

Description

@McPo

Attempting to return None if the image is a blank string

class Image(graphene.types.Scalar):

    @staticmethod
    def serialize(image):
        return image.url if image else None

    @staticmethod
    def parse_literal(node):
        return None

    @staticmethod
    def parse_value(value):
        return None

but am receiving the following error

graphql.error.base.GraphQLError: Expected a value of type "Image" but received:

Going by the comment at https://github.com/graphql-python/graphql-core/blob/master/graphql/execution/executor.py#L615 this should be possible, however the code does not imply that its possible.

There appears to be PRs for this feature (By adding an explicit NullValue)
graphql-python/graphql-core#119
graphql-python/graphql-core#172

But it appears this issue isn't gonna be fixed until graphql-core-next is released. Ive attempted to install the next alpha version along with graphene-django but it seems unhappy. (Are they currently incompatible)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions