Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Input/Output Type for fields #120

Open
Secretmapper opened this issue May 3, 2016 · 1 comment
Open

Custom Input/Output Type for fields #120

Secretmapper opened this issue May 3, 2016 · 1 comment

Comments

@Secretmapper
Copy link

Secretmapper commented May 3, 2016

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 😄

@yoadsn
Copy link
Contributor

yoadsn commented Aug 21, 2016

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants