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

Support for graphql@16 #5857

Merged
merged 4 commits into from
Nov 5, 2021

Conversation

IvanGoncharov
Copy link
Member

The only change required is in apollo-server-errors.
Alternative to #5844

@IvanGoncharov
Copy link
Member Author

Not updating graphql in devDependencies since it conflict with other dev dependencies (e.g. apollo-client, graphql-tag, etc.).
Locally tested with graphql@16.0.0 with npm i -f.

Copy link
Member

@glasser glasser left a comment

Choose a reason for hiding this comment

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

Very exciting!

Can you add a note about this to CHANGELOG.md? (I'd like us to eventually have a better mechanism for making changelogs than manually tracking them inside PRs in a single file, but that's what we do today.)

};
}
}

export class ApolloError extends Error implements GraphQLError {
Copy link
Member

Choose a reason for hiding this comment

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

Might be nice to throw in a comment noting that we'd like to switch to extends GraphQLError and look forward to doing so as soon as we drop support for <15.7.

Copy link
Member Author

Choose a reason for hiding this comment

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

done ✅

@@ -14,7 +25,7 @@ export class ApolloError extends Error implements GraphQLError {
readonly source: Source | undefined;
readonly positions: ReadonlyArray<number> | undefined;
readonly nodes: ReadonlyArray<ASTNode> | undefined;
public originalError: Error | null | undefined;
public originalError: Error | undefined;
Copy link
Member

Choose a reason for hiding this comment

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

To check my understanding: this is a safe change (that won't break users of graphql@15) because it's OK for an implementation of an interface to declare that a field has a type that is a subtype of the supertype's type?

Or I guess this is specifically the case because the interface (in v15) declared the field as readonly, which means that while ApolloError allows you to write e.originalError = null, that's unrelated to the GraphQLError declaration. (Because readonly just means "this interface doesn't provide the ability for you to change the field", not "the implementing type must forbid you from changing the field".)

Right?

Copy link
Member Author

Choose a reason for hiding this comment

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

@glasser Basically, we need to do this change to be compatible with v16.
From a purely theoretical position, it's a breaking change but I just can't figure out how to work around it.
In practical terms, I don't think it will break anyone especially since runtime behavior is the same.
Worst-case scenario library author (don't expect end-users to mess with originalError) need to change e.originalError = null to e.originalError = undefined.

Happy to replace it with some workaround that is less breaking I just can't come up with something right now.

Copy link
Member

Choose a reason for hiding this comment

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

Ah right, I was focused just on "will this work with graphql 15" and not "is this a backwards incompatible change for users". But I think it's fine. We'll make this a minor update at least.

packages/apollo-server-errors/src/index.ts Show resolved Hide resolved
packages/apollo-server-errors/src/index.ts Outdated Show resolved Hide resolved
packages/apollo-server-errors/src/index.ts Show resolved Hide resolved
@glasser
Copy link
Member

glasser commented Nov 1, 2021

@IvanGoncharov before we declare victory on 16 support can you look into the report at #5852? This is about an example in our docs, not the core code, but worth understanding what's going on there.

@IvanGoncharov
Copy link
Member Author

@IvanGoncharov before we declare victory on 16 support can you look into the report at #5852? This is about an example in our docs, not the core code, but worth understanding what's going on there.

@glasser Thanks for the ping, fixed in apollographql/subscriptions-transport-ws#902

arbitrary: 'user_data',
});

expect(error.toString()).toEqual('My original message');
Copy link
Member Author

Choose a reason for hiding this comment

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

That was useful.
I discovered a bug in graphql-js for toString we should follow Error.toString behavior so it should be ApolloError: My original message.

> e = new Error('test')
> e.name = 'TEST_NAME'
> e.toString()
'TEST_NAME: test'

I will fix it in the 16.0.x release, I don't think it would be a breaking change for both graphql-js and AS since I just added GraphQLError.toString in v16.0.0.

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense. If you're planning to change this in graphql-js, maybe just make this test accept either value? Or we can fix the test in the next graphql-js Renovate PR.

@IvanGoncharov
Copy link
Member Author

@glasser I updated the changelog and also addressed review comments.

Copy link
Member

@glasser glasser left a comment

Choose a reason for hiding this comment

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

Either you can merge this "tomorrow" and we can release it then (I can do the release or we can together), or I'll merge and release it on Thursday after doing a different thing.

arbitrary: 'user_data',
});

expect(error.toString()).toEqual('My original message');
Copy link
Member

Choose a reason for hiding this comment

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

Makes sense. If you're planning to change this in graphql-js, maybe just make this test accept either value? Or we can fix the test in the next graphql-js Renovate PR.

@glasser glasser enabled auto-merge (squash) November 5, 2021 16:52
@glasser glasser merged commit 13bf29e into apollographql:main Nov 5, 2021
glasser added a commit that referenced this pull request Nov 5, 2021
@karlhorky
Copy link

karlhorky commented Nov 7, 2021

Which package upgrades are necessary for users to use this PR? Only upgrading the single package apollo-datasource to 3.3.0?

Or maybe there's a new version of apollo-server itself?

@glasser
Copy link
Member

glasser commented Nov 7, 2021

This was released as part of Apollo Server 3.5.0.

apollo-datasource is an almost entirely unrelated caching HTTP client that is only in this repo for historical reasons; I can't imagine that it needed any changes for graphql@16 because it has nothing to do with GraphQL (other than that it's nice to have access to a caching HTTP client when implementing a GraphQL server).

@karlhorky
Copy link

Ah, ok, I was just going by the tag marked at the top of the PR.

Thanks for the answer!

@hwillson hwillson mentioned this pull request Nov 12, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 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.

None yet

3 participants