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( GraphQLString, description='The name of the ship.', ) }, interfaces=[node_interface] ) # We define a connection between a faction and its ships. # # connection_type implements the following type system shorthand: # type ShipConnection { # edges: [ShipEdge] # pageInfo: PageInfo! # }
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]) queryType = GraphQLObjectType( 'Query', fields=lambda: {
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] ) queryType = GraphQLObjectType(
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( GraphQLString, description='The name of the ship.', ) }, interfaces=[node_interface]) # We define a connection between a faction and its ships. # # connection_type implements the following type system shorthand: # type ShipConnection { # edges: [ShipEdge] # pageInfo: PageInfo! # } #
def get_field(self, schema): return global_id_field(self.object_type._meta.type_name)
node_interface, node_field = node_definitions(get_node, get_node_type)[:2] # 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(GraphQLString, description="The name of the ship."), }, interfaces=[node_interface], ) # We define a connection between a faction and its ships. # # connection_type implements the following type system shorthand: # type ShipConnection { # edges: [ShipEdge] # pageInfo: PageInfo! # } # # connection_type has an edges field - a list of edgeTypes that implement the # following type system shorthand:
_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: { "id": global_id_field("Ship"), "name": GraphQLField(GraphQLString, description="The name of the ship."), }, interfaces=[node_interface], ) # We define a connection between a faction and its ships. # # connection_type implements the following type system shorthand: # type ShipConnection { # edges: [ShipEdge] # pageInfo: PageInfo! # } # # connection_type has an edges field - a list of edgeTypes that implement the # following type system shorthand: