[英]How to define an Array datatype for GraphQL field in Type definition
我正在開發一個 Nodejs 應用程序,我正在嘗試為 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;
使用GraphQLList
定義列表/數組:
const QuestionChoiceType = new GraphQLObjectType({
name: 'QuestionChoiceType',
fields: () => ({
id: { type: GraphQLID },
correctChoice: { type: GraphQLString },
choices: { type: new GraphQLList(GraphQLString)}
})
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.