Skip to content

How to add pagination ? #416

Closed
Closed
@dmitry-saritasa

Description

@dmitry-saritasa

In the swapi star wars example:
https://github.com/graphql-python/swapi-graphene/blob/master/starwars/schema.py

class Film(DjangoObjectType):
    producers = graphene.List(graphene.String)

    @resolve_only_args
    def resolve_producers(self):
        return [c.strip() for c in self.producer.split(',')]

    '''A single film.'''
    class Meta:
        model = models.Film
        interfaces = (Node, )
        exclude_fields = ('created', 'edited', 'producer')
        filter_fields = {'episode_id': ('gt', )}

Film.Connection = connection_for_type(Film)

and query

class Query(graphene.ObjectType):
    all_films = DjangoFilterConnectionField(Film)

It seems 'after' keyword is not supported? (https://facebook.github.io/relay/docs/graphql-connections.html#content)

I tried the following query
http://swapi.graphene-python.org/graphql

query cinema($withCinemas: Boolean=false){
  ids: allFilms(first:1 after: "RmlsbToy") {
    edges {
      node {
        id
        title
      }
    }
  }
  allFilms  @include(if: $withCinemas) {
    edges {
      node {
        id
        title
        director
        releaseDate
      }
    }
  }
  
  part3: film(id: "RmlsbTox") {
    ...movieDetails
  }
  part4: film(id: "RmlsbToy") {
    ...movieDetails
  }
}

fragment movieDetails on Film {
  id
  title
   # pll	
   planets {
      edges {
        node {
          id
          name
          diameter
        }
      }
    }
    species {
      edges {
        node {
          id
          name
          classification
          eyeColors
        }
      }
    }
}

and always getting this

{
  "data": {
    "ids": {
      "edges": [
        {
          "node": {
            "id": "RmlsbTox",
            "title": "A New Hope"
          }
        }
      ]
    },
....
}

which is just the first in a row?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions