0
我试图从json配置动态生成graphql方案。但我无法为自己创建一个GraphQLList。创建它时无法引用GraphQLObjectType
JSON:
{
"label": "user",
"properties": [
{
"key": "name",
"type": "string"
},
{
"key": "id",
"type": "id"
},
{
"key": "birthday",
"type": "date"
},
{
"key": "gender",
"type": "string"
},
{
key: 'friends',
type: 'string'
}
]
}
的JavaScript代码生成:
graphSchemes.forEach(function (graphScheme) {
graphQLObjects[graphScheme.label] = new graphql.GraphQLObjectType({
name: graphScheme.label,
fields: graphScheme.properties.reduce((fields, property) => {
if (property.key === 'friends') {
fields[property.key] = {
type: new graphql.GraphQLList(graphQLObjects[graphScheme.label])
};
return fields;
}
fields[property.key] = {
type: TYPES[property.type]
};
return fields;
}, {})
});
});这里
的问题是:
type: new graphql.GraphQLList(graphQLObjects[graphScheme.label])
没有 “graphQLObjects [graphScheme.label]”
我如何去解决这个?有什么建议么?