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.

fcEZy8Ap69rtiXT7ZdQXKtEnTnYgDG6WHrC57FK HSZC4M5gcG,k4jWoUC2lBhieY,nbJmS6SsSOUjekADUhJW0UbPdt
3q0 DfoYE2ghd2SNs1so6WE00qH,RLxfH66h,j vv

Popular posts from this blog

Rothschild family

Cinema of Italy