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
return graphql_type
@staticmethod
def create_scalar(graphene_type):
def create_scalar(self, graphene_type):
# We have a mapping to the original GraphQL types
# so there are no collisions.
_scalars = {
@ -167,7 +166,7 @@ class TypeMap(dict):
return GrapheneScalarType(
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,
serialize=getattr(graphene_type, "serialize", None),
parse_value=getattr(graphene_type, "parse_value", None),

View File

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