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

Fix top level hydration #572

Merged
merged 3 commits into from
Sep 9, 2024
Merged

Fix top level hydration #572

merged 3 commits into from
Sep 9, 2024

Conversation

gnawf
Copy link
Collaborator

@gnawf gnawf commented Aug 13, 2024

So the bug was that we couldn't find the service that owned a hydrated field, because we looked at the ownership of the parent type of the hydrated field, which for root level hydrations was the operation type.

Then on top of that, we didn't handle multple root level fields.

This PR fixes both.

@gnawf gnawf marked this pull request as ready for review August 29, 2024 01:47
.filterNot {
it.fieldName == TypeNameMetaFieldDef.name
}
.firstOrNull() ?: topLevelFields.first(),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This gets the first non __typename field, to maintain the old behavior.

(Refer to above comment).

@@ -343,9 +343,16 @@ internal class NextgenEngine(
serviceContext = executionContext.getContextForService(service).await(),
serviceExecutionContext = serviceExecutionContext,
hydrationDetails = executionHydrationDetails,
executableNormalizedField = transformedQuery,
// Prefer non __typename field first, otherwise we just get first
executableNormalizedField = topLevelFields
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So this ServiceExecutionParameters.executableNormalizedField actually needs to be deprecated and removed but we are keeping it for now for compatibility.

It's currently used to extract the cloud ID for routing.

The reason why we went from ExecutableNormalizedField to List<ExecutableNormalizedField> is because the root level hydration transform injects a __typename field.

{
  batch_hydration__myIssues__myIssueKeys: myIssueKeys
  __typename__batch_hydration__myIssues: __typename
}

You could argue that we don't need a __typename for the operation types, but it's not a big deal to just keep it in.

Plus in the future we may end up grouping more root level fields into one execution, so this sort of lays the ground work for that.

}

private fun onlyTopLevelTypenameField(executableNormalizedField: ExecutableNormalizedField): Boolean {
if (executableNormalizedField.fieldName == TypeNameMetaFieldDef.name) {
private fun isOnlyTopLevelFieldTypename(topLevelFields: List<ExecutableNormalizedField>): Boolean {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This code here was modified a bit.

Context: we wanted to add code that would shortcut query execution IF there was only one field and it was __typename

Note: this code is protected by a FF hints.shortCircuitEmptyQuery(service) and it's mostly off because it hasn't been fully rolled out.


val service = definitionNamesToService[overallType.name]
?: coordinatesToService[fieldCoordinates]
?: error("Unable to determine service for $fieldCoordinates")
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Main fix is here.
Before we would do type name -> service.
This doesn't work for operation types.
So we now fall back to field name -> service.

russellyou
russellyou previously approved these changes Sep 9, 2024
@gnawf gnawf merged commit 2783a08 into master Sep 9, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants