Title: Question: Field selection and error handling in a batch loader? · Issue #53 · graphql-java/java-dataloader · GitHub
Open Graph Title: Question: Field selection and error handling in a batch loader? · Issue #53 · graphql-java/java-dataloader
X Title: Question: Field selection and error handling in a batch loader? · Issue #53 · graphql-java/java-dataloader
Description: I have two unrelated questions: 1. Error handling Neither org.dataloader.BatchLoader::load nor org.dataloader.BatchLoaderWithContext::load allow one to throw an exception while attempting to fetch some data from some source, because the ...
Open Graph Description: I have two unrelated questions: 1. Error handling Neither org.dataloader.BatchLoader::load nor org.dataloader.BatchLoaderWithContext::load allow one to throw an exception while attempting to fetch ...
X Description: I have two unrelated questions: 1. Error handling Neither org.dataloader.BatchLoader::load nor org.dataloader.BatchLoaderWithContext::load allow one to throw an exception while attempting to fetch ...
Opengraph URL: https://github.com/graphql-java/java-dataloader/issues/53
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Question: Field selection and error handling in a batch loader?","articleBody":"I have two unrelated questions:\r\n\r\n### 1. Error handling\r\n\r\nNeither `org.dataloader.BatchLoader::load` nor `org.dataloader.BatchLoaderWithContext::load` allow one to throw an exception while attempting to fetch some data from some source, because the interface does not declare that an exception is thrown:\r\n\r\n```java\r\n CompletionStage\u003cList\u003cV\u003e\u003e load(List\u003cK\u003e keys);\r\n```\r\n\r\nWhat is the correct way to handle an error, when, for example, my repository blows up while trying to load a list of entities by the provided keys? Similarly, what if some external HTTP request to fetch a list of entities fails in an unrecoverable way? It seems wrong in these cases to return an empty list; I would prefer to throw an exception and cause the entire GraphQL call stack to unwind instead of returning partial data.\r\n\r\n### 2. Field selection\r\n\r\nThe `BatchLoaderEnvironment` passed to a `BatchLoaderWithContext::load` call does not allow me to inspect the request for the selected fields that caused loading of some entities to occur. Is there a way to do this? I prefer to select only the columns absolutely necessary from the database/API/etc. to optimize performance.\r\n\r\nI can imagine that it may be difficult to traverse all nodes on the query to aggregate the minimum acceptable selection of fields from a given type, but it doesn't seem impossible. What I'm hoping is possible is something like this:\r\n\r\nGiven a query like this:\r\n```\r\nquery {\r\n foo {\r\n bar {\r\n fieldA\r\n fieldB\r\n fieldC\r\n }\r\n }\r\n bar {\r\n fieldA\r\n fieldD\r\n }\r\n}\r\n```\r\n\r\n...that I can be able to then only select fields A, B, C, and D, instead of a `SELECT *` (assuming a relational database is the backing store).\r\n\r\nThanks for your help!","author":{"url":"https://github.com/timrourke","@type":"Person","name":"timrourke"},"datePublished":"2019-09-23T22:26:53.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/53/java-dataloader/issues/53"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:cdbdf65e-ccb1-4cf7-cd81-b1a1e3b8d7fa |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 86DC:287443:AB6040:E49C54:69701726 |
| html-safe-nonce | ef5442608573cf5c1dd37d7cfa6f86065f7aad89d150af8614ffe2146e8bacd5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NkRDOjI4NzQ0MzpBQjYwNDA6RTQ5QzU0OjY5NzAxNzI2IiwidmlzaXRvcl9pZCI6IjM5NDE4ODQ4MzEwMDMwNTU5MTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 79c280a4b933159d999683082c63cb82f84c121280dfa9e5e914060e7699d376 |
| hovercard-subject-tag | issue:497359119 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/graphql-java/java-dataloader/53/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f6626571881f41233a112936dde17fd5bb64930b7fd7ff233d4fb0804fce99c5/graphql-java/java-dataloader/issues/53 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f6626571881f41233a112936dde17fd5bb64930b7fd7ff233d4fb0804fce99c5/graphql-java/java-dataloader/issues/53 |
| og:image:alt | I have two unrelated questions: 1. Error handling Neither org.dataloader.BatchLoader::load nor org.dataloader.BatchLoaderWithContext::load allow one to throw an exception while attempting to fetch ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | timrourke |
| hostname | github.com |
| expected-hostname | github.com |
| None | 043a09521e81f00c45482046b3f38390b8b292cf9a86ad665a632633a072c05c |
| turbo-cache-control | no-preview |
| go-import | github.com/graphql-java/java-dataloader git https://github.com/graphql-java/java-dataloader.git |
| octolytics-dimension-user_id | 14289921 |
| octolytics-dimension-user_login | graphql-java |
| octolytics-dimension-repository_id | 97364654 |
| octolytics-dimension-repository_nwo | graphql-java/java-dataloader |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 97364654 |
| octolytics-dimension-repository_network_root_nwo | graphql-java/java-dataloader |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 98881eadf8ae73000970c42161c094b0809b1330 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width