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

fix(types): Remove global ReadableStream override #3281

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

AdiRishi
Copy link

This PR attempts to solve the problem raised in n1ru4l/envelop#2104

Currently graphql-yoga overrides the ReadableStream interface in the global namespace. This causes issues in environments like cloudflare workers where @cloudflare/worker-types already overrides the global namespace with its own definitions of ReadableStream among other types.

Copy link

changeset-bot bot commented May 18, 2024

⚠️ No Changeset found

Latest commit: 13afaec

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

*
* See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncIterator
*/
export interface YogaReadableStreamOverride<R = any> extends ReadableStream<R> {
Copy link
Author

Choose a reason for hiding this comment

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

I was a bit torn on this name. I was thinking of using ReadableStreamWithAsyncIterator.
Would love some more perspectives on this name

@AdiRishi
Copy link
Author

A change like this could have some bad behaviors downstream. Users of the library may not realise that they rely on the override that graphql-yoga injected into their type definitions.

Curious to know what level of changeset we want for this change.

@@ -7,5 +7,6 @@
"lib": ["esnext", "DOM", "DOM.Iterable"],
"allowSyntheticDefaultImports": true,
"skipLibCheck": true
}
},
"include": ["src/*"]
Copy link
Author

Choose a reason for hiding this comment

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

Had to add this in as tsc was complaining about errors in graphql-yoga/src/server.ts
Many errors like this

> example-fastify@0.13.6 check /home/arishi/forks/graphql-yoga/examples/fastify
> tsc --pretty --noEmit

../../packages/graphql-yoga/src/server.ts:351:15 - error TS2578: Unused '@ts-expect-error' directive.

351               // @ts-expect-error Add plugins has context but this hook doesn't care
       

@n1ru4l n1ru4l requested a review from ardatan May 21, 2024 08:16
@ardatan
Copy link
Collaborator

ardatan commented May 21, 2024

n1ru4l/envelop#2104 (comment)
I am not sure if we should go with this kind of casting with extra functions and so on.
I know we should remove the global override at some point (this will also be part of the original TypeScript types), but until then we can just fix the type to match CloudFlare Workers' as I proposed in my comment there.

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.

None yet

2 participants