在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使用护照从Androidlogin到节点js服务器
- Sencha应用程序在Facebook的iFrame得到一个“不能POST /”
- {
- Facebook使者“开始”button
- 如何将一个node.js webhook连接到我的Facebook应用程序的messenger API?
- create-react-app,安装错误(“找不到命令”)
- 无法在iOS Facebook SDK中将access_tokenvalidation为PassportJS
- 后端服务器软件与PHP / MySQL / JS类似Facebook的聊天?
- 在Rest API中使用Facebook维护Express和NodeJS中的JWT的密钥和访问令牌