Skip to content

Commit

Permalink
Remove unnecessary try/catch block (#6488)
Browse files Browse the repository at this point in the history
  • Loading branch information
timleslie authored Sep 7, 2021
1 parent 144f7f8 commit bf33114
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
5 changes: 5 additions & 0 deletions .changeset/hot-cameras-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/fields-document': patch
---

Removed unnecessary try/catch block in relationship data resolver.
39 changes: 16 additions & 23 deletions packages/fields-document/src/relationship-data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,30 +49,23 @@ export function addRelationshipData(
const id = data?.id;
if (id != null) {
const labelField = getLabelFieldsForLists(graphQLAPI.schema)[relationship.listKey];
let val;
try {
val = await graphQLAPI.run({
query: `query($id: ID!) {item:${
gqlNames(relationship.listKey).itemQueryName
}(where: {id:$id}) {${labelFieldAlias}:${labelField}\n${
relationship.selection || ''
}}}`,
variables: { id },
});
if (val.item === null) {
if (!process.env.TEST_ADAPTER) {
// If we're unable to find the item (e.g. we have a dangling reference), or access was denied
// then simply return { id } and leave `label` and `data` undefined.
const r = JSON.stringify(relationship);
console.error(`Unable to fetch relationship data: relationship: ${r}, id: ${id} `);
}
return { id };
// An exception here indicates something wrong with either the system or the
// configuration (e.g. a bad selection field). These will surface as system
// errors from the GraphQL field resolver.
const val = await graphQLAPI.run({
query: `query($id: ID!) {item:${
gqlNames(relationship.listKey).itemQueryName
}(where: {id:$id}) {${labelFieldAlias}:${labelField}\n${relationship.selection || ''}}}`,
variables: { id },
});
if (val.item === null) {
if (!process.env.TEST_ADAPTER) {
// If we're unable to find the item (e.g. we have a dangling reference), or access was denied
// then simply return { id } and leave `label` and `data` undefined.
const r = JSON.stringify(relationship);
console.error(`Unable to fetch relationship data: relationship: ${r}, id: ${id} `);
}
} catch (err) {
// Errors indicate something wrong with either the system or the
// configuration (e.g. a bad selection field) and they should be surfaced as a
// GraphQL error.
throw err;
return { id };
}
return {
id,
Expand Down

0 comments on commit bf33114

Please sign in to comment.