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

Commit ced56d8

Browse files
committed
Merge pull request #15 from graphql-python/feature/id_to_key
NdbNode.global_id_to_key utility method
2 parents 521e1cc + 172049e commit ced56d8

File tree

5 files changed

+21
-2
lines changed

5 files changed

+21
-2
lines changed

HISTORY.rst

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

6+
0.1.6 (TBD)
7+
---------------------
8+
* Added NdbNode.global_id_to_key [PR #15](https://github.com/graphql-python/graphene-gae/pull/15)
9+
610
0.1.5 (2016-06-08)
711
---------------------
812
* Fixed behavior of ndb.KeyProperty ([PR #14](https://github.com/graphql-python/graphene-gae/pull/14))

graphene_gae/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
)
1313

1414
__author__ = 'Eran Kampf'
15-
__version__ = '0.1.5'
15+
__version__ = '0.1.6'
1616

1717
__all__ = [
1818
NdbObjectType,

graphene_gae/ndb/types.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from graphene.core.classtypes.objecttype import ObjectType, ObjectTypeMeta
66

77
from google.appengine.ext import ndb
8+
from graphql_relay import from_global_id
89

910
from .options import NdbOptions
1011

@@ -96,6 +97,11 @@ def to_global_id(self):
9697
entity_id = self.key.urlsafe() if self.key else None
9798
return self.global_id(entity_id)
9899

100+
@classmethod
101+
def global_id_to_key(cls, global_id):
102+
_, urlsafe_key = from_global_id(global_id)
103+
return ndb.Key(urlsafe=urlsafe_key)
104+
99105
@classmethod
100106
def get_node(cls, urlsafe_key, info=None):
101107
try:

tests/_ndb/test_types.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,4 +325,3 @@ def testQuery_repeatedKeyProperty(self):
325325
self.assertLength(article['tags'], 4)
326326
for i in range(0, 3):
327327
self.assertEqual(article['tags'][i]['name'], 't%s' % (i + 1))
328-

tests/_ndb/test_types_relay.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ def testNdbNode_getNode_validID_entityDoes_shouldReturnEntity(self):
8383
self.assertIsNotNone(result)
8484
self.assertEqual(result.instance, article_key.get())
8585

86+
def testNdbNode_globalIdToKey_returnsNdbKey(self):
87+
article_key = Article(
88+
headline="TestGetNode",
89+
summary="1",
90+
author_key=Author(name="John Dow", email="[email protected]").put(),
91+
).put()
92+
93+
node = ArticleType.get_node(article_key.urlsafe())
94+
self.assertEqual(NdbNode.global_id_to_key(node.to_global_id()), article_key)
95+
8696
def test_keyProperty(self):
8797
Article(
8898
headline="Test1",

0 commit comments

Comments
 (0)