Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for custom scalars #33

Open
Ambro17 opened this issue Jul 13, 2020 · 4 comments
Open

Add support for custom scalars #33

Ambro17 opened this issue Jul 13, 2020 · 4 comments

Comments

@Ambro17
Copy link

Ambro17 commented Jul 13, 2020

No description provided.

@ethe
Copy link
Owner

ethe commented Jul 15, 2020

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

  • Allow user to declare scalar types
  • custom scalar types can be printed as a schema: https://graphql.org/learn/schema/#scalar-types
  • Allow client transfer string values and load them from string to Python types (Datetime, UUID, etc.) which declared in scalar types

@ethe
Copy link
Owner

ethe commented Jul 15, 2020

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
Copy link
Author

Ambro17 commented Jul 19, 2020

Should I solve the first three items on this issue?

@ethe
Copy link
Owner

ethe commented Jul 20, 2020

Yeah, I am glad to hear that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants