-
Notifications
You must be signed in to change notification settings - Fork 54
Fix input types resolver in generators #373
Fix input types resolver in generators #373
Conversation
@zazido Thanks!
🙏 |
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.
Should have left my feedback in review form. See above.
@jasonkuhrt thanks for the great tool. I'm glad to help with 1 & 3 after your commit. For those who want a quick fix from #310, go to function deepResolveInputTypes(inputTypesMap, typeName, seen) {
if (seen === void 0) { seen = {}; }
console.log(seen);
var type = inputTypesMap[typeName];
if (type) {
var childTypes = type.fields
.filter(function (t) { return t.type.isInput && !seen[t.type.name]; })
.map(function (t) { return t.type.name; })
.map(function (name) {
seen[name] = true;
return deepResolveInputTypes(inputTypesMap, name, seen);
})
.reduce(utils_1.flatten, []);
return [typeName].concat(childTypes);
}
else {
throw new Error("Input type " + typeName + " not found");
}
} and rerun Looking forward to your feedback. |
I will try to address my own points but not sure when I will have it done. If you can do it before me all the better : ) |
deepResolveInputTypes(inputTypesMap, name, { ...seen, [name]: true }), | ||
) | ||
.map(name => { | ||
seen[name] = true |
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.
What is the intended effect of your change, given:
import * as _ from 'lodash'
const seen = {}
const name = 'bar'
const seenCopy = { ...seen, [name]: true }
seen[name] = true
assert(_.isEqual(seen, seenCopy))
?
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.
Ah, but by using mutation to share state across the recursion's various branches of the tree-of-types, we effectively guarantee that said branches share their seen
state... which otherwise is not the case (seen state is effectively forked at every node.
|
Fixes the potential unnecessary recursive function calls. Resolves #310
For a type structure like this:
A
has child typesB
&D
,B
andD
both haveC
.When executing
deepResolveInputTypes(inputTypesMap, typeName, seen)
onA -> B -> C -> D -> C
, C will still be marked as unseen sinceseen
is a new object on line:https://github.com/prisma/graphqlgen/blob/f7a90f41aa297e70a1076698c9393096dab3ec12/packages/graphqlgen/src/generators/common.ts#L243
Instead, we should use
seen
itself.TODO
deepResolveInputTypes
test incommon.spec.ts
.