# We define a connection between a faction and its ships. # # connectionType implements the following type system shorthand: # type ShipConnection { # edges: [ShipEdge] # pageInfo: PageInfo! # } # # connectionType has an edges field - a list of edgeTypes that implement the # following type system shorthand: # type ShipEdge { # cursor: String! # node: Ship # } shipConnection = connectionDefinitions('Ship', shipType).connectionType # We define our faction type, which implements the node interface. # # This implements the following type system shorthand: # type Faction : Node { # id: String! # name: String # ships: ShipConnection # } factionType = GraphQLObjectType( name='Faction', description='A faction in the Star Wars saga', fields=lambda: { 'id': globalIdField('Faction'), 'name': GraphQLField(
'friends': GraphQLField( friendConnection, args=connectionArgs, resolver= lambda user, args, *_: connectionFromArray(allUsers, args), ), }, ) friendConnection = connectionDefinitions( 'Friend', userType, edgeFields= lambda: { 'friendshipTime': GraphQLField( GraphQLString, resolver= lambda *_: 'Yesterday' ), }, connectionFields= lambda: { 'totalCount': GraphQLField( GraphQLInt, resolver= lambda *_: len(allUsers) ), } ).connectionType queryType = GraphQLObjectType( 'Query', fields=lambda: { 'user': GraphQLField( userType, resolver=lambda *_: allUsers[0] ),