在Ariadne GraphQL Response中添加header



我正在使用ariadne使用python制作一个graphql服务器。

我想在响应中添加报头,如Set-Cookie,用于设置cookie。

有办法吗?如果没有,有没有办法在阿里阿德涅中设置一个炊事员。

我使用React作为前端。

请帮助。谢谢!

更改"#添加cookie到响应对象"部分

from ariadne import make_executable_schema, gql
type_defs = gql("""
type Query {
example: String!
}
""")
@app.route("/graphql", methods=["POST"])
def graphql():
def resolve_example(_, info, **kwargs):
# Add the cookie to the response object
info.context["response"].set_cookie("my-custom-cookie", "my-custom-value")
return "Example"
resolvers = {
"Query": {
"example": resolve_example
}
}
schema = make_executable_schema(type_defs, resolvers)
return GraphQLView.as_view(schema=schema)(request)

最新更新