【发布时间】:2019-05-11 08:03:56
【问题描述】:
我正在尝试创建一个自定义 graphql 架构以在我的 graphql 瑜伽服务器上使用。 graphql 瑜伽服务器只是另一个 graphql API 的代理,我已经设法从中检索 JSON 格式的模式。以下是该架构的预览:
{
"data": {
"__schema": {
"queryType": {
"name": "Query"
},
"mutationType": null,
"subscriptionType": null,
"types": [
{
"kind": "OBJECT",
"name": "Core",
"description": null,
"fields": [
{
"name": "_meta",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "Meta",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "_linkType",
"description": null,
"args": [],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
"interfaces": [
{
我现在想使用这个生成的 JSON 模式并使用它来创建一个 graphql 模式,以便在我的 graphql 瑜伽服务器中使用。我相信正确的方法是使用 graphql 中的 new GraphQLSchema 方法和根查询。这是我尝试这样做的代码:
schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'Query',
fields: schema.data.__schema
})
});
上面的代码给了我以下错误:
错误:Query.mutationType 字段配置必须是对象
不完全确定哪里出了问题,或者这是否是从生成的 JSON 创建 graphql 架构的正确方法?
【问题讨论】:
标签: javascript node.js graphql