def test_field_resolve_type_custom(): s = Schema() f = Field('self') f.contribute_to_class(ot, 'field_name') field_type = f.get_object_type(s) assert field_type == ot
def test_field_none_type_raises_error(): s = Schema() f = Field(None) f.contribute_to_class(ot, 'field_name') with raises(Exception) as excinfo: f.internal_field(s) assert str(excinfo.value) == "Internal type for field ObjectType.field_name is None"
def test_field_none_type_raises_error(): s = Schema() f = Field(None) f.contribute_to_class(MyOt, 'field_name') with raises(Exception) as excinfo: s.T(f) assert str( excinfo.value) == "Internal type for field MyOt.field_name is None"
def test_field_resolve_type_custom(): class MyCustomType(ObjectType): pass class OtherType(ObjectType): pass s = Schema() f = Field('MyCustomType') f.contribute_to_class(OtherType, 'field_name') field_type = f.get_object_type(s) assert field_type == MyCustomType
def inner_field(self, schema): from graphene.relay.types import BaseNode node_field = BaseNode.get_definitions(schema).node_field def resolver(instance, args, info): global_id = args.get('id') resolved_global_id = from_global_id(global_id) if resolved_global_id.type == self.field_object_type._meta.type_name: return node_field.resolver(instance, args, info) args = OrderedDict([(a.name, a) for a in node_field.args]) field = Field(self.field_object_type, id=args['id'], resolve=resolver) field.contribute_to_class(self.object_type, self.field_name) return field
def test_field_resolve_type_custom(): class MyCustomType(object): pass class Schema(object): def get_type(self, name): if name == 'MyCustomType': return MyCustomType s = Schema() f = Field('MyCustomType') f.contribute_to_class(ot, 'field_name') field_type = f.get_object_type(s) assert field_type == MyCustomType
def test_field_name_use_name_if_exists(): f = Field(GraphQLString, name='my_custom_name') f.contribute_to_class(MyOt, 'field_name') assert f.name == 'my_custom_name'
def test_field_name(): f = Field(GraphQLString) f.contribute_to_class(MyOt, 'field_name') assert f.name is None assert f.attname == 'field_name'
def test_field_type(): f = Field(GraphQLString) f.contribute_to_class(MyOt, 'field_name') assert isinstance(schema.T(f), GraphQLField) assert schema.T(f).type == GraphQLString
def test_field_name_automatic_camelcase(): f = Field(GraphQLString) f.contribute_to_class(ot, 'field_name') assert f.name == 'fieldName'
def test_field_type(): f = Field(GraphQLString) f.contribute_to_class(ot, 'field_name') assert isinstance(f.internal_field(schema), GraphQLField) assert f.internal_type(schema) == GraphQLString
def test_field_name_automatic_camelcase(): f = Field(GraphQLString) f.contribute_to_class(MyOt, 'field_name') assert f.name == 'fieldName'