GraphQL出现错误:Query.example字段类型必须为Output Type,但得到:[object Object] [英] GraphQL with express error : Query.example field type must be Output Type but got: [object Object]

查看:49
本文介绍了GraphQL出现错误:Query.example字段类型必须为Output Type,但得到:[object Object]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用graphql运行Express Server,但出现以下错误:

I'm trying to run express server with graphql and I get the following error:

错误:Query.example字段类型必须为输出类型",但得到:[object Object].

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

路径中使用的

express-graphql:

express-graphql used in a route:

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

该架构如下所示:

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

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

Queries has only one query that imported from here:

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)正在另一个项目上工作,所以我认为它们不是问题.

The schemas (exampleScheme) and data (exampleScheme) are working on another project so I assume they're not the problem.

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

Any ideas? What does 'Output type' mean?

推荐答案

如果

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

是您的查询,然后您弄错了,查询的字段,因此在您的示例中的查询应如下所示:

is your queries, then you got it wrong, Query's fields, hence queries in your example, should be looking like this:

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

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

anyway, the error is that 'type' is not a valid GraphQLType. then the query will look like this

query {
   testString
}

将导致:

{
    testString: "Hello World!"
}

如果含义是exampleScheme是其他对象,请确保您使用以下方法创建它:

if the meaning was that the exampleScheme is some other object, please make sure you are creating it using:

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

希望有帮助!:)

这篇关于GraphQL出现错误:Query.example字段类型必须为Output Type,但得到:[object Object]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