def get_node(global_id, *args): _type, _id = from_global_id(global_id) if _type == 'User': return userData[_id] else: return photoData[_id] def get_node_type(obj, context, info): if isinstance(obj, User): return userType else: return photoType node_interface, node_field = node_definitions(get_node, get_node_type) userType = GraphQLObjectType('User', fields=lambda: { 'id': global_id_field('User'), 'name': GraphQLField(GraphQLString), }, interfaces=[node_interface]) photoType = GraphQLObjectType( 'Photo', fields=lambda: { 'id': global_id_field('Photo', lambda obj, *_: obj.photoId), 'width': GraphQLField(GraphQLInt), }, interfaces=[node_interface])
_type, _id = resolvedGlobalId.type, resolvedGlobalId.id if _type == 'Faction': return getFaction(_id) elif _type == 'Ship': return getShip(_id) else: return None def getNodeType(obj): if isinstance(obj, Faction): return factionType else: return shipType _node_definitions = node_definitions(getNode, getNodeType) node_field, node_interface = (_node_definitions.node_field, _node_definitions.node_interface) # We define our basic ship type. # # This implements the following type system shorthand: # type Ship : Node { # id: String! # name: String # } shipType = GraphQLObjectType( name='Ship', description='A ship in the Star Wars saga', fields=lambda: {
_type, _id = from_global_id(global_id) if _type == 'Faction': return getFaction(_id) elif _type == 'Ship': return getShip(_id) else: return None def get_node_type(obj, context, info): if isinstance(obj, Faction): return factionType else: return shipType node_interface, node_field = node_definitions(get_node, get_node_type) # We define our basic ship type. # # This implements the following type system shorthand: # type Ship : Node { # id: String! # name: String # } shipType = GraphQLObjectType( name='Ship', description='A ship in the Star Wars saga', fields=lambda: { 'id': global_id_field('Ship'), 'name': GraphQLField(