-
Notifications
You must be signed in to change notification settings - Fork 52
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
Add support for Embedded Types #104
Conversation
@nodkz Thank you, I like it! Although I have started to split the project into a general adapter (that waits a graffiti model as input) and a mongoose specific one, I might wait to merge this until that's finished. :) |
@tothandras finished with mutations. Add converter Splitting, hmm, will waiting new major version ;) const UserSchema = new mongoose.Schema({
name: {
type: String,
graffiti: { // <-------------------------------------------------------------------
hooks: {
pre: (next, root, args, {rootValue}) => {
const {request} = rootValue;
authorize(request);
next();
},
post: [
(next, name) => next(`${name} first hook`),
(next, name) => next(`${name} & second hook`)
]
}
}
}
});
|
* @return {Object} | ||
*/ | ||
function listToGraphQLEnumType(list, name) { | ||
const values = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reduce?
Let me merge and release this, the splitting will take more time. Can you squash the commits and rebase on master? And please use the angular commit message convention. Thank you! :) |
First squash for me with merging. |
For me |
@@ -84,8 +84,10 @@ function stringToGraphQLType(type) { | |||
* @return {Object} | |||
*/ | |||
function listToGraphQLEnumType(list, name) { | |||
const values = {}; | |||
list.forEach((val) => { values[val] = {value: val}; }); | |||
const values = reduce(list, (values, val) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const values = list.reduce((allValues, value) => ({
...allValues,
value
}), {});
? :) (didn't run it, may fail)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works on my project.
I do it like in getOrderByType
method, which uses lodash
reduce.
May rewrite on regular ES6 reduce.
PS. a subtle hint for tests :P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:P don't worry about them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Working version might look like:
const values = list.reduce((allValues, value) => ({
...allValues,
[value]: { value }
}), {});
Some syntax-sugar-shit ))))))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, right :) 👍
Also, I will write some tests then, don't worry about that. :) |
Done.
|
Ups, I didn't notice conflicts yesterday with your master. |
@nodkz Thank you! |
@nodkz The tests are failing, both locally and on CI. Can you take a look? I will do the same. |
Yep. After 30 minutes.
|
you don't need to rush :) it's okay later, take some rest On Mon, Mar 28, 2016, 09:49 Pavel Chertorogov notifications@github.com
|
No problem. I have now gone for lunch. Fixing tests after lunch is the
|
Are mutations already supported @nodkz ? I've defined a subdocument array but it is not present in the schema input and hence I can't update/add a subdocument: My schema:
.graphql input is missing 'chapters'
Hoping I just missed something :) |
First of all a see problem with Why it not convert array of chapters to input, i can not imagine. Right now I on mobile, so can see and try help only on Thursday. Right now I recommend you try sub-docs (http://mongoosejs.com/docs/subdocs.html) for chapters. Also I have many hacks on graffiti, and Internally I totally rewrite it in own project from scratch. And right now it under heavy api changing. I'm trying make comfortable and heavy customizable thing. I think it will be open sourced at end of may, when api will be stable and covered all our needs. |
@nodkz Actually thinking about it, you are right Mixed is impossible since graphql has to be strongly typed. For some reason though array of chapters doesn't seem to be added to Input for some reason, even if using subdocs. Have done some digging through the source and tried to take a stab on it but still doesn't seem to get picked up (though it appears in changedMaterialNode weirdly enough) |
According to http://mongoosejs.com/docs/subdocs.html#single-embedded
Add ability to pass
childSchema
to GraphQL. Also was addedgraphqlTypeName
for child schema, because it must have Type name.Mutations
not realized yet, but for such field types I add catcherfield.type.mongooseEmbedded
. (realized in 2da95bf)@tothandras review needed, may be your suggest better solution for embedded documents.