Skip to content

Convert UUID Type failed #233

@jingjinz

Description

@jingjinz

Hi, I'm currently have a node model as below:
class Node(BaseModel):
name = Column(String)
node_uuid = Column(UUIDType(binary=False), unique=True, nullable=False)

When I try to use the SQLAlchemyObjectType with the node model metaclass, it doesn't know how to convert type. The error message is as below:
File "/usr/local/lib/python3.7/site-packages/graphene_sqlalchemy/converter.py", line 119, in convert_sqlalchemy_type
% (column, column.class)
Exception: Don't know how to convert the SQLAlchemy field node.node_uuid (<class 'sqlalchemy.sql.schema.Column'>)

I noticed that we can register our custom type as discussed before (#53). So I have a method as below:
@convert_sqlalchemy_type.register(String)
@convert_sqlalchemy_type.register(UUIDType)
def convert_column_to_string(type, column, registry=None):
return graphene.String(description=get_column_doc(column),
required=not (is_column_nullable(column)))

But I don't know where to put this method and cannot find any example about it. May I know where this register method should be put? Or is there any other method i can use to convert this UUID type to String?

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