我有一个具有以下结构的Mongoose模式:
import mongoose from 'mongoose';
const PropertySchema = new mongoose.Schema({
name: {
type: String
},
description: {
type: String
},
value: {
type: mongoose.Schema.Types.Mixed
},
unit: {
type: String
},
});
export default mongoose.model('Property', PropertySchema);
我需要为给定的数据构建GraphQL查询。如何处理value
属性的混合类型?
这是我的尝试:
import NodeInterface from '../interfaces';
import PropertyModel from '../../models/Property';
const fields = {
id: {
type: new GraphQLNonNull(GraphQLID),
resolve: (obj) => dbIdToNodeId(obj._id, "Property")
},
name: {
type: GraphQLString
},
description: {
type: GraphQLString
},
value: {
type: <<< What to use here ?
},
unit: {
type: GraphQLString
}
};
export const PropertyType = new GraphQLObjectType({
name: 'Property',
description: 'Property',
interfaces: () => [NodeInterface],
isTypeOf: (value) => value instanceof PropertyModel,
fields: fields
});