我正在尝试使用npm GraphQL库将自省查询转换为GraphQL模式。
它一直在说:
devAssert.mjs:7 Uncaught Error: Invalid or incomplete introspection result. Ensure that you are passing "data" property of introspection response and no "errors" was returned alongside: { ... } 问题是我直接从GraphiQL商店得到它,不知道如何验证我的自省返回是正确的。
代码:
var introspection = `
{
"data": {
"__schema": {
"types": [
{
"name": "Boolean"
},
{
"name": "String"
},
{
"name": "QueryRoot"
},
{
"name": "Job"
},
{
"name": "ID"
},
{
"name": "Node"
},
{
"name": "Order"
}
]
}
},
"extensions": {
"cost": {
"requestedQueryCost": 2,
"actualQueryCost": 2,
"throttleStatus": {
"maximumAvailable": 1000,
"currentlyAvailable": 980,
"restoreRate": 50
}
}
}
}`;
let schema = buildClientSchema(introspection);
//console.log(schema.printSchema());我以为自省结果可能是一个字符串?或者是没有足够的信息来构建模式?我需要扩展字段的数量吗?将自省结果交换到模式中所需的最低要求是多少?
发布于 2019-11-15 08:06:21
您应该使用getIntrospectionQuery来获得所需的完整自检查询。如果您正在处理的响应是一个字符串,那么在传递给buildClientSchema之前应该将其解析为一个对象--该函数接受一个对象,而不是一个字符串。
下面是一个使用graphql函数直接查询模式的示例--您需要根据实际执行查询的方式对其进行修改。
const { getIntrospectionQuery, buildClientSchema, graphql } = require('graphql')
const schema = new GraphQLSchema(...)
const source = getIntrospectionQuery()
const { data } = await graphql({ source, schema })
const clientSchema = buildClientSchema(data)确保只传入响应的data部分。您传入的对象应如下所示:
{
__schema: {
// ...more properties
}
}https://stackoverflow.com/questions/58868276
复制相似问题