出现此错误: 类型错误:应该是 GraphQL 模式
全新虚拟环境,Python 3.10
Pipfile 看起来像这样:
[packages]
graphene = "*"
[requires]
python_version = "3.10"
和 Pipfile.lock
{
"_meta": {
"hash": {
"sha256": "7a8283f892c4c8f1656b470e9ad7f0b79b5d08b21afb627bcb8f1df5d5db7933"
},
"pipfile-spec": 6,
"requires": {
"python_version": "3.10"
},
"sources": [
{
"name": "pypi",
"url": "https://pypi.org/simple",
"verify_ssl": true
}
]
},
"default": {
"graphene": {
"hashes": [
"sha256:2a3786948ce75fe7e078443d37f609cbe5bb36ad8d6b828740ad3b95ed1a0aaa",
"sha256:820db6289754c181007a150db1f7fff544b94142b556d12e3ebc777a7bf36c71"
],
"index": "pypi",
"version": "==3.4.3"
},
"graphql-core": {
"hashes": [
"sha256:2f150d5096448aa4f8ab26268567bbfeef823769893b39c1a2e1409590939c8a",
"sha256:e671b90ed653c808715645e3998b7ab67d382d55467b7e2978549111bbabf8d5"
],
"markers": "python_version >= '3.6' and python_version < '4'",
"version": "==3.2.5"
},
"graphql-relay": {
"hashes": [
"sha256:1ff1c51298356e481a0be009ccdff249832ce53f30559c1338f22a0e0d17250c",
"sha256:c9b22bd28b170ba1fe674c74384a8ff30a76c8e26f88ac3aa1584dd3179953e5"
],
"markers": "python_version >= '3.6' and python_version < '4'",
"version": "==3.2.0"
},
"python-dateutil": {
"hashes": [
"sha256:37dd54208da7e1cd875388217d5e00ebd4179249f90fb72437e91a35459a0ad3",
"sha256:a8b2bc7bffae282281c8140a97d3aa9c14da0b136dfe83f850eea9a5f7470427"
],
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2'",
"version": "==2.9.0.post0"
},
"six": {
"hashes": [
"sha256:4721f391ed90541fddacab5acf947aa0d3dc7d27b2e1e8eda2be8970586c3274",
"sha256:ff70335d468e7eb6ec65b95b99d3a2836546063f63acc5171de367e834932a81"
],
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2'",
"version": "==1.17.0"
},
"typing-extensions": {
"hashes": [
"sha256:04e5ca0351e0f3f85c6853954072df659d0d13fac324d0072316b67d7794700d",
"sha256:1a7ead55c7e559dd4dee8856e3a88b41225abfe1ce8df57b7c13915fe121ffb8"
],
"markers": "python_version >= '3.8'",
"version": "==4.12.2"
}
},
"develop": {}
}
在 pipelinev shell 中执行以下命令:
>>> class Query(graphene.ObjectType):
... name = graphene.String()
...
>>> import graphql
>>> new_schema = graphene.Schema(query=Query)
>>> graphql.type.validate_schema(new_schema)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/tsk147/.local/share/virtualenvs/temp-zjU4Ht41/lib/python3.10/site-packages/graphql/type/validate.py", line 62, in validate_schema
assert_schema(schema)
File "/Users/tsk147/.local/share/virtualenvs/temp-zjU4Ht41/lib/python3.10/site-packages/graphql/type/schema.py", line 449, in assert_schema
raise TypeError(f"Expected {inspect(schema)} to be a GraphQL schema.")
TypeError: Expected <Schema instance> to be a GraphQL schema.
我希望此验证能够成功通过,因为它在此处的教程中使用:https://docs.graphene-python.org/en/latest/execution/queryvalidation/
当然,我一发布这篇文章我就意识到了这个问题。
我需要使用模式名称.graphql_schema
所以在我的例子中,它应该是:
graphql.type.validate_schema(new_schema.graphql_schema)
[]