Technical details

The optimizer uses the GraphQLResolveInfo and GraphQL AST to introspect the desired query, and construct queryset.only(), queryset.select_related(), and queryset.prefetch_related() statements for the resolver queryset. The queryset is then "marked as optimized" in the queryset hints(1) by setting a key defined by the OPTIMIZER_MARK setting.

Queryset hints are designed to be used in multi-database routing, so this is a slightly hacky way to ensuring the mark is retained when the queryset is cloned. It is relatively safe since multi-database routers should accept the hints as **kwargs, and can ignore this extra hint.