Skip to content
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

feat: [API] Merge non-GraphQL spec error fields into GraphQLError.extensions #401

Merged
merged 3 commits into from
Apr 30, 2020

Conversation

lawmicha
Copy link
Contributor

@lawmicha lawmicha commented Apr 23, 2020

Description of changes:
This change merges the graphQL error values with keys which do not match the GraphQL spec into the extensions JSON.

Android PR for reference aws-amplify/amplify-android#392

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@lawmicha lawmicha requested review from drochetti and wooj2 April 23, 2020 16:26
@lawmicha lawmicha force-pushed the feature/graphql-error-extensions branch from 1648234 to 042391e Compare April 23, 2020 16:31
@lawmicha lawmicha self-assigned this Apr 23, 2020
@lawmicha lawmicha added the api Issues related to the API category label Apr 23, 2020
@lawmicha lawmicha force-pushed the feature/graphql-error-extensions branch from 63cf3d9 to 5ac3f14 Compare April 27, 2020 15:29
return GraphQLError(message: graphQLError.message,
locations: graphQLError.locations,
path: graphQLError.path,
extensions: !mergedExtensions.isEmpty ? mergedExtensions : nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of the ! you could just invert the ternary result

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Comment on lines 55 to 59
if key == "message" ||
key == "locations" ||
key == "path" ||
key == "extensions" ||
mergedExtensions.keys.contains(key) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could have a list of keys and then append the mergedExtensions.keys into that list and just check for contains(key)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, updating

throw APIError.unknown("""
Unexpected failure while decoding GraphQL response containing errors:
\(String(describing: graphQLErrors))
""", "", error)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should that second argument contain something? Does the "report to AWS" suggestion fit here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like we already do that when exposed to the developer

case .unknown(_, let recoverySuggestion, _):
            return """
            \(recoverySuggestion)

            \(AmplifyErrorMessages.shouldNotHappenReportBugToAWS())
            """

@lawmicha lawmicha merged commit b87811c into master Apr 30, 2020
@lawmicha lawmicha deleted the feature/graphql-error-extensions branch May 11, 2020 23:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Issues related to the API category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants