示例#1
0
    def resolve_id(self, args, context, info):
        graphene_type = info.parent_type.graphene_type
        if is_node(graphene_type):
            PynamoObjectType.inspect_model(graphene_type._meta.model)
            return getattr(self, graphene_type._meta.model._meta_table.hash_keyname)

        return getattr(args, graphene_type._meta.id)
示例#2
0
    def __init__(self,
                 type,
                 fields=None,
                 extra_filter_meta=None,
                 filterset_class=None,
                 *args,
                 **kwargs):

        if is_node(type):
            _fields = type._meta.filter_fields
            _model = type._meta.model
        else:
            # ConnectionFields can also be passed Connections,
            # in which case, we need to use the Node of the connection
            # to get our relevant args.
            _fields = type._meta.node._meta.filter_fields
            _model = type._meta.node._meta.model

        self.fields = fields or _fields
        meta = dict(model=_model, fields=self.fields)
        if extra_filter_meta:
            meta.update(extra_filter_meta)
        self.filterset_class = get_filterset_class(filterset_class, **meta)
        self.filtering_args = get_filtering_args_from_filterset(
            self.filterset_class, type)
        kwargs.setdefault('args', {})
        kwargs['args'].update(self.filtering_args)
        super(DjangoFilterConnectionField,
              self).__init__(type, *args, **kwargs)
示例#3
0
    def dynamic_type():
        _type = registry.get_type_for_model(model)
        if not _type:
            return

        if is_node(_type):
            return get_connection_field(_type)
        return Field(List(_type))
示例#4
0
    def dynamic_type():
        _type = registry.get_type_for_model(model)
        if not _type:
            return

        if is_node(_type):
            return get_connection_field(_type)
        return Field(List(_type))
示例#5
0
 def dynamic_type():
     _type = registry.get_type_for_model(model)
     if not _type:
         return None
     if (direction == interfaces.MANYTOONE or not relationship.uselist):
         return Field(_type)
     elif (direction == interfaces.ONETOMANY
           or direction == interfaces.MANYTOMANY):
         if is_node(_type):
             return SQLAlchemyConnectionField(_type)
         return Field(List(_type))
    def dynamic_type():
        _type = registry.get_type_for_model(model)
        if not _type:
            return

        if isinstance(field.field, models.OneToOneField):
            return Field(_type)

        if is_node(_type):
            return get_connection_field(_type)
        return DjangoListField(_type)
示例#7
0
    def __init__(self, type: Union[ObjectType, None] = None, **kwargs):
        if type:
            assert issubclass(type, ObjectType), "Object is not an ObjectType."
            assert is_node(type), "Object is not a Node."
        self.__type = type

        super(NodeField, self).__init__(
            type or Node,
            id=ID(required=True, description="The ID of the object."),
            **kwargs,
        )
示例#8
0
 def resolve_id(self, args, context, info):
     if self.id < 0:
         # this is a temporary object we created manually in resolve_landing_page_modules
         return self.id
     else:
         # this is a SQLAlchemy object
         # we can't use super here, so we just copy/paste resolve_id method from SQLAlchemyObjectType class
         from graphene.relay import is_node
         graphene_type = info.parent_type.graphene_type
         if is_node(graphene_type):
             return self.__mapper__.primary_key_from_instance(self)[0]
         return getattr(self, graphene_type._meta.id, None)
示例#9
0
 def resolve_id(self, args, context, info):
     if self.id < 0:
         # this is a temporary object we created manually in resolve_landing_page_modules
         return self.id
     else:
         # this is a SQLAlchemy object
         # we can't use super here, so we just copy/paste resolve_id method from SQLAlchemyObjectType class
         from graphene.relay import is_node
         graphene_type = info.parent_type.graphene_type
         if is_node(graphene_type):
             return self.__mapper__.primary_key_from_instance(self)[0]
         return getattr(self, graphene_type._meta.id, None)
