Skip to content

Add connection_from_list_slice support to Connection - #201

Closed
Globegitter wants to merge 8 commits into
graphql-python:masterfrom
Globegitter:patch-6
Closed

Globegitter wants to merge 8 commits into
graphql-python:masterfrom
Globegitter:patch-6

Conversation

@Globegitter

Copy link
Copy Markdown

This allows to return e.g. Connection.for_node(Node).from_list([1, 2, 3, 4], args, context, info, 5389) to get pagination support for sliced lists.

This allows to return e.g. `Connection.for_node(Node).from_list([1, 2, 3, 4], args, context, info, 5389)` to get pagination support for sliced lists.
@mjtamlyn

mjtamlyn commented Jun 8, 2016

Copy link
Copy Markdown
Contributor

This looks like a good way to allow simple optimisations.

@coveralls

coveralls commented Jun 8, 2016 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.006%) to 96.15% when pulling 40705d3 on Globegitter:patch-6 into 1711e6a on graphql-python:master.

@Globegitter

Copy link
Copy Markdown
Author

Not sure why the test is failing. Will investigate tomorrow.

@coveralls

coveralls commented Jun 13, 2016 •

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.1%) to 96.047% when pulling 6f8b03d on Globegitter:patch-6 into 1711e6a on graphql-python:master.

@coveralls

coveralls commented Jun 13, 2016 •

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.1%) to 96.047% when pulling a821f19 on Globegitter:patch-6 into 1711e6a on graphql-python:master.

@Globegitter

Copy link
Copy Markdown
Author

Actually on top of that it would also be nice to be able to not pass in the count, but instead hasNextPage or hasPreviousPage. Just starting to write our pagination and some of our service will return these values directly. Just a note for myself.

@Globegitter

Copy link
Copy Markdown
Author

@Globegitter

Copy link
Copy Markdown
Author

We have now actually resorted to create the connection and edges ourselves like so:

def _create_statement_edge(statement):
    edge_type = relay.Edge.for_node(StatementEntry)
    return edge_type(node=statement, cursor=base64.b64encode(str(statement.id)))

...
def resolve_bla(...):
    pagination_param = base64.b64decode(args['after']) if args.get('after') else None

    statements, has_next_page  = call_to_database_service(pagination_param)

    edges = [_create_statement_edge(statement) for statement in statements]
    connection_type = relay.Connection.for_node(StatementEntry)

    return connection_type(edges=edges, page_info=relay.PageInfo(has_next_page=has_next_page))

There is a bug though with returning connection_type in this way, which I fixed here: #237

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants