如何使用'flask-graphql'将资源管理器添加到GraphiQL?

问题描述 投票:1回答:1

我正在使用flask-graphql提供GraphiQL,但是如果不使用Node.JS,则看不到任何启用GraphiQL的“资源管理器”的方法。有没有办法为Python(flask-graphql)后端启用资源管理器?

python-3.x flask graphql
1个回答
0
投票

Node.js不是必需的,但是React is,因为graphiqlgraphiql-explorer都是React组件。 flask-graphql只是使用脚本渲染HTML页面,该脚本使用here所示的React来渲染GraphiQL接口。

[如图graphiql_template所示,通过here选项创建GraphQLView时,您应该能够提供自己的模板来呈现此页面。

复制并粘贴现有模板,然后为库添加脚本标签:

<script src="//cdn.jsdelivr.net/npm/[email protected]/graphiqlExplorer.min.js"></script>

并执行here所示的组件。由于您没有在编译此代码,因此您将无法使用JSX,因此您需要执行以下操作...

React.createElement(
  "div",
  { className: "graphiql-container" },
  React.createElement(
    GraphiQLExplorer,
    { /* props here */ },
  ),
  React.createElement(
    GraphiQL,
    { /* props here */ },
  )
)
© www.soinside.com 2019 - 2024. All rights reserved.