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

Commit 330a1c7

Browse files
committed
Fixed keys_only query results
1 parent d20c5f8 commit 330a1c7

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

graphene_gae/ndb/fields.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ def connection_from_ndb_query(query, args={}, connection_type=None,
3939
except StopIteration:
4040
break
4141

42+
if keys_only:
43+
# entity is actualy an ndb.Key and we need to create an empty entity to hold it
44+
entity = edge_type.node_type._meta.model(key=entity)
45+
4246
edge = edge_type(node=entity, cursor=iter.cursor_after().urlsafe())
4347
edges.append(edge)
4448

tests/_ndb/test_types_relay.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,34 @@ def test_connectionField(self):
176176
self.assertLength(comments, 1)
177177
self.assertEqual(comments[0]['node']['body'], "c" + article['summary'])
178178

179+
def test_connectionField_keysOnly(self):
180+
a1 = Article(headline="Test1", summary="1").put()
181+
a2 = Article(headline="Test2", summary="2").put()
182+
a3 = Article(headline="Test3", summary="3").put()
183+
184+
Comment(parent=a1, body="c1").put()
185+
Comment(parent=a2, body="c2").put()
186+
Comment(parent=a3, body="c3").put()
187+
188+
result = schema.execute("""
189+
query Articles {
190+
articles(keysOnly: true) {
191+
edges {
192+
cursor,
193+
node {
194+
id
195+
}
196+
}
197+
198+
}
199+
}
200+
""")
201+
202+
self.assertEmpty(result.errors)
203+
204+
articles = result.data.get('articles', {}).get('edges')
205+
self.assertLength(articles, 3)
206+
179207
def test_connectionField_empty(self):
180208
Article(headline="Test1", summary="1").put()
181209

0 commit comments

Comments
 (0)