This repository was archived by the owner on Sep 6, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +21
-2
lines changed Expand file tree Collapse file tree 5 files changed +21
-2
lines changed Original file line number Diff line number Diff line change 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+
6100.1.5 (2016-06-08)
711---------------------
812* Fixed behavior of ndb.KeyProperty ([PR #14](https://github.com/graphql-python/graphene-gae/pull/14))
Original file line number Diff line number Diff line change 1212)
1313
1414__author__ = 'Eran Kampf'
15- __version__ = '0.1.5 '
15+ __version__ = '0.1.6 '
1616
1717__all__ = [
1818 NdbObjectType ,
Original file line number Diff line number Diff line change 55from graphene .core .classtypes .objecttype import ObjectType , ObjectTypeMeta
66
77from google .appengine .ext import ndb
8+ from graphql_relay import from_global_id
89
910from .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 :
Original file line number Diff line number Diff 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-
Original file line number Diff line number Diff 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" ,
You can’t perform that action at this time.
0 commit comments