Skip to content

Custom Input/Output Type for fields #120

Description

@Secretmapper

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 😄

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions