我正在使用Node JS创建GraphQL服务器。
我正在尝试复制mongo模式,该模式具有一个纯粹用于组织的嵌套对象。这是我的mongo模式:
var plansSchema = new Schema({
planName: {
type: String,
required: [true, "Plan name is required"]
},
pricing: {
monthly: Number,
scanEnvelope: Number,
initalScan: Number,
perPage: Number,
forwardMail: Number,
forwardParcel: Number,
shred: Number,
perMonthPerGram: Number,
freeStorePerGram: Number,
setup: Number,
idFree: Number
},
expires: Number,
private: Boolean,
deleted: Boolean,
date: { type: Date, default: Date.now },
});
我正在尝试在GraphQL模式中复制它,到目前为止,我具有以下内容:
const PlanType = new GraphQLObjectType({
name: "Plan",
fields: () => ({
id: { type: GraphQLString },
planName: { type: GraphQLString },
pricing: new GraphQLObjectType({
name: "Pricing",
fields: () => ({
expires: { type: GraphQLInt },
private: { type: GraphQLBoolean },
monthly: { type: GraphQLInt },
scanEnvelope: { type: GraphQLInt },
initalScan: { type: GraphQLInt },
perPage: { type: GraphQLInt },
forwardMail: { type: GraphQLInt },
forwardParcel: { type: GraphQLInt },
shred: { type: GraphQLInt },
perMonthPerGram: { type: GraphQLInt },
freeStorePerGram: { type: GraphQLInt },
setup: { type: GraphQLInt },
idFree: { type: GraphQLInt }
})
})
})
});
但是我在GraphiQL中遇到以下错误
{
"errors": [
{
"message": "The type of Plan.pricing must be Output Type but got: undefined."
}
]
}
答案 0 :(得分:0)
设置为{{1}的GraphQLFieldConfigMapThunk
或GraphQLFieldConfigMap
中的每个字段必须是一个fields
对象,该对象必须包含GraphQLFieldConfig
,{{1 }},type
等。您无法像对args
字段那样将resolve
设置为field
。换句话说,您的代码应更像这样:
GraphQLObjectType