我有一个非常简单的flask graphql应用程序,一切都按我的方式工作,我可以从浏览器中调用它并返回给定的数据。
但是如果我发送包含'&'的字符串,我总是会收到消息“语法错误GraphQL(1:22)未终止的字符串\ n \ n1:(...)\ n ^ \ n“
浏览器将给定的字符串拆分为参数。
有没有解决方法来解决这个问题?
#!/usr/bin/env python3
import flask
import flask_graphql
import graphene
app = flask.Flask('graphql-test')
class Query(graphene.ObjectType):
helloz = graphene.String(text=graphene.String())
def resolve_helloz(self, info, text):
return text
@app.route('/')
def index():
# Create graphql view with the authentication passed as context
return flask_graphql.GraphQLView.as_view(
'index',
schema=graphene.Schema(query=Query),
graphiql=False
)()
if __name__ == '__main__':
# Run application
app.run(host='127.0.0.1', port='8001')
如果将查询作为查询参数发送,则需要转义具有特殊含义的所有字符,例如&
和?
。 &
用于定界单个参数,因此,在不转义的情况下,query
参数最终被解释为{helloz(text:"test
-这不是有效的GraphQL语法。您应该发送:
127.0.0.1:8001?query={helloz(text:"test%26test")}