我正在尝试使用graphql运行快速服务器,我收到以下错误:
错误:Query.example字段类型必须是输出类型,但得到:[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)正在处理另一个项目,所以我认为它们不是问题所在 .
有任何想法吗? “输出类型”是什么意思?
1 回答
如果
是你的查询,然后你弄错了,查询的字段,因此你的例子中的查询应该是这样的:
无论如何,错误是'type'不是有效的GraphQLType . 然后查询将如下所示
将导致:
如果含义是exampleScheme是其他对象,请确保使用以下方法创建它:
希望能帮助到你! :)