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

Cleanup error related code #1914

Merged
merged 6 commits into from
Jun 28, 2022
Merged

Conversation

pcmanus
Copy link
Contributor

@pcmanus pcmanus commented Jun 15, 2022

This PR started with wanting to remove our usages of the now deprecated GraphQLError that takes all arguments positionally (it's been deprecated by graphql-js in favour of a version that take a new GraphQLErrorOptions type).

Looking at this however, I noticed a few related cleanup and improvements that are in that PR. In particular:

  • we had our own GraphQLErrorParams in error.ts which was almost the same than GraphQLErrorOptions. The only difference being that we included the message in our own, while graphql-js decide to keep the message separate. It didn't felt meaningful to keep our own version just for what, so the first commit switch to extracting the message as it's own argument in our own error code and reusing GraphQLErrorOptions.
  • there was a number of cases where we where using new GraphQLError(...) but should really have been using a proper error code.

I'll note that this later point means that this patch introduce a few new error codes. As the error code doc is trying to track when code have been introduced, I've tentatively marked those as "adding: 2.1.0" but don't see this as any commitment: if the review of this slips by 2.1.0, I'll just update those pre-commit (once I know for sure where it lands).

@netlify
Copy link

netlify bot commented Jun 15, 2022

👷 Deploy request for apollo-federation-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit a676502

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jun 15, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@benweatherman benweatherman added this to the 2.1.0 milestone Jun 24, 2022
Copy link
Contributor

@benweatherman benweatherman left a comment

Choose a reason for hiding this comment

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

As always, 🐐

internals-js/src/definitions.ts Outdated Show resolved Hide resolved
internals-js/src/error.ts Show resolved Hide resolved
internals-js/src/federation.ts Outdated Show resolved Hide resolved
Sylvain Lebresne added 6 commits June 28, 2022 10:42
We had a `GraphQLErrorArgs` type that was almost equivalent to the
graphql-js `GraphQLErrorOptions`, and the reason being that the
later was added recently-ish, but keeping that slight inconsistency
doesn't make sense and this commit fixes.

It does imply mimicking the new `GraphQLError` constructor signature
which have the message first and the options, while we had put the
message inside the options on our side, so this imply changing all
the call sites, but it's one-off easy-if-annoying fix, so just went
with it.
That `error` was early that never was kept up-to-date with other
changes. In practice, it was called in one of 2 ways:
1. to check for code assertions (programmer errors). We have an
   `assert` method we use for this consistently and this commit use
   it for those usages.
2. for genuine graphql errors. But for those, we weren't giving
  a proper error code, so this commit switch to using the machinery from
  `error.ts` to handle those.

The result being that this `error()` method has been removed.
Noticed while working on the errors that we were duplicating the error
code that handled errors during the validation of a "field set", and
that's easy enough to make dryer.
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