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/related entities loading each in a separate query #1510

Merged

Conversation

juan871003
Copy link
Contributor

@juan871003 juan871003 commented Jan 13, 2025

Dataloader was sometimes being used, but in effect bypassed because a unique loader was used for every iteration of the for loop when resolvers were running.

This PR fixes this issue and restores dataloader's behaviour, as well as changing the loading strategy for MikroORM so we can better filter the related entities when doing this type of fetch.

juan871003 and others added 5 commits January 10, 2025 15:24
Set common loader key so we can properly batch related entities and make one call to findByRelatedId with all the batched keys.
```
const loaderKey = `${gqlTypeName}-${relatedField}-${JSON.stringify(
		filter
	)}`; /* gqlTypeName-fieldname-filterObject */
```
👆 The above code causes the `loaderKey` to be unique for each related entity instead of having a common key.

```
const loaderKey = `${gqlTypeName}-${relatedField}`; /* gqlTypeName-fieldname */
```
This makes a common key per entity and field
@thekevinbrown thekevinbrown changed the title Fix/related entities loading each in a separate querys Fix/related entities loading each in a separate query Jan 13, 2025
@thekevinbrown thekevinbrown marked this pull request as ready for review January 13, 2025 05:32
@thekevinbrown thekevinbrown merged commit bb2587c into main Jan 13, 2025
14 checks passed
@thekevinbrown thekevinbrown deleted the fix/related-entities-loading-each-in-a-separate-querys branch January 13, 2025 05:45
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.

2 participants