Example #1
0
#   }
factionType = GraphQLObjectType(
    name='Faction',
    description='A faction in the Star Wars saga',
    fields=lambda: {
        'id': globalIdField('Faction'),
        'name': GraphQLField(
            GraphQLString,
            description='The name of the faction.',
        ),
        'ships': GraphQLField(
            shipConnection,
            description='The ships used by the faction.',
            args=connectionArgs,
            resolver=lambda faction, args, *_: connectionFromArray(
                [getShip(ship) for ship in faction.ships],
                args
            ),
        )
    },
    interfaces=[nodeInterface]
)

# This is the type that will be the root of our query, and the
# entry point into our schema.
#
# This implements the following type system shorthand:
#   type Query {
#     rebels: Faction
#     empire: Faction
#     node(id: String!): Node
#   }
Example #2
0
allUsers = [
  User(name='Dan'),
  User(name='Nick'),
  User(name='Lee'),
  User(name='Joe'),
  User(name='Tim'),
]

userType = GraphQLObjectType(
  'User',
  fields= lambda: {
    'name': GraphQLField(GraphQLString),
    '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(