nodeField, nodeInterface = (_nodeDefinitions.nodeField, _nodeDefinitions.nodeInterface) # 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': globalIdField('Ship'), 'name': GraphQLField( GraphQLString, description='The name of the ship.', ) }, interfaces=[nodeInterface] ) # We define a connection between a faction and its ships. # # connectionType implements the following type system shorthand: # type ShipConnection { # edges: [ShipEdge] # pageInfo: PageInfo! # }
else: return photoData[_id] def getNodeType(obj): if isinstance(obj, User): return userType else: return photoType _nodeDefinitions = nodeDefinitions(getNode, getNodeType) nodeField, nodeInterface = _nodeDefinitions.nodeField, _nodeDefinitions.nodeInterface userType = GraphQLObjectType( 'User', fields= lambda: { 'id': globalIdField('User'), 'name': GraphQLField(GraphQLString), }, interfaces= [nodeInterface] ) photoType = GraphQLObjectType( 'Photo', fields= lambda: { 'id': globalIdField('Photo', lambda obj: obj.photoId), 'width': GraphQLField(GraphQLInt), }, interfaces= [nodeInterface] ) queryType = GraphQLObjectType(