graphql-python / graphene-django

Build powerful, efficient, and flexible GraphQL APIs with seamless Django integration.
http://docs.graphene-python.org/projects/django/en/latest/
MIT License
4.31k stars 769 forks source link

Pagination does not work with DjangoConnectionField #231

Closed Stormteller closed 7 years ago

Stormteller commented 7 years ago

I have node schema:

class DealNode(DjangoObjectType):
    class Meta:
        model = Deal
        interfaces = (relay.Node, )
        filter_fields = {
            'close_date': ['exact', 'gt', 'gte', 'lt', 'lte'],
            'buy_now_price': ['exact', 'gt', 'gte', 'lt', 'lte'],
            'is_featured': ['exact'],
            'is_best': ['exact']
        }

And Query:

class DealsQuery(AbstractType):
    deal = relay.Node.Field(DealNode)
    deals = DjangoFilterConnectionField(DealNode)

When I am trying to use some query with built-in pagination like:

query {
  deals(first: 2) {
    edges {
      node {
        id
        closeDate
      }
    }
    pageInfo {
      hasNextPage
      startCursor
      endCursor
    }
  }
}

I get the error:

{
  "data": {
    "deals": null
  },
  "errors": [
    {
      "message": "Cannot resolve keyword 'first' into field. Choices are: added, bid, buy_now_price, close_date, is_best, is_closed, is_featured, min_bid_increment, model_id, start_price, vehicle, vehicle_id, winner, winner_id",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ]
    }
  ]
}

What's the problem? And how to fix it?

brianjp93 commented 7 years ago

I would also like to know how indexing works. Does that "first" argument work?

japrogramer commented 7 years ago

The way I have pagination setup is more straight forward and takes advantage of the advantages and optimisations of Djangos Paginator https://github.com/graphql-python/graphene/issues/573

sachingaikwad123 commented 7 months ago

I am facing this problem. @Stormteller - How did you fix this?