我想测试一个检查查询是否请求字段的函数:
def field_in_query(field, info):
fragments = {}
node = ast_to_dict(info.field_asts[0])
for name, value in info.fragments.items():
fragments[name] = ast_to_dict(value)
while node.get('selection_set'):
for leaf in node['selection_set']['selections']:
if leaf['name']['value'] == field:
return True
else:
node = fragments[leaf['name']['value']] if leaf['kind'] == 'FragmentSpread' else leaf
return False
但是我不知道如何获取info参数。 有什么办法吗?