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
make new function exposed from the enricher so lookaheads can check and evaluate skips / includes #177
base: main
Are you sure you want to change the base?
make new function exposed from the enricher so lookaheads can check and evaluate skips / includes #177
Conversation
84315f3
to
d24cbdc
Compare
d24cbdc
to
5405ec5
Compare
current problem this test with snapshot is not passing there is query query {
node(id: "root") {
id
... on Image {
width
}
... on DocumentElement {
__typename
... on Image {
url
tags {
name
}
}
... on Media {
tags {
id
}
}
}
}
} and I receive that my result contains property "tags": Object {
"Tag": Object {
"id": Object {
Symbol(LeafFieldSymbol): true,
},
- "name": Object {
- Symbol(LeafFieldSymbol): true,
- }, but we query property UPD: test is correct. my debug document (access only for zalandoers) |
I re-read the comment now, and realised it is other way around. The snapshot is expecting |
yes, that's why it certainly must not be merged and I need to find a place where it's happening because my additions were not meant to modify query response tree. |
src/resolve-info.ts
Outdated
const fieldExpansion: FieldExpansion = Object.create( | ||
{ | ||
__shouldInclude: shouldInclude | ||
}, | ||
{} | ||
); |
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.
I have 0 ideas how, but these lines break objects merging and lead to the failing test in this PR.
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.
The object merging breaks because we set here a prototype for the object, but lodash mergeWith
is expecting objects to be plain objects to function, and it does not know how to merge objects that have non null
prototypes.
See https://lodash.com/docs/4.17.15#merge
Array and plain object properties are merged recursively. Other objects and value types are overridden by assignment.
Basically because we are not having plain objects anymore, in this code https://github.com/lodash/lodash/blob/2da024c3b4f9947a48517639de7560457cd4ec6c/.internal/baseMergeDeep.js#L69-L89 we skip this merge part, and just override the value, as stated above
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.
Our customizer
for mergeWith
is only customizing the leaf nodes, and returns undefined
for other nodes, i.e. then normal lodash merge is used.
One way to deal with this would be to extend the customizer function to also merge our new objects that have prototype
graphql-jit/src/resolve-info.ts
Lines 378 to 393 in 9de816e
mergeWith(obj, src, (objValue, srcValue): LeafField | undefined => { | |
if (isLeafField(objValue)) { | |
if (isLeafField(srcValue)) { | |
return { | |
...objValue, | |
...srcValue | |
}; | |
} | |
return objValue; | |
} else if (isLeafField(srcValue)) { | |
return srcValue; | |
} | |
return undefined; | |
}); |
src/resolve-info.ts
Outdated
}; | ||
function createLeafField<T extends object>( | ||
props: T, | ||
shouldInclude: (variables: ShouldIncludeVariables) => boolean |
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.
The typename "ShouldIncludeVariables" should be ShouldIncludeParams
. Otherwise it would read variables.variables[variableName]
.
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.
renamed.
src/resolve-info.ts
Outdated
} | ||
}; | ||
|
||
type RootFieldExpansion = { |
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.
Why do we need this separate type?
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.
initially it was because root doesn't have ShouldIncludeExtension since root is always included.
…st suite and remove the skip from the describe block. Also, fix the schema object formatting. test(resolve-info.test.ts): add tests for resolver info and field expansion
…ed twice instead of once when skipping a field
…implify lookaheadForUrl expression
… based on __shouldInclude() result test(resolve-info.test.ts): add tests for not skipping expensive function based on __shouldInclude() result refactor(resolve-info.ts): simplify createLeafField function using object spread syntax feat(resolve-info.ts): add support for nested __internalShouldIncludePath in expandFieldNode function
current todo / problems
|
…eParams refactor(resolve-info): rename shouldInclude function parameter from variables to params refactor(resolve-info): remove empty object from createLeafField function call refactor(resolve-info): remove empty object from Object.create call in expandFieldNode function
… of ShouldIncludeExtension refactor(resolve-info.ts): use Object.create and Object.assign to create LeafField object refactor(resolve-info.ts): use Object.defineProperties to define __shouldInclude property in FieldExpansion object
refactor(resolve-info): simplify rightKey variable assignment fix(resolve-info): add missing semicolons and fix eslint errors
…h tags excluded and tag query with name field
….test.ts refactor(resolve-info): simplify expandFieldNode function in resolve-info.ts
test(resolve-info.test.ts): clear mock before each test
Bug description
Even though fields inside the entities() field of a collection are @skip-ed as part of a query, they still make the calls to backends as if they are not skipped but just discards the data instead of returning it to the client.
Expected behavior
Backend systems should not be called in the case that the field it is required for is skipped.
Current behavior
Backends are called even if the field is skipped