1111
1212
1313class GraphQLNode (object ):
14+
1415 def __init__ (self , nodeInterface , nodeField ):
1516 self .nodeInterface = nodeInterface
1617 self .nodeField = nodeField
@@ -29,30 +30,31 @@ def nodeDefinitions(idFetcher, typeResolver=None):
2930 '''
3031 nodeInterface = GraphQLInterfaceType (
3132 'Node' ,
32- description = 'An object with an ID' ,
33- fields = lambda :{
33+ description = 'An object with an ID' ,
34+ fields = lambda : {
3435 'id' : GraphQLField (
3536 GraphQLNonNull (GraphQLID ),
3637 description = 'The id of the object.' ,
3738 ),
3839 },
39- resolve_type = typeResolver
40+ resolve_type = typeResolver
4041 )
4142 nodeField = GraphQLField (
4243 nodeInterface ,
43- description = 'Fetches an object given its ID' ,
44- args = {
44+ description = 'Fetches an object given its ID' ,
45+ args = {
4546 'id' : GraphQLArgument (
4647 GraphQLNonNull (GraphQLID ),
4748 description = 'The ID of an object'
4849 )
4950 },
50- resolver = lambda obj , args , info : idFetcher (args .get ('id' ), info )
51+ resolver = lambda obj , args , info : idFetcher (args .get ('id' ), info )
5152 )
5253 return GraphQLNode (nodeInterface , nodeField )
5354
5455
5556class ResolvedGlobalId (object ):
57+
5658 def __init__ (self , type , id ):
5759 self .type = type
5860 self .id = id
@@ -65,6 +67,7 @@ def toGlobalId(type, id):
6567 '''
6668 return base64 (':' .join ([type , str (id )]))
6769
70+
6871def fromGlobalId (globalId ):
6972 '''
7073 Takes the "global ID" created by toGlobalID, and retuns the type name and ID
@@ -84,6 +87,7 @@ def globalIdField(typeName, idFetcher=None):
8487 '''
8588 return GraphQLField (
8689 GraphQLNonNull (GraphQLID ),
87- description = 'The ID of an object' ,
88- resolver = lambda obj , * _ : toGlobalId (typeName , idFetcher (obj ) if idFetcher else obj .id )
90+ description = 'The ID of an object' ,
91+ resolver = lambda obj , *
92+ _ : toGlobalId (typeName , idFetcher (obj ) if idFetcher else obj .id )
8993 )
0 commit comments