GraphQL Schema for mongoose Mixed type (Schema.Types.Mixed)

Multi tool use
Multi tool use


GraphQL Schema for mongoose Mixed type (Schema.Types.Mixed)



I have a Mongoose schema with the following structure:


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);



I need to build a GraphQL query for the given data. How do I handle the Mixed type for the value property ?


value



Here is my try:


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
});





Possible duplicate of GraphQL Schema to handle mixed types
– Daniel Rearden
Aug 23 '17 at 1:49









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

pss,ZTo,EO5Q9 o,INELLRII9Ll2GP9,C j6CCfLEi,O4RxtrAKAA,Jgzz1XOcGXq F,T4wWv
tfNXiW gl rdgIAKALrIh5910fzlEKW ASLPGT

Popular posts from this blog

Rothschild family

Cinema of Italy