Graphene-django: `after` and `before` ignored when using a DjangoConnectionField.

Created on 23 Sep 2018  路  2Comments  路  Source: graphql-python/graphene-django

Specifying after or before does not change the result of a query, nor does it throw and error.

Example:

class Person(models.Model):
    name = models.CharField(max_length=50, help_text="Property number or name")

class PersonType(DjangoObjectType):
    class Meta:
        model = Property
        interfaces = (relay.Node, )

    node = relay.Node.Field()

class PersonConnection(relay.Connection):
    class Meta:
        node = PropertyType

class Query(graphene.ObjectType):
    node = relay.Node.Field()
    people = DjangoFilterField(Person)

Performing the query:

query {
  people(first: 2) {
    edges {
      node {
        id
        name
      }
    }
  }
}

Returns:

{
  "data": {
    "people": {
      "edges": [
        {
          "node": {
            "id": "UHJvcGVydHlUeXBlOjE=",
            "name": "Hannah"
          }
        },
        {
          "node": {
            "id": "UHJvcGVydHlUeXBlOjI=",
            "name": "Steve"
          }
        }
      ]
    }
  }
}

And performing:

query {
  people(first: 2, after: "UHJvcGVydHlUeXBlOjI=") {
    edges {
      node {
        id
        name
      }
    }
  }
}

Returns exactly the same: "Hannah" and "Steve".

I feel as though I'm missing something, but I have tried this out on two separate projects and the problem persists - any guidance is hugely appreciated!

Most helpful comment

@jckw "after" is not an id but a "relay cursor", it usually maintained by relay on client and response looks like that:

screenshot from 2018-09-24 23-48-39

In [3]: base64.decodebytes(b'YXJyYXljb25uZWN0aW9uOjk=')
Out[3]: b'arrayconnection:9'

You can try to add cursor field to your query:

query {
  people(first: 2) {
    edges {
      node {
        id
        name
      }
      cursor
    }
    pageInfo {
      endCursor
      hasNextPage
    }
  }
}

All 2 comments

@jckw "after" is not an id but a "relay cursor", it usually maintained by relay on client and response looks like that:

screenshot from 2018-09-24 23-48-39

In [3]: base64.decodebytes(b'YXJyYXljb25uZWN0aW9uOjk=')
Out[3]: b'arrayconnection:9'

You can try to add cursor field to your query:

query {
  people(first: 2) {
    edges {
      node {
        id
        name
      }
      cursor
    }
    pageInfo {
      endCursor
      hasNextPage
    }
  }
}

Thank you so much @kalekseev! Works as expected. Should've read the Relay docs more closely 馃槵

Was this page helpful?
0 / 5 - 0 ratings

Related issues

eyalch picture eyalch  路  3Comments

Dawidpol picture Dawidpol  路  4Comments

MilanRgm picture MilanRgm  路  3Comments

licx picture licx  路  3Comments

timothyjlaurent picture timothyjlaurent  路  3Comments