graphql-python / graphql-python/graphene-sqlalchemy
Queries fail to return if sub-relation table has real world amount of data
- 主要語言
- Python
- 星號
- 985
- 分支
- 223
- PR 合併指標
- 30 天內沒有已合併 PR
描述
In a one to many if you have a table setup as follows (a very simple one to many relationship), the GraphQL query will timeout if tableB has any real world amount of data.
TableB has about 400k records in total. Graphene-sqlalchemy will query for TableA, and then SQLAlchemy itself will try resolve the relationship of the table when graphene calls for it. When this happens the query is sent to the DB but it won't return in enough time (its pulling back ~1GB of data as it tries to pull every single field on the sub table).
I've narrowed it down to graphene/types/resolver.py
```
def attr_resolver(attname, default_value, root, info, **args):
return getattr(root, attname, default_value)
```
Graphene captures the TableA information, and then when TableB get resolved, the `root` parameter is populated with the "TableA" model, which SQLAlchemy then tries to completely resolve 400k records, query times out and then fails.
```
query{
tableA(first: 10){
edges{
node{
tableB(first: 5){
edges{
node{
fieldA
}
}
}
}
}
}
}
```
貢獻指南
研究方向
Start with graphene/types/resolver.py, especially attr_resolver, and reproduce the nested tableA/tableB query shown in the issue against a large related table. Trace how resolving TableA leads to the TableB relationship being accessed, then verify that the query returns within a reasonable time without loading the entire related table.
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- graphql, python, sqlalchemy
- 領域
- api, database, performance
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100