2016-08-22 74 views
1

我收到以下错误:GraphQL错误 - 错误:只能创建一个列表的GraphQLType却得到了:对象对象]

Error: Can only create List of a GraphQLType but got: [object Object].

但我传递一个GraphQLType。

这是触发错误的文件。

``` 
var GraphQL = require('graphql'); 
var BotType = require('../types/bot-type'); 
var Datastore = require('../../datastores/memory-datastore') 

const BotListType = new GraphQL.GraphQLList(BotType); 

module.exports = new GraphQL.GraphQLObjectType({ 
    type: BotListType, 
    resolve: function(object) { 
    return object.bots.map(Datastore.getBot) 
    } 
}) 
``` 

这是关于

``` 
var GraphQL = require('graphql'); 
var RelayQL = require('graphql-relay'); 
var Node = require('../node'); 
var IntegrationListField = require('../fields/integration-list-field') 

const BotType = new GraphQL.GraphQLObjectType({ 
    name: 'Bot', 
    fields: { 
    id: RelayQL.globalIdField('Bot'), 
    name: { type: GraphQL.GraphQLString }, 
    integrations: IntegrationListField 
    }, 
    interfaces: [ Node.nodeInterface ] 
}); 

module.exports = BotType 

``` 

回答

1

我试图复制在我的本地您的模式,并没有得到错误约GraphQLList它的抱怨的BotType。

不过,我得到错误(在第一档)

Error: Type must be named.

,因为我注意到,你在你的第一个文件输入错误GraphQLObjectType定义。在我看来,你试图定义一个字段,而不是类型。

module.exports = new GraphQL.GraphQLObjectType({ 
    name: 'BotListType', 
    fields:() => ({ 
    list: { 
     type: new GraphQL.GraphQLList(BotType), 
     resolve: function(object) { 
     return object.bots.map(Datastore.getBot) 
     } 
    } 
    }) 
}); 

我使用GraphQL版本0.6.2

+0

经过一番调查看来'require'是在空的对象拉动。 –

+0

尝试用函数替换你的'field'对象。而不是 'fields:{...}'将它定义为'fields:()=>({...})'。 – LordDave