Example #1
0
    def mutate(self, info, user_api_key, name, origin):
        user = User.objects.get(api_key=user_api_key)
        trip = Trip(name=name, user=user)
        response = get_coordinates(origin)

        if len(response) > 0:
            trip.origin = response[0]['formatted_address']
            trip.origin_lat = response[0]['geometry']['location']['lat']
            trip.origin_long = response[0]['geometry']['location']['lng']
            trip.origin_abbrev = get_airport_code(trip.origin)
            trip.save()
            return CreateTrip(trip=trip)
        else:
            raise GraphQLError('Invalid location. Please try again.')