Skip to content
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

more actionable federation errors for nil key field queries #3437

Merged
merged 3 commits into from
Dec 16, 2024

Conversation

StevenACoffman
Copy link
Collaborator

@StevenACoffman StevenACoffman commented Dec 14, 2024

In #3029 @clayne11 altered the federation behavior, so that null values for key Fields would now also skip using the resolver (since it would never work). This was both a security and performance enhancement, as expensive safelisted queries with nil KeyField values could have been sent for no reason.

However, the error messages for this change were not very specific and as a result, were not very clearly actionable.
I think I correctly understand the cases and have added more specific error messages, but I would definitely appreciate confirmation from @clayne11 or @kanodia-parag or anyone else that I'm not subtly misleading people.

I am collecting entity resolution errors as it is valid for entities with multiple key fields to fail with some resolvers and then succeed with a different resolver.

Signed-off-by: Steve Coffman <steve@khanacademy.org>
Signed-off-by: Steve Coffman <steve@khanacademy.org>
}
{{- if (ne $i $keyField.Field.LastIndex ) }}
if m, ok = val.(map[string]interface{}); !ok {
break
// nested field value is not a map[string]interface
return "", fmt.Errorf("%w for {{$entity.Name}} due to nested Keyfield not being map value", ErrTypeNotFound)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@clayne11 This is the one I am least confident if it is a good error message

@StevenACoffman StevenACoffman changed the title federation errors more actionable federation errors Dec 15, 2024
@StevenACoffman StevenACoffman changed the title more actionable federation errors more actionable federation errors for nil key field queries Dec 15, 2024
@StevenACoffman StevenACoffman force-pushed the federation_errors branch 3 times, most recently from b0fbf6d to bfaf7fc Compare December 15, 2024 15:43
@coveralls
Copy link

coveralls commented Dec 15, 2024

Coverage Status

coverage: 73.893% (+0.009%) from 73.884%
when pulling d6b38cf on federation_errors
into e92956a on master.

Signed-off-by: Steve Coffman <steve@khanacademy.org>
@@ -310,10 +313,15 @@ func (ec *executionContext) resolveManyEntities(
{{- range $i, $field := .Field }}
val, ok = m["{{.}}"]
if !ok {
entityResolverErrs = append(entityResolverErrs,
fmt.Errorf("%w due to missing Key Field \"{{.}}\" for {{$entity.Name}}", ErrTypeNotFound))
break
}
{{- if (ne $i $keyField.Field.LastIndex ) }}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not very sure I understand what this code is doing here.
We only want to possibly skip suggesting this resolver if the current field index does not match the last index of the key field?

@StevenACoffman StevenACoffman added help wanted Extra attention is needed federation Related to Apollo federation labels Dec 15, 2024
@StevenACoffman StevenACoffman merged commit 0d2b9d2 into master Dec 16, 2024
18 checks passed
@StevenACoffman StevenACoffman deleted the federation_errors branch December 16, 2024 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
federation Related to Apollo federation help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants