diff --git a/graphene/types/tests/test_type_name_prefix.py b/graphene/types/tests/test_type_name_prefix.py index add188ae..49cb9b0a 100644 --- a/graphene/types/tests/test_type_name_prefix.py +++ b/graphene/types/tests/test_type_name_prefix.py @@ -1,6 +1,5 @@ from textwrap import dedent - from ..field import Field from ..enum import Enum from ..inputobjecttype import InputObjectType @@ -12,153 +11,6 @@ from ..schema import Schema from ..union import Union -def test_schema_type_name_prefix_override(): - class MyInputObjectType(InputObjectType): - class Meta: - type_name_prefix = "OverridePrefix" - - field = String() - - class MyScalar(Scalar): - class Meta: - type_name_prefix = "" - - class MyEnum(Enum): - class Meta: - type_name_prefix = "" - - FOO = "foo" - BAR = "bar" - - class MyInterface(Interface): - class Meta: - type_name_prefix = "" - - field = String() - - class MyBarType(ObjectType): - class Meta: - type_name_prefix = "" - - field = String(input=MyInputObjectType()) - my_interface = Field(MyInterface) - my_scalar = MyScalar() - my_enum = MyEnum() - - class MyFooType(ObjectType): - class Meta: - type_name_prefix = "" - - field = String() - - class MyUnion(Union): - class Meta: - type_name_prefix = "" - types = (MyBarType, MyFooType) - - class MyType(ObjectType): - class Meta: - type_name_prefix = "" - - field = String() - my_union = MyUnion() - my_bar_type = Field(MyBarType) - - class Query(ObjectType): - class Meta: - type_name_prefix = "OverridePrefix" - - inner = Field(MyType) - - class CreateUser(Mutation_): - class Meta: - type_name_prefix = "" - - class Arguments: - name = String() - - name = String() - - def mutate(self, info, name): - return CreateUser(name=name) - - class Mutation(ObjectType): - class Meta: - type_name_prefix = "" - - create_user = CreateUser.Field() - - class Subscription(ObjectType): - class Meta: - type_name_prefix = "" - - count_to_ten = Field(Int) - - schema = Schema( - Query, - Mutation, - Subscription, - auto_camelcase=True, - type_name_prefix="MyPrefix", - ) - assert ( - str(schema).strip() - == dedent( - """ - type Query { - overridePrefixInner: MyType - } - - type MyType { - field: String - myUnion: MyUnion - myBarType: MyBarType - } - - union MyUnion = MyBarType | MyFooType - - type MyBarType { - field(input: OverridePrefixMyInputObjectType): String - myInterface: MyInterface - myScalar: MyScalar - myEnum: MyEnum - } - - input OverridePrefixMyInputObjectType { - field: String - } - - interface MyInterface { - field: String - } - - scalar MyScalar - - enum MyEnum { - FOO - BAR - } - - type MyFooType { - field: String - } - - type Mutation { - createUser(name: String): CreateUser - } - - type CreateUser { - name: String - } - - type Subscription { - countToTen: Int - } - """ - ).strip() - ) - - class MyInputObjectType(InputObjectType): field = String() @@ -351,3 +203,150 @@ def test_schema_type_name_prefix_camelcase_disabled(): """ ).strip() ) + + +def test_schema_type_name_prefix_override(): + class MyInputObjectType(InputObjectType): + class Meta: + type_name_prefix = "OverridePrefix" + + field = String() + + class MyScalar(Scalar): + class Meta: + type_name_prefix = "" + + class MyEnum(Enum): + class Meta: + type_name_prefix = "" + + FOO = "foo" + BAR = "bar" + + class MyInterface(Interface): + class Meta: + type_name_prefix = "" + + field = String() + + class MyBarType(ObjectType): + class Meta: + type_name_prefix = "" + + field = String(input=MyInputObjectType()) + my_interface = Field(MyInterface) + my_scalar = MyScalar() + my_enum = MyEnum() + + class MyFooType(ObjectType): + class Meta: + type_name_prefix = "" + + field = String() + + class MyUnion(Union): + class Meta: + type_name_prefix = "" + types = (MyBarType, MyFooType) + + class MyType(ObjectType): + class Meta: + type_name_prefix = "" + + field = String() + my_union = MyUnion() + my_bar_type = Field(MyBarType) + + class Query(ObjectType): + class Meta: + type_name_prefix = "OverridePrefix" + + inner = Field(MyType) + + class CreateUser(Mutation_): + class Meta: + type_name_prefix = "" + + class Arguments: + name = String() + + name = String() + + def mutate(self, info, name): + return CreateUser(name=name) + + class Mutation(ObjectType): + class Meta: + type_name_prefix = "" + + create_user = CreateUser.Field() + + class Subscription(ObjectType): + class Meta: + type_name_prefix = "" + + count_to_ten = Field(Int) + + schema = Schema( + Query, + Mutation, + Subscription, + auto_camelcase=True, + type_name_prefix="MyPrefix", + ) + assert ( + str(schema).strip() + == dedent( + """ + type Query { + overridePrefixInner: MyType + } + + type MyType { + field: String + myUnion: MyUnion + myBarType: MyBarType + } + + union MyUnion = MyBarType | MyFooType + + type MyBarType { + field(input: OverridePrefixMyInputObjectType): String + myInterface: MyInterface + myScalar: MyScalar + myEnum: MyEnum + } + + input OverridePrefixMyInputObjectType { + field: String + } + + interface MyInterface { + field: String + } + + scalar MyScalar + + enum MyEnum { + FOO + BAR + } + + type MyFooType { + field: String + } + + type Mutation { + createUser(name: String): CreateUser + } + + type CreateUser { + name: String + } + + type Subscription { + countToTen: Int + } + """ + ).strip() + )