虽然使用 GraphiQL 效果很好,但我的老板要求我实现一个用户界面,用户可以在其中检查通过 UI 元素(如复选框、映射关系并获取数据)呈现给他们的元素,这样做将为该人生成一个 graphql 输入,调用API 并将结果返回给用户。
所以,基本上这涉及2代。从 GraphQL 模式生成用户界面并根据用户的选择生成 GraphQL 输入查询。
我进行了搜索,但找不到任何已经执行此操作的工具。我的服务器在 Node 中,我正在使用 Express GraphQL。我使用 https://github.com/graphql-cli/graphql-cli 将我的 express 模式转换为 GraphQLSchema 语言,并使用https://github.com/sheerun/graphqlviz/blob/master上的自省函数自省了 GraphQLSchema语言/cli.js
我得到的对象是这样的(下面只给出部分模式输出)`
"data": {
"__schema": {
"queryType": {
"name": "Query"
},
"mutationType": {
"name": "Mutation"
},
"subscriptionType": null,
"types": [{
"kind": "OBJECT",
"name": "Query",
"description": null,
"fields": [{
"name": "employee",
"description": null,
"args": [{
"name": "ecode",
"description": null,
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
}],
`
我正在循环尝试生成 UI 的元素,但我被卡住了。
做这个的最好方式是什么?提前致谢。