Custom Input/Output Type for fields
Secretmapper opened this issue · comments
Following the Mongoose Schema provides us with an incredibly easy and smooth way to generate a GraphQL Schema. However, there are some instances where we may want to use a different GraphQL type than our underlying mongodb type. While customQueries and customQueries solves this to some extent, 'baking' in the the functionality to graffiti-mongoose seems advantageous moving forward.
An example of this is image upload. While the Mongoose Type for an image
field might be a Schema.ID
(an id for a gridfs file) our input has to be a string. This is just one example, I'm sure there are a bunch of other use cases too.
What I propose is to use a graffiti attribute that will be read by graffiti during the schema generation process. I figured we put every graffiti custom attribute here so as not to pollute the mongoose type object:
const MaterialSchema = new mongoose.Schema({
cover: {
type: mongoose.Schema.ObjectId,
graffiti: {
input: { type: String },
output: { type: ID },
hooks: {}
}
}
})
This is going to potentially need lots of changes, but will make graffiti-mongoose very powerful. If you think this is a good approach, let me know and I'll get started on a PR 😄
I'm also looking to customize similar things in the generated schema.
But wouldn't that pollute the mongoose schema too much with graffiti dialect?
What did you do so far to solve your needs?