我正在开发Node.js应用程序,并且试图为graphQL定义下面的类型,但是我无法弄清楚如何用Javascript数组类型定义字段。
const graphql = require('graphql');
const {
GraphQLObjectType,
GraphQLString,
GraphQLID
} = graphql;
const { Question } = require('../../../../models');
const QuestionChoiceType = new GraphQLObjectType({
name: 'QuestionChoiceType',
fields: () => ({
id: { type: GraphQLID },
correctChoice: { type: GraphQLString },
choices: [{ type: GraphQLString }]
})
});
module.exports = QuestionChoiceType;
答案 0 :(得分:0)
使用GraphQLList
定义列表/数组:
const QuestionChoiceType = new GraphQLObjectType({
name: 'QuestionChoiceType',
fields: () => ({
id: { type: GraphQLID },
correctChoice: { type: GraphQLString },
choices: { type: new GraphQLList(GraphQLString)}
})
});