GraphQL 对象 属性 应该是一个字符串列表
GraphQL object property should be a list of strings
如何为 GraphQL 中的字符串数组对象 属性 创建架构?我希望响应看起来像这样:
{
name: "colors",
keys: ["red", "blue"]
}
这是我的架构
var keysType = new graphql.GraphQLObjectType({
name: 'keys',
fields: function() {
key: { type: graphql.GraphQLString }
}
});
var ColorType = new graphql.GraphQLObjectType({
name: 'colors',
fields: function() {
return {
name: { type: graphql.GraphQLString },
keys: { type: new graphql.GraphQLList(keysType)
};
}
});
当我 运行 这个查询时我得到一个错误并且没有数据,错误只是 [{}]
查询{颜色{名称,键}}
然而,当我 运行 查询 return 时,我得到了成功的响应。
查询{颜色{名称}}
当我查询键时,如何创建一个 return 字符串数组的架构?
我找到了答案。关键是将 graphql.GraphQLString
传递给 graphql.GraphQLList()
架构变为:
var ColorType = new graphql.GraphQLObjectType({
name: 'colors',
fields: function() {
return {
name: { type: graphql.GraphQLString },
keys: { type: new graphql.GraphQLList(graphql.GraphQLString)
};
}
});
使用此查询:
查询{颜色{名称,键}}
我得到了想要的结果:
{
name: "colors",
keys: ["red", "blue"]
}
如何为 GraphQL 中的字符串数组对象 属性 创建架构?我希望响应看起来像这样:
{
name: "colors",
keys: ["red", "blue"]
}
这是我的架构
var keysType = new graphql.GraphQLObjectType({
name: 'keys',
fields: function() {
key: { type: graphql.GraphQLString }
}
});
var ColorType = new graphql.GraphQLObjectType({
name: 'colors',
fields: function() {
return {
name: { type: graphql.GraphQLString },
keys: { type: new graphql.GraphQLList(keysType)
};
}
});
当我 运行 这个查询时我得到一个错误并且没有数据,错误只是 [{}]
查询{颜色{名称,键}}
然而,当我 运行 查询 return 时,我得到了成功的响应。
查询{颜色{名称}}
当我查询键时,如何创建一个 return 字符串数组的架构?
我找到了答案。关键是将 graphql.GraphQLString
传递给 graphql.GraphQLList()
架构变为:
var ColorType = new graphql.GraphQLObjectType({
name: 'colors',
fields: function() {
return {
name: { type: graphql.GraphQLString },
keys: { type: new graphql.GraphQLList(graphql.GraphQLString)
};
}
});
使用此查询:
查询{颜色{名称,键}}
我得到了想要的结果:
{
name: "colors",
keys: ["red", "blue"]
}