Beispiel #1
0
    def resolve_factions(self, args, context, info):
        headers = dict(context.headers)
        # if you wanted to pass data along to future requests, you'd have to
        # do this in each resolve method
        data = json.loads(context.data.decode("utf-8"))
        del data['query']

        # if you wanted to pass query params along to future requests,
        # you'd have to do this in each method
        query_params = [qp.split('=')
                        for qp
                        in context.query_string.decode("utf-8").split("&")
                        if qp]
        query_params = {qp[0]: next(iter(qp[1:]), '')
                        for qp in query_params}
        query_params['id'] = args['id']

        url = '{}/?{}'.format(
            Faction.endpoint,
            '&'.join([key + '=' + str(value)
                      for key, value in query_params.items()])
        )

        response = requests.get(url, data=data, headers=headers)
        return reduce_fields_to_objects(
            object_class=Faction,
            is_list=True,
            json_result=response.json()['results']
        )
Beispiel #2
0
    def resolve_faction(self, args, context, info):
        headers = dict(context.headers)

        url = '{}/?id={}'.format(
            Faction.endpoint,
            self.faction_id
        )
        response = requests.get(url, headers=headers)
        return reduce_fields_to_objects(
            object_class=Faction,
            is_list=False,
            json_result=response.json()['results'][0]
        )
Beispiel #3
0
    def resolve_heroes(self, args, context, info):
        headers = dict(context.headers)

        url = '{}/?faction_id={}'.format(
            Hero.endpoint,
            self.id
        )
        response = requests.get(url, headers=headers)
        return reduce_fields_to_objects(
            object_class=Hero,
            is_list=True,
            json_result=response.json()['results']
        )
Beispiel #4
0
 def resolve_friends_promise(self, heroes_json):
     friends_json = filter(lambda h: h['id'] in self.friend_ids, heroes_json)
     return reduce_fields_to_objects(
         object_class=Hero, is_list=True, json_result=friends_json
     )