node.js - 带有明确错误 : Query. 的 GraphQL 示例字段类型必须是输出类型,但得到:[object Object]

标签 node.js graphql

我尝试使用 graphql 运行 Express 服务器,但收到以下错误:

Error: Query.example field type must be Output Type but got: [object Object].

路由中使用的express-graphql:

app.use('/graphql', graphqlHTTP(req => ({
 schema,
 pretty: true
})));

架构如下所示:

export default new GraphQLSchema({
 query: new GraphQLObjectType({
    name: 'Query',
    fields: queries
 })
});

查询只有一个从此处导入的查询:

import {
 GraphQLList,
 GraphQLID,
 GraphQLNonNull
} from 'graphql';

import exampleScheme from '../models/schemes/example';
import {example as exampleData}  from '../models/jsons'

export default {
 type: exampleScheme,
 resolve (root, params, options) {
     return exampleData;
 }
};

架构 (exampleScheme) 和数据 (exampleScheme) 正在另一个项目中工作,因此我认为它们不是问题。

有什么想法吗? “输出类型”是什么意思?

最佳答案

如果

export default {
 type: exampleScheme,
 resolve (root, params, options) {
     return exampleData;
 }
};

是你的疑问,那么你就错了, 查询的字段,因此示例中的查询应该如下所示:

export default {
 helloString: {
     type: GraphQLString,
     resolve (root, params, options) {
         return "Hello World!";
     }
 }
 ... <Next query>
};

无论如何,错误是“type”不是有效的 GraphQLType。 那么查询将如下所示

query {
   testString
}

将导致:

{
    testString: "Hello World!"
}

如果意思是 exampleScheme 是其他对象, 请确保您使用以下方式创建它:

new GraphQLObjectType({ .... Options });

希望对您有帮助! :)

关于node.js - 带有明确错误 : Query. 的 GraphQL 示例字段类型必须是输出类型,但得到:[object Object],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39496372/

相关文章:

node.js - 无服务器的 MoonMail Lambda 架构

graphql - 如何为自引用数据层次结构创建graphql模式?

node.js - Gatsby `S3Object` 架构中不存在。在添加解析器之前使用 `createTypes` 添加类型

node.js - 如何在 express 上捕获完整的 http 请求以再次向我的本地主机请求它们

node.js - AWS Lambda - 错误 : unable to get local issuer certificate

Graphql 数据建模 : extending types and interfaces

graphql - Gatsby 内容丰富的嵌入图像

reactjs - 如果参数为空,则不运行查询

javascript - 如何使用nodeJS从mongodb获取数据并将其传输到Html页面?

javascript - 如何获取传递给 Mongoose 模式构造函数的数据