Skip to content
This repository was archived by the owner on Sep 6, 2022. It is now read-only.

Support for mapping\filtering entities in ndb connection field #25

Merged
merged 4 commits into from
Nov 22, 2016
Merged

Support for mapping\filtering entities in ndb connection field #25

merged 4 commits into from
Nov 22, 2016

Conversation

davidis1
Copy link
Contributor

This PR contains support for post NDB query interference to achieve mapping and filtering of entities fetched by NDB queries resolved within NDBConnectionFields.

It's very useful in situations where there's a many to many relation between two NDB models and you need to paginate over them.
See the added tests for an example.

Example explained -
A new Reader model was added. Each reader may have read multiple articles, and each article may have been read by multiple readers. The many to many relation is implemented using the ArticleReader model which represents that some reader has read an article and contains the reader key and article key.
Now, in order to paginate over all the article readers, the readers property was added to ArticleType:
readers = NdbConnectionField(ReaderType, entities_mapper=readers_mapper, entity_filter=reader_filter)
Notice that ArticleType's resolve_readers returns a query for all the ArticleReader entities.
Upon resolving it readers_mapper is called and maps each article reader to the appropriate reader.
Later we filter the readers in reader_filter and only return the readers that are alive.

@davidis1
Copy link
Contributor Author

@ekampf please review.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.05%) to 91.711% when pulling 05eb67a on davidis1:feature/mapping_entities_in_connection_field into f886661 on graphql-python:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.07%) to 91.826% when pulling 40d0409 on davidis1:feature/mapping_entities_in_connection_field into f886661 on graphql-python:master.

@ekampf ekampf merged commit a1f7c56 into graphql-python:master Nov 22, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants