Skip to content

feat(api-graphql): Add affected items in the errors object #11200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions packages/api-graphql/src/GraphQLAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@ export class GraphQLAPIClass {
errors: [error],
};
}

let response;
try {
response = await this._api.post(endpoint, init);
Expand All @@ -340,10 +339,32 @@ export class GraphQLAPIClass {
errors: [new GraphQLError(err.message, null, null, null, null, err)],
};
}

const { errors } = response;

if (errors && errors.length) {
let queryfield: string | null;
const null_values = errors.find((obj): boolean => {
if (obj.message.includes('Cannot return null for non-nullable type')) {
queryfield = obj.path[0] as string;
return true;
}
});
if (null_values && queryfield) {
const data_values: Array<String> = response.data[queryfield].items;
const query: string =
body.query.slice(0, body.query.indexOf('id') + 3) +
'}' +
body.query.slice(body.query.lastIndexOf('nextToken'));
init.body.query = query;
response.items = [];
const new_response = await this._api.post(endpoint, init);
const compare_values: Array<String> =
new_response.data[queryfield].items;
for (let index: number = 0; index < data_values.length; index++) {
if (!data_values[index]) {
response.items.push(compare_values[index]);
}
}
}
throw response;
}

Expand Down