-
Notifications
You must be signed in to change notification settings - Fork 125
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
Pass down ast.Path of current field
, argument
etc.. inside validator.Events.OnField
#332
Comments
@shotmk I would always be very open to a PR that helps clients to locate the path in graph where error happened, especially if it did not break backwards compatibility or cause a big performance regression. Are you suggesting that the It's currently only in the |
@StevenACoffman |
Sure, that makes sense. Are you able to make a PR for that? I'm swamped at work for the foreseeable future, but would like to see this happen. |
@StevenACoffman |
@StevenACoffman type Query {
topLevelField: TopLevelField
}
type TopLevelField {
nestedField: NestedField
}
type NestedField {
deeplyNestedField: String
}
schema { query: Query} and i am doing the following query: {
topLevelField {
nestedField {
...NestedFieldFragment
}
}
}
fragment NestedFieldFragment on NestedField {
deeplyNestedField
} In my test i am doing : called := 0
observers := &Events{}
observers.OnField(func(walker *Walker, field *ast.Field) {
called++
})
Walk(schema, query, observers)
require.Equal(t,3, called) Expecting the OnField to be called 3 times, but actually it is called 4 times. for _, child := range w.Document.Operations {
w.validatedFragmentSpreads = make(map[string]bool)
w.walkOperation(child)
// AT THIS POINT OnField is called 3 times
}
for _, child := range w.Document.Fragments {
w.validatedFragmentSpreads = make(map[string]bool)
w.walkFragment(child)
// This additional walkFragment causes the additional OnField call
} Is it expected can this be changed ? WDYT? |
That might be great! I remember there were some tricky corner cases where it was better to call some observers twice to avoid missing calling other observers at all. I can't think of why we would need to call the observers twice.
Looking at this on my phone on a bus makes me think something else might also be incorrect. For example, In the walk()
WDYT? I'd need to look at the side effect differences between Sorry, this is my bus stop! :) |
Hey, if you get stuck, or need to set this work aside, push up your current work as a branch somewhere and I'm happy to take a look. |
[WIP] Initial commit. //todo: check the issue with field being walked twice : from walkOperation and from walkFragment
i had a pretty simple implementation ready, and when i was covering it with tests i noticed this fragments thingy... I even have a workaround in place, but wanted maybe to fix the issue in it's root by not walking fragment fields or smth.. |
Oh, now I see. Yeah, that's awkward. Ok, thanks for letting me peek! I'll let you think of a more elegant solution. If I think of anything before then I'll tell you. |
GraphQL errors have a
path
field that helps clients to locate the path in graph where error happened.I am writing some custom directive implementation on top of
validator.Walk
andvalidator.Events
APIs inside gqlparser.I was surprised to find out that i do not have access to current field
ast.Path
inside the OnField() callback.Looking on a walker implementation it feels like it is pretty easy to calculate path as we are doing a straightforward tree traversal.
Can ast.Path info be added to the
OnField
Events listener of validator.Events ?The text was updated successfully, but these errors were encountered: