ethe / pygraphy

A modern Pythonic GraphQL implementation.
MIT License
92 stars 13 forks source link

Add support for custom scalars #33

Open Ambro17 opened 4 years ago

ethe commented 4 years ago

In my opinion, there are several objectives we need to implement:

ethe commented 4 years ago

Maybe we should create a new metaclass called ScalarType and a root class called Scalar, then users could create their custom scalar types as objects of this metaclass by inheriting Scalar. There are some use cases:

from pygraphy import ScalarType

class Scalar(metaclass=ScalarType):
    # defined in pygraphy, implement some default method
    ...

class UUID(Scalar):
    def load(self, string: str) -> pyUUID:
        return pyUUID(string)

    def dump(self) -> str:
        return str(self.value)  # value is defined in `Scalar` class maybe

then UUID can be used as a normal type when declaring models:

class Foo(pygraphy.Object):
    id: UUID
Ambro17 commented 4 years ago

Should I solve the first three items on this issue?

ethe commented 4 years ago

Yeah, I am glad to hear that.