graphql-python / graphene-pydantic

Integrate GraphQL with your Pydantic models
Other
229 stars 44 forks source link

The current supported type is inconsistent with the type supported by pydantic #15

Closed hyu9999 closed 4 years ago

hyu9999 commented 4 years ago

The current supported type is inconsistent with the type supported by pydantic ,for example EmailStr UrlStr etc.

dantheman39 commented 4 years ago

Hi! I'm not exactly sure what the desired behavior is, could you maybe post a more explicit description, ideally a pseudo-code sample?

dantheman39 commented 4 years ago

Closing due to inactivity

michael-koenig commented 4 years ago

Hi! I could use that functionality, too!

Problem is the missing mapping of new pydantic data types, such as "EmailStr" or "UUID4", to graphene data types.

Example pydantic model:

from pydantic import BaseModel, EmailStr, UUID4, HttpUrl

class User(BaseModel):
    id: UUID4
    name: str
    email: EmailStr
    profileImage: HttpUrl

My idea was to either 1) extend "find_graphene_type" in converters.py @ line 140 (kinda hardcoding it...) or

2) extend the registry with a function similar to:

registry.add_data_type_mapping(from=Pydanitc.EmailStr, to=str)
registry.add_data_type_mapping(from=Pydanitc.HttpUrl, to=str)
registry.add_data_type_mapping(from=Pydanitc.UUID4, to=uuid.UUID)

and then applying the existing converter-function.

3) or use the "type"-value that pydantic provides - as used in ".schema_json()" :

... "email": {"title": "Email", "type": "string", "format": "email"} ...

(thank you for the package btw^^)

necaris commented 4 years ago

@michael-koenig I like your second suggestion! Would you be interested in making a pull request to implement it?

michael-koenig commented 4 years ago

@necaris Sure, I can certainly give it a try :)

necaris commented 4 years ago

@dantheman39 and I are here to help if you need anything -- looking forward to your contribution!