用于mongoose混合类型的GraphQL Schema(Schema.Types.Mixed)

时间:2017-08-23 00:59:11

标签: mongodb mongoose graphql

我有一个具有以下结构的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
});

0 个答案:

没有答案
相关问题