The GraphQL API is currently not optimized for performance. Getting nested entities from a list, especially, results in a lot of queries.
Example.:
query ($filter: IssueMatchFilter) {
IssueMatches (filter: $filter) {
edges {
node {
componentInstance {
id
ccrn
component version {
id
}
}
cursor
}
}
}
This query would lead to a separate SQL query in the backend for each IssueMatch in the list and each of the component instances. When we get a list of 10 issue matches, we get 1+10 SQL queries. Like.:
SELECT * FROM IssueMatch WHERE $filter;
SELECT * FROM ComponenInstance WHERE ID=1;
SELECT * FROM ComponenInstance WHERE ID=2;
....
SELECT * FROM ComponenInstance WHERE ID=10;
This can be a major performance bottleneck, especially for deeper nested structures and long lists.
There is the concept of Dataloaders https://github.com/graphql/dataloader that circumvents this bottleneck by providing a "loader" that waits for a short period and collects all IDS used to request a result and instead provides an aggregated query and returns the individual results to the resolvers.
The result is that the queries in the above example will be reduced to 2:
SELECT * FROM IssueMatch WHERE $filter;
SELECT * FROM ComponenInstance WHERE ID IN(1, 2,3,4,5,6,7,8,9,10);
⚠️ The queries above are only for illustration purpose.
Therefore we need to investigate how we can do the above using gqlgen and how high the effort of implementation is.
Acceptance Criteria:
[ ] Find out how it could work for our Application
[ ] Get an understanding of the effort
[ ] PoC
[ ] Create a PoC PR to review
[ ] Decide whether we implement this situational in general
Expected Test:
A test that validates that the dataloaders are correctly used would be beneficial
Task Description
The GraphQL API is currently not optimized for performance. Getting nested entities from a list, especially, results in a lot of queries.
Example.:
This query would lead to a separate SQL query in the backend for each IssueMatch in the list and each of the component instances. When we get a list of 10 issue matches, we get 1+10 SQL queries. Like.:
This can be a major performance bottleneck, especially for deeper nested structures and long lists.
There is the concept of Dataloaders https://github.com/graphql/dataloader that circumvents this bottleneck by providing a "loader" that waits for a short period and collects all IDS used to request a result and instead provides an aggregated query and returns the individual results to the resolvers.
The result is that the queries in the above example will be reduced to 2:
⚠️ The queries above are only for illustration purpose.
Therefore we need to investigate how we can do the above using gqlgen and how high the effort of implementation is.
Acceptance Criteria:
Expected Test: