Address DORA metrics analytics GraphQL cache warning
Summary
In the DORA metrics analytics dashboard, we are making multiple queries to the Group.dora object to fetch data for the SingleStat and LineChart visualizations. This is causing the following warning to be thrown:
Cache data may be lost when replacing the dora field of a Group object.
To address this problem (which is not a bug in Apollo Client), either ensure all objects of type GroupDora have an ID or a custom merge function, or define a custom merge function for the Group.dora field, so InMemoryCache can safely merge these objects:
Though this is currently only occurring at the group level, it is likely to occur at the project level as well.
Steps to reproduce
-
Seed data:
SEED_DORA=1 FILTER=dora_metrics bundle exec rake db:seed_fu -
Enable the feature flags in rails console:
Feature.enable(:dora_metrics_dashboard) -
Create a new group/project, then navigate to
Analyze > Analytics dashboardsin the menu -
Select DORA metrics analytics
-
Open up the console and see the warning being thrown.
What is the current bug behavior?
Warning is being thrown:
Cache data may be lost when replacing the dora field of a Group object.
What is the expected correct behavior?
Warning is no longer thrown in the dashboard at either the group or project levels.
Relevant logs and/or screenshots
Cache data may be lost when replacing the dora field of a Group object.
To address this problem (which is not a bug in Apollo Client), either ensure all objects of type GroupDora have an ID or a custom merge function, or define a custom merge function for the Group.dora field, so InMemoryCache can safely merge these objects:
existing: {"__typename":"GroupDora","metrics({\"interval\":\"ALL\"})":[{"__typename":"DoraMetric","date":null,"deploymentFrequency":13.535911602209945,"changeFailureRate":0.06979591836734694,"leadTimeForChanges":25081,"timeToRestoreService":55198.5}]}
incoming: {"__typename":"GroupDora","metrics({\"interval\":\"DAILY\"})":[{"__typename":"DoraMetric","date":"2024-10-11","deploymentFrequency":null,"changeFailureRate":null,"leadTimeForChanges":null,"timeToRestoreService":null},{"__typename":"DoraMetric","date":"2024-10-12","deploymentFrequency":null,"changeFailureRate":null,"leadTimeForChanges":null,"timeToRestoreService":null},{"__typename":"DoraMetric","date":"2024-10-13","deploymentFrequency":null,"changeFailureRate":null,"leadTimeForChanges":null,"timeToRestoreService":null},{"__typename":"DoraMetric","date":"2024-10-14","deploymentFrequency":null,"changeFailureRate":null,"leadTimeForChanges":null,"timeToRestoreService":null},{"__typename":"DoraMetric","date":"2024-10-15","deploymentFrequency":null,"changeFailureRate":null,"leadTimeForChanges":null,"timeToRestoreService":null},{"__typename":"DoraMetric","date":"2024-10-16","deploymentFrequency":null,"changeFailureRate":null,"leadTimeForChanges":null,"timeToRestoreService":null},{"__typename"
Possible fixes
As per the frontend GraphQL docs, define a custom merge function.