graphql-compose-mongoose
graphql-compose-mongoose copied to clipboard
How to handle custom types?
How should I handle models with custom types such as mongoose-long?
Currently I get the following error when creating a TypeComposer with composeWithMongoose if the model has a field using the custom type mongoose.Schema.Types.Long.
Uncaught Exception: Error: You provide incorrect mongoose field to `deriveComplexType()`. Correct field should contain `path` and `instance` properties.
at deriveComplexType (/code/node_modules/graphql-compose-mongoose/lib/fieldsConverter.js:228:11)
at convertFieldToGraphQL (/code/node_modules/graphql-compose-mongoose/lib/fieldsConverter.js:197:23)
at Object.keys.forEach.fieldName (/code/node_modules/graphql-compose-mongoose/lib/fieldsConverter.js:145:13)
at Array.forEach (<anonymous>)
at convertModelToGraphQL (/code/node_modules/graphql-compose-mongoose/lib/fieldsConverter.js:142:31)
at composeWithMongoose (/code/node_modules/graphql-compose-mongoose/lib/composeWithMongoose.js:30:57)
I ended up fixing this by modifying the instance property of the model.schema.paths.field.instance = 'String'.
They allowed me to bypass the error and retrieve the value as a string.