-
Notifications
You must be signed in to change notification settings - Fork 50
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
About splitting the project into a general adapter and a mongoose. #105
Comments
@nodkz I will write a detailed proposal, but basically the Graffiti model would be the connection between the adapters. The general adapter would have a Graffiti model as an input and a query object that has all the |
Hmm, may be very interesting. Need code example. |
Found this comment #64 (comment) I'd like this idea, and suggest implement it like wrappers: let Post = mongoose.model('Post');
// current behaviour
const schema = getSchema([Post]);
// add wrapper
const schema = getSchema([withFilesConnection(Post)]);
// add more
const schema = getSchema([withFriendsQueries(withFilesConnection(Post))]); Reusable wrappers under mongoose models is simple and extendable solution. |
For example const Post = mongoose.model('Post');
const PostWithVirtual = withVirtualFields(Post, {'name.full': string, 'metaInfo': MetaSchema});
const schema = getSchema([PostWithVirtual]); Also some hooks may be hidden under wrappers. So wrappers can eliminate extending graffiti options in mongoose schemas. |
Proposal implementation of wrappers: nodkz@0f72a8b import mongoose, { Schema } from 'mongoose';
import { GraphQLString } from 'graphql/type';
import ExtraFieldsWrapper from 'lib/graffiti-mongoose/src/wrappers/extra-fields';
import VirtualFieldsWrapper from 'lib/graffiti-mongoose/src/wrappers/virtual-fields';
const CvSchema = new Schema(
{
name: {
type: String,
description: 'Person name',
},
},
{
toObject: { virtuals: true }, // for population virtual values in resolver
}
);
CvSchema.virtual('name333').get(function () {
return '!!!!!!!!' + this._id + '!!!!!!!!';
});
const Cv = mongoose.model('Cv', CvSchema);
let CvWrapped = new ExtraFieldsWrapper(Cv, {
extraFields: {
_session: {
type: GraphQLString,
resolve(rootValue, args, info) {
return `This is extra field which returns id: ${rootValue._id}`;
},
},
}
});
CvWrapped = new VirtualFieldsWrapper(CvWrapped, {
virtualFields: {
name333: 'String',
}
});
const Schema = getSchema([CvWrapped]); |
New problem reveal today. I have
To solve this problem I should:
So Right now I will do monkeypatching 😉 of |
@nodkz Thanks for the very detailed proposal! I really appreciate it! :) I will dig into it more as soon as I have some free time. |
Also I will use DataLoader (nice 30 min walkthrough from Lee Byron) between Mongoose and GraphQL. So need ability to switch Eg. if we want load authors metadata for 100 articles, best choice would be using |
App schema example https://gist.github.com/nodkz/164f410c78d7a8f01a0d |
For React/Relay components I should have ability use GraphQL Interfaces. Some components can be rendered under different types (so it can be done, if we add interface to such types and will use fragment on interfaceName), so to have such ability I create `ExtraInterfacesWrapper. Commit: nodkz@08aa4a3 |
@nodkz Thanks for your effort! Sorry for not being active lately, I will try to keep up with your progress asap. |
@nodkz any progress on this? |
@sibelius internally I totally rewrite module with different architecture for our project purposes. |
@sibelius @tothandras just started develop new module https://github.com/nodkz/graphql-compose Also you may see my previous version https://github.com/nodkz/graphql-mongoose which I won't publish to npm (reason - mash code in app). |
@tothandras said: I have started to split the project into a general adapter (that waits a graffiti model as input) and a mongoose specific one.
Did you share somewhere a Proposal of your changes? How it will look like?
It will be great if new version will support:
getOneResolver
can be wrapped by DataLoader for performance reasonsThe text was updated successfully, but these errors were encountered: