grails / gorm-graphql

An automatic GraphQL schema generator for GORM
Apache License 2.0
80 stars 23 forks source link

More efficient custom dataFetchers by passing along DetachedCriteria #67

Closed jamesdh closed 3 years ago

jamesdh commented 3 years ago

Currently, if you supply your own dataFetcher for a given field, the GORM database query gets delineated at the point of that dataFetcher. The original query is executed as if the custom dataFetcher was not even provided (to the extent that the fields being queried were already part of the graph), and then any queries performed within the custom dataFetcher are executed in addition to that.

In the case of a deep object graph, with 1-to-Many associations and with potentially multiple custom dataFetchers, this becomes inefficient very quickly. It should be possible that instead we simply pass the unexecuted DetachedCriteria along to a deeper custom dataFetcher. That in turn could use DetachedCriteria's query composition abilities to modify the original query, so on and so forth, ultimately resulting in one single, efficient query.

jamesdh commented 3 years ago

This is especially relevant to #64 since I'm noticing that by supplying a custom dataFetcher on a field that already exists in the graph, you automatically go from having a single query to a minimum of two, and possibly many more if it's a 1-to-Many association.