发布具有语法错误的查询时,graphql / graphene会为您提供建议。例如,发送“ i”,则建议“ ID”。
query{
users{
i
}
}
{
"errors": [
{
"message": "Cannot query field \"i\" on type \"User\". Did you mean \"id\"?",
"locations": [
{
"line": 5,
"column": 9
}
]
}
]
}
可以禁用建议吗?
更多信息:添加建议的语法分析在中间件之前执行。显然,ScalarLeafsRule类提出了建议。
好吧,graphql-core github存储库中的人很棒,他们帮助我解决了这个问题。
因此graphql-core具有两个相关版本,3(当前)和2.3.2(旧版)。对于graphql-core 3,引用Cito
好吧,如果您想使其保持关闭状态并同时禁用自省功能,则这更有意义。我建议您只需设置
graphql.pyutils.did_you_mean.MAX_LENGTH = 0
。我只是提交了一个小更改ffdf1b3,使此工作更好一些。您还可以在https://github.com/graphql/graphql-js/issues处询问他们是否要添加一些功能来支持您的用例。从那里它将被移植回这里。
对于旧版本:
from graphql.validation import rules
def get_empty_suggested_field_names(schema, graphql_type, field_name):
return []
def get_empty_suggested_type_names(schema, output_type, field_name):
return []
rules.fields_on_correct_type.get_suggested_field_names = get_empty_suggested_field_names
rules.fields_on_correct_type.get_suggested_type_names = get_empty_suggested_type_n
您可以将其放置在Django设置文件中。
请关注https://github.com/graphql-python/graphql-core/issues/97上的所有主题>