在GraphQL中将数组作为parameter passing
我已经开始研究GraphQL。我的模式也包含一个列表项目。
以下是我的模式的代码:
var userType = new graphql.GraphQLObjectType({ name: 'user', fields: function () { return { _id: { type: graphql.GraphQLID }, name: { type: graphql.GraphQLString }, age: { type: graphql.GraphQLString }, degrees:[ {type:graphql.GraphQLList} ] } } });
并且查询如下:
var QueryType = new graphql.GraphQLObjectType({ name: 'Query', fields: () => ({ userArr: { type: new graphql.GraphQLList(userType), args:{ degrees:{type:new graphql.GraphQLList(userType)} }, resolve: function(source, args) { console.log(args); resolve(args); } } }) })
我得到这个错误。
基本上我需要从客户端graphql查询发布数组,并必须相应地定义查询,我无法实现。 任何build议,因为我找不到任何帮助,在这个问题..
我最近做了类似的事情。 您的input参数不需要保存到格式化输出数据以发送回相同的types系统。 所以你的arg只需要接受一个string或对象的列表,或者你想要发送的任何标准types。
在这种情况下,我更新它接受string列表(数组)。
var QueryType = new graphql.GraphQLObjectType({ name: 'Query', fields: () => ({ userArr: { type: new graphql.GraphQLList(userType), args:{ degrees:{type:new graphql.GraphQLList(graphql.GraphQLString)} }, resolve: function(source, args) { console.log(args); resolve(args); } } }) })
另外,我注意到你的用户types,你有包围arrays括号度。 类似于你的学位input参数,你将输出一个string数组。 尝试这样的事情:
degrees:{ type:new graphql.GraphQLList(graphql.GraphQLString) }
快乐的编码!
GraphQLObjectType
不是有效的inputtypes。
请参阅突变和inputtypes
“inputtypes不能包含其他对象的字段,只能是基本的标量types,列表types和其他inputtypes。”
您可以使用上面的build议,因为GraphQLString
是一个标量
degrees:{ type:new graphql.GraphQLList(graphql.GraphQLString) }
否则,你需要定义一个GraphQLInputObjectType
const userInputType = new GraphQLInputObjectType({ name: 'userInput', fields: { /* put your fields here */ } }); /* some code in between */ degrees:{ type:new graphql.GraphQLList(userInputType) }
- Facebook的使者bot错误“TypeError:不能读取未定义的属性”0“。
- 如何在本地存储用户信息,当他使用Facebook Messenger的聊天机器人?
- Facebook的OG元与angular和节点
- Mongoose schematype.castForQuery错误。 用户身份validation失败
- Facebook Messenger API在c#asp.net mvc应用程序中的实现
- Facebook Messenger API:发布请求返回错误500
- 我得到的消息:“(#100)没有find匹配的用户”,当使用facebook messenger bot示例教程代码
- Facebook OauthException代码2
- 一个适当的方法来validation