Ejemplo n.º 1
0
    def __init__(self, _type, *args, **kwargs):

        if isinstance(_type, NonNull):
            _type = _type.of_type
        self.django_type = _type

        kwargs.setdefault("limit", Int())
        kwargs.setdefault("offset", Int())
        super(DjangoListField, self).__init__(List(_type), *args, **kwargs)
Ejemplo n.º 2
0
 def type(self):
     _type = super().type
     if self.resolve_to_object_type:
         return type(f"{_type._meta.name}ListResults",
                     (graphene.ObjectType, NonNull), {
                         "docs": graphene.List(_type),
                         "total": graphene.Int()
                     })
     else:
         return List(_type)
Ejemplo n.º 3
0
    def __init__(self, _type, *args, **kwargs):
        from .types import DjangoObjectType

        if isinstance(_type, NonNull):
            _type = _type.of_type

        # Django would never return a Set of None  vvvvvvv
        super(DjangoListField, self).__init__(List(NonNull(_type)), *args, **kwargs)

        assert issubclass(
            self._underlying_type, DjangoObjectType
        ), "DjangoListField only accepts DjangoObjectType types"
Ejemplo n.º 4
0
 def __init__(self, _type, *args, **kwargs):
     super(DjangoListField, self).__init__(List(_type), *args, **kwargs)
Ejemplo n.º 5
0
    def __init_subclass_with_meta__(cls, node=None, name=None, **options):
        _meta = ConnectionOptions(cls)
        assert node, "You have to provide a node in {}.Meta".format(
            cls.__name__)
        assert isinstance(node, NonNull) or issubclass(
            node, (Scalar, Enum, ObjectType, Interface, Union, NonNull)), (
                'Received incompatible node "{}" for Connection {}.').format(
                    node, cls.__name__)

        base_name = re.sub("Connection$", "", name
                           or cls.__name__) or node._meta.name
        if not name:
            name = "{}Connection".format(base_name)

        edge_class = getattr(cls, "Edge", None)
        _node = node

        class EdgeBase(object):
            node = Field(_node, description="The item at the end of the edge")
            cursor = String(required=True,
                            description="A cursor for use in pagination")

        class EdgeMeta:
            description = "A Relay edge containing a `{}` and its cursor.".format(
                base_name)

        edge_name = "{}Edge".format(base_name)
        if edge_class:
            edge_bases = (edge_class, EdgeBase, ObjectType)
        else:
            edge_bases = (EdgeBase, ObjectType)

        edge = type(edge_name, edge_bases, {"Meta": EdgeMeta})
        cls.Edge = edge

        from graphene_elastic.types.json_string import JSONString

        options["name"] = name
        _meta.node = node
        _meta.fields = OrderedDict([
            (
                "page_info",
                Field(
                    PageInfo,
                    name="pageInfo",
                    required=True,
                    description="Pagination data for this connection.",
                ),
            ),
            (
                "edges",
                Field(
                    NonNull(List(edge)),
                    description="Contains the nodes in this connection.",
                ),
            ),
            # TODO: Construct this dynamically from the filter backends.
            (
                "facets",
                Field(
                    JSONString,
                    name="facets",
                    required=False,
                    description="Pagination data for this connection.",
                ),
            ),
        ])
        # for backend_cls in backends:
        #     if backend_cls.has_connection_fields:
        #         backend = backend_cls()
        #         connection_fields_type = backend.get_backend_connection_fields_type()
        #         if connection_fields_type:
        #             try:
        #                 _meta.fields.update(connection_fields_type)
        #             except:
        #                 pass
        return super(Connection, cls).__init_subclass_with_meta__(_meta=_meta,
                                                                  **options)
Ejemplo n.º 6
0
 def __init__(self, _type, *args, **kwargs):
     # Django would never return a Set of None  vvvvvvv
     super(DjangoListField, self).__init__(List(NonNull(_type)), *args,
                                           **kwargs)
Ejemplo n.º 7
0
 def __init__(self, _type, *args, **kwargs):
     self.permission_classes = kwargs.pop("permission_classes", None)
     super(DjangoListField, self).__init__(List(_type), *args, **kwargs)