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

Commit 0e12eb2

Browse files
committed
Merge pull request #10 from graphql-python/feature/ndb_connection_keys_only
Feature/ndb connection keys only
2 parents a9dc427 + e5482a3 commit 0e12eb2

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

HISTORY.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
History
44
-------
55

6+
0.1.4 (TBD)
7+
---------------------
8+
* NdbConnectionField added arguments that can be used in quert:
9+
* keys_only - to execute a keys only query
10+
* batch_size - to control the NDB query iteration batch size
11+
12+
613
0.1.3 (2016-05-27)
714
---------------------
815
* Added `graphene_gae.webapp2.GraphQLHandler` - a basic HTTP Handler to process GraphQL requests

graphene_gae/ndb/fields.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from graphene import relay
55
from graphene.core.exceptions import SkipField
66
from graphene.core.types.base import FieldType
7+
from graphene.core.types.scalars import Boolean, Int
78

89
__author__ = 'ekampf'
910

@@ -24,9 +25,11 @@ def connection_from_ndb_query(query, args={}, connection_type=None,
2425
first = full_args.get('first')
2526
after = full_args.get('after')
2627
has_previous_page = bool(after)
28+
keys_only = full_args.get('keys_only', False)
29+
batch_size = full_args.get('batch_size', 10)
2730
start_cursor = ndb.Cursor(urlsafe=after) if after else None
2831

29-
iter = query.iter(produce_cursors=True, start_cursor=start_cursor, batch_size=10)
32+
iter = query.iter(produce_cursors=True, start_cursor=start_cursor, batch_size=batch_size, keys_only=keys_only)
3033

3134
page_size = first if first else 10
3235
edges = []
@@ -65,9 +68,16 @@ def from_list(cls, ndb_query, args, context, info):
6568

6669

6770
class NdbConnectionField(relay.ConnectionField):
68-
def __init__(self, *args, **kwargs):
71+
def __init__(self, type, **kwargs):
6972
kwargs['connection_type'] = kwargs.pop('connection_type', NdbConnection)
70-
super(NdbConnectionField, self).__init__(*args, **kwargs)
73+
super(NdbConnectionField, self).__init__(
74+
type,
75+
keys_only=Boolean(),
76+
batch_size=Int(),
77+
**kwargs)
78+
79+
if not self.default:
80+
self.default = self.model.query()
7181

7282
@property
7383
def model(self):

tests/_ndb/test_types_relay.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ def resolve_comments(self, args, info):
4545
class QueryRoot(graphene.ObjectType):
4646
articles = NdbConnectionField(ArticleType)
4747

48-
def resolve_articles(self, args, info):
49-
return Article.query()
50-
5148

5249
schema.query = QueryRoot
5350

0 commit comments

Comments
 (0)