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

Only one way of dealing with ApolloError extensions #5294

Merged
merged 1 commit into from
Jun 9, 2021

Conversation

glasser
Copy link
Member

@glasser glasser commented Jun 9, 2021

In Apollo Server 2, we had two different ways to specify extensions to
ApolloError:

new ApolloError(message, code, {ext1: value})
new ApolloError(message, code, {extensions: {ext1: value}})

and two different ways to read those extensions back:

error.extensions.ext1
error.ext1

This also meant that the extension values showed up twice in the
user-exposed errors list.

In Apollo Server 3, we have just one way to do it: the first line of
each of those pairs. That is, we treat the third argument to the
ApolloError constructor as "the extensions", not "the extensions or
maybe something wrapping the extensions"; and we only put the extensions
on error.extensions, not directly on error as well. (Note that the
built in code and exception extensions already only lived on
extensions rather than showing up twice!)

If you try to use the old {extensions: {...}} method, the ApolloServer
constructor throws instead of creating an extension named extensions.

Fixes #3835.

In Apollo Server 2, we had two different ways to specify extensions to
`ApolloError`:

    new ApolloError(message, code, {ext1: value})
    new ApolloError(message, code, {extensions: {ext1: value}})

and two different ways to read those extensions back:

    error.extensions.ext1
    error.ext1

This also meant that the extension values showed up twice in the
user-exposed errors list.

In Apollo Server 3, we have just one way to do it: the first line of
each of those pairs. That is, we treat the third argument to the
ApolloError constructor as "the extensions", not "the extensions or
maybe something wrapping the extensions"; and we only put the extensions
on `error.extensions`, not directly on `error` as well. (Note that the
built in `code` and `exception` extensions already only lived on
`extensions` rather than showing up twice!)

If you try to use the old `{extensions: {...}}` method, the ApolloServer
constructor throws instead of creating an extension named `extensions`.

Fixes #3835.
@glasser glasser enabled auto-merge (squash) June 9, 2021 22:24
@glasser glasser merged commit 36410aa into release-3.0 Jun 9, 2021
@glasser glasser deleted the glasser/extensions-only-one-place branch June 9, 2021 22:26
glasser added a commit that referenced this pull request Jun 18, 2021
glasser added a commit that referenced this pull request Jun 18, 2021
glasser added a commit that referenced this pull request Jun 22, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant