我在我的strawberry-graphql模式解析器实现中有一个嵌套结构。关于如何在strawberry-graphql (Django实现)中限制查询深度,有什么建议吗?
发布于 2021-06-24 00:46:36
这将很快成为草莓中的一个功能:https://github.com/strawberry-graphql/strawberry/pull/1021
您将能够定义一个可以传递给execute命令的验证器:
import strawberry
from strawberry.schema import default_validation_rules
from strawberry.tools import depth_limit_validator
# Add the depth limit validator to the list of default validation rules
validation_rules = (
default_validation_rules + [depth_limit_validator(3)]
)
# assuming you already have a schema
result = schema.execute_sync(
"""
query MyQuery {
user {
pets {
owner {
pets {
name
}
}
}
}
}
""",
validation_rules=validation_rules,
)
)
assert len(result.errors) == 1
assert result.errors[0].message == "'MyQuery' exceeds maximum operation depth of 3"https://stackoverflow.com/questions/68088942
复制相似问题