示例#10
0
    def type(self):
        type = super(ConnectionField, self).type
        connection_type = type
        if isinstance(type, graphene.NonNull):
            connection_type = type.of_type

        if is_node(connection_type):
            raise Exception(
                "ConnectionFields now need a explicit ConnectionType for Nodes.\n"
                "Read more: https://github.com/graphql-python/graphene/blob/v2.0.0/"
                "UPGRADE-v2.0.md#node-connections")

        assert issubclass(connection_type, Connection), (
            '{} type have to be a subclass of Connection. Received "{}".'
        ).format(self.__class__.__name__, connection_type)
        return type
示例#11
0
def test_object_type():


    class Human(SQLAlchemyObjectType):
        '''Human description'''

        pub_date = Int()

        class Meta:
            model = Article
            # exclude_fields = ('id', )
            registry = registry
            interfaces = (Node, )

    assert issubclass(Human, ObjectType)
    assert list(Human._meta.fields.keys()) == ['id', 'headline', 'pub_date', 'reporter_id', 'reporter']
    assert is_node(Human)
def test_object_type():
    class Human(SQLAlchemyObjectType):
        '''Human description'''

        pub_date = Int()

        class Meta:
            model = Article
            # exclude_fields = ('id', )
            registry = registry
            interfaces = (Node, )

    assert issubclass(Human, ObjectType)
    assert list(Human._meta.fields.keys()) == [
        'id', 'headline', 'pub_date', 'reporter_id', 'reporter'
    ]
    assert is_node(Human)
示例#13
0
    def __init__(self,
                 type,
                 fields=None,
                 extra_filter_meta=None,
                 filterset_class=None,
                 *args,
                 **kwargs):

        base = type if is_node(type) else type._meta.node

        self.fields = fields or base._meta.filter_fields
        meta = dict(model=base._meta.model, fields=self.fields)
        if extra_filter_meta:
            meta.update(extra_filter_meta)
        self.filterset_class = get_filterset_class(filterset_class, **meta)
        self.filtering_args = get_filtering_args_from_filterset(
            self.filterset_class, base)
        kwargs.setdefault('args', {})
        kwargs['args'].update(self.filtering_args)
        super(DjangoFilterConnectionField,
              self).__init__(type, *args, **kwargs)
示例#14
0
def test_object_type():
    assert issubclass(Human, ObjectType)
    assert list(Human._meta.fields.keys()) == ['id', 'headline', 'reporter_id', 'reporter', 'pub_date']
    assert is_node(Human)
示例#15
0
 def resolve_id(root, args, context, info):
     graphene_type = info.parent_type.graphene_type
     if is_node(graphene_type):
         return root.__mapper__.primary_key_from_instance(root)[0]
     return getattr(root, graphene_type._meta.id, None)
示例#16
0
def test_object_type():
    assert issubclass(Human, ObjectType)
    assert list(Human._meta.fields.keys()) == [
        'id', 'headline', 'reporter_id', 'reporter', 'pub_date'
    ]
    assert is_node(Human)
示例#17
0
 def resolve_id(self, args, context, info):
     graphene_type = info.parent_type.graphene_type
     if is_node(graphene_type):
         keys = self.__mapper__.primary_key_from_instance(self)
         return tuple(keys) if len(keys) > 1 else keys[0]
     return getattr(self, graphene_type._meta.id, None)
示例#18
0
def test_object_type():
    assert issubclass(Human, ObjectType)
    assert set(Human._meta.fields.keys()) == set(
        ["id", "headline", "pub_date", "editor", "reporter"])
    assert is_node(Human)
示例#19
0
def test_object_type():
    assert issubclass(Human, ObjectType)
    assert set(Human._meta.fields.keys()) == set(
        ['id', 'headline', 'pub_date', 'editor', 'reporter'])
    assert is_node(Human)
示例#20
0
 def resolve_id(self, info):
     graphene_type = info.parent_type.graphene_type
     if is_node(graphene_type):
         return getattr(self, get_key_name(graphene_type._meta.model))
示例#21
0
 def resolve_id(root, args, context, info):
     graphene_type = info.parent_type.graphene_type
     if is_node(graphene_type):
         return root.__mapper__.primary_key_from_instance(root)[0]
     return getattr(root, graphene_type._meta.id, None)