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

Handle errors better in merged schemas #425

Merged
merged 2 commits into from
Oct 11, 2017

Conversation

freiksenet
Copy link
Contributor

@freiksenet freiksenet commented Oct 11, 2017

  • Translate paths
  • Throw errors per field with errors from remote schema

TODO:

  • If this PR is a new feature, reference an issue where a consensus about the design was reached (not necessary for small changes)
  • Make sure all of the significant new logic is covered by tests
  • Rebase your changes on master so that they can be merged easily
  • Make sure all tests and linter rules pass
  • Update CHANGELOG.md with your change

* Translate paths
* Throw errors per field with errors from remote schema
context,
info,
) => {
const fieldName = info.fieldNodes[0].alias
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe call this responseKey to avoid confusion with info.fieldName?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

import { GraphQLResolveInfo, responsePathAsArray } from 'graphql';
import { locatedError } from 'graphql/error';

const ERROR_SYMBOL = Symbol('Schema Merging Error');
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe something like subSchemaErrors as the symbol name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

}
}
return {
childrenErrors,
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think I fully understand the logic, but is there ever a situation where you'd want to return both ownError and childrenErrors?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. I guess I should use algebraic type with 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.

Done.

const { ownError, childrenErrors } = getErrorsFromParent(parent, fieldName);
if (ownError) {
throw locatedError(
ownError.message,
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not for now I think, but we may want to make sure we can also support additional error fields besides message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So the problem is the implementation of locatedError, it copies all the fields like "location" and "path" that we actually want to recreate.

@freiksenet
Copy link
Contributor Author

@martijnwalraven All fixed.

@freiksenet freiksenet merged commit 3e4b61a into master Oct 11, 2017
@freiksenet freiksenet deleted the stitching-handle-errors-better branch October 11, 2017 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants