문서 보기역링크PDF로 내보내기맨 위로 이 문서는 읽기 전용입니다. 원본을 볼 수는 있지만 바꿀 수는 없습니다. 문제가 있다고 생각하면 관리자에게 문의하세요. # DataLoader <blockquote> DataLoader allows you to decouple unrelated parts of your application without sacrificing the performance of batch data-loading. While the loader presents an API that loads individual values, all concurrent requests will be coalesced and presented to your batch loading function. This allows your application to safely distribute data fetching requirements throughout your application and maintain minimal outgoing data requests <cite></cite></blockquote> <code> import strawberry import asyncio from strawberry.dataloader import DataLoader async def fetch(product_id): url = f"https://[URL]/product/v1/products/{product_id}" resp = requests.get(url) data = json.loads(resp.text) product = Product.from_json(data) return product async def load_product(product_id_list: List[int]) -> Product: futures = [ asyncio.ensure_future(fetch(url)) for url in product_id_list ] # 태스크(퓨처) 객체를 리스트로 만듦 result = await asyncio.gather(*futures) return result loader = DataLoader(load_fn=load_product) async def product_resolver(root, info) -> Product: product_id = root.id return await loader.load(product_id) @strawberry.type class ProductInfo(FromJson): id: int name: str product: Product = strawberry.field(resolver=product_resolver) </code> open/dataloader.txt 마지막으로 수정됨: 2022/06/15 09:12저자 127.0.0.1