when user click button, I want to update A(Stock) DB by using data from B(Account) DB.
when user click button, django get data(company_id and company_secret) From Account DB. and then web scraping with data. it makes new data. i want to just save new data to Stock DB. I don't want to give data to web.
below code show error "GetStockMutation fields must be a mapping (dict / OrderedDict) with field names as keys or a function which returns such a mapping."
import graphene
from .types import AccountType, StockType
from .models import *
from .crypt import AESCipher
from graphql_jwt.decorators import login_required
from .views import getStockNamu
class GetStockMutation(graphene.Mutation):
@login_required
def mutate(self, info, **kwargs):
if info.context.user.is_authenticated:
user_id = info.context.user.id
#data from Account DB
account = Account.objects.get(user_id=user_id, company=1)
#decrypt
company_id = AESCipher().decrypt_str(account.company_id)
company_secret = AESCipher().decrypt_str(account.company_secret)
# web scraping
code, amount = getStockNamu(company_id, company_secret)
#save it to Stock DB
stock = Stock.objects.create(user_id=user_id, code=code, amount=amount, company=1)
stock.save()
print(stock)
else:
raise PermissionError("로그인이 필요합니다.")
class Query(object):
pass
class Mutation(graphene.ObjectType):
get_account = GetaccountMutation.Field()
get_stock = GetStockMutation.Field()