fix: added Scalar

This commit is contained in:
Laurent Riviere 2022-10-25 14:28:35 +00:00
parent 8cb9791342
commit 84237060f4
2 changed files with 17 additions and 4 deletions

View File

@ -151,8 +151,7 @@ class TypeMap(dict):
self[name] = graphql_type self[name] = graphql_type
return graphql_type return graphql_type
@staticmethod def create_scalar(self, graphene_type):
def create_scalar(graphene_type):
# We have a mapping to the original GraphQL types # We have a mapping to the original GraphQL types
# so there are no collisions. # so there are no collisions.
_scalars = { _scalars = {
@ -167,7 +166,7 @@ class TypeMap(dict):
return GrapheneScalarType( return GrapheneScalarType(
graphene_type=graphene_type, graphene_type=graphene_type,
name=graphene_type._meta.name, name=self.add_prefix_to_type_name(graphene_type._meta.name),
description=graphene_type._meta.description, description=graphene_type._meta.description,
serialize=getattr(graphene_type, "serialize", None), serialize=getattr(graphene_type, "serialize", None),
parse_value=getattr(graphene_type, "parse_value", None), parse_value=getattr(graphene_type, "parse_value", None),

View File

@ -10,7 +10,7 @@ from ..inputobjecttype import InputObjectType
from ..interface import Interface from ..interface import Interface
from ..mutation import Mutation from ..mutation import Mutation
from ..objecttype import ObjectType from ..objecttype import ObjectType
from ..scalars import Int, String from ..scalars import Int, String, Scalar
from ..schema import Schema from ..schema import Schema
from ..union import Union from ..union import Union
@ -19,6 +19,10 @@ class MyInputObjectType(InputObjectType):
field = String() field = String()
class MyScalar(Scalar):
...
class MyEnum(Enum): class MyEnum(Enum):
FOO = "foo" FOO = "foo"
BAR = "bar" BAR = "bar"
@ -35,6 +39,7 @@ class MyBarType(ObjectType):
class MyFooType(ObjectType): class MyFooType(ObjectType):
field = String() field = String()
my_scalar = MyScalar()
my_enum = MyEnum() my_enum = MyEnum()
@ -135,9 +140,12 @@ def test_schema_str():
type MyFooType { type MyFooType {
field: String field: String
myScalar: MyScalar
myEnum: MyEnum myEnum: MyEnum
} }
scalar MyScalar
enum MyEnum { enum MyEnum {
FOO FOO
BAR BAR
@ -201,9 +209,12 @@ def test_schema_type_name_prefix_camelcase():
type MyPrefixMyFooType { type MyPrefixMyFooType {
field: String field: String
myScalar: MyPrefixMyScalar
myEnum: MyPrefixMyEnum myEnum: MyPrefixMyEnum
} }
scalar MyPrefixMyScalar
enum MyPrefixMyEnum { enum MyPrefixMyEnum {
FOO FOO
BAR BAR
@ -265,9 +276,12 @@ def test_schema_type_name_prefix_camelcase_disabled():
type MyPrefixMyFooType { type MyPrefixMyFooType {
field: String field: String
my_scalar: MyPrefixMyScalar
my_enum: MyPrefixMyEnum my_enum: MyPrefixMyEnum
} }
scalar MyPrefixMyScalar
enum MyPrefixMyEnum { enum MyPrefixMyEnum {
FOO FOO
BAR BAR