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

Support for Mongoose methods and statics #62

Open
zuhair-naqvi opened this issue Nov 23, 2015 · 3 comments
Open

Support for Mongoose methods and statics #62

zuhair-naqvi opened this issue Nov 23, 2015 · 3 comments

Comments

@zuhair-naqvi
Copy link

Is there a way to wire up the existing model methods and statics with resolve functions?

i.e. if my model User has a method User.statics.findSimilar() is there a way for me to expose this as a GraphQL type?

If this was a new application I would use pre and post hooks but theres TONNES of existing business logic within the mongoose statics that I would rather not replicate by hand!

Any thoughts?

@ghost
Copy link

ghost commented Nov 23, 2015

Are you talking about static (model level) or method (instance level)?
I'm not sure how much sense exposing statics would make.

There isn't at the moment (as far as I know), but I'd imagine it wouldn't be too hard to implement.

@zuhair-naqvi
Copy link
Author

@burkhardr Take the example of Animal.search from http://mongoosejs.com/docs/2.7.x/docs/methods-statics.html

In a lot of cases existing Mongoose schemas have business logic implemented as schema statics which I think become instance methods by default when a model is instantiated.

I think it makes sense for graffiti-mongoose to automatically add a Animal.search as a resolve function instead of requiring me to re-implement Animal.search manually, to give you some idea the schema I'm working on has 50+ models and most models have 30+ methods / statics with very specific logic and I'm sure I'm not the only one!

@zuhair-naqvi
Copy link
Author

See #64 for a real use case

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

1 participant