Skip to content

Commit

Permalink
Flow: add hack to support 'Symbol.asyncIterator' (graphql#2776)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov authored Aug 31, 2020
1 parent f3e2954 commit e5a2b77
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 8 deletions.
5 changes: 5 additions & 0 deletions flow-typed/core.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Various hacks to compensate for outdated Flow core definitions

declare class Symbol extends Symbol {
static asyncIterator: string; // polyfill '@@asyncIterator'
}
2 changes: 0 additions & 2 deletions src/jsutils/__tests__/isAsyncIterable-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import isAsyncIterable from '../isAsyncIterable';

describe('isAsyncIterable', () => {
it('should return `true` for AsyncIterable', () => {
// $FlowFixMe[prop-missing] Flow doesn't support Symbol.asyncIterator
const asyncIteratable = { [Symbol.asyncIterator]: identityFunc };
expect(isAsyncIterable(asyncIteratable)).to.equal(true);

Expand Down Expand Up @@ -45,7 +44,6 @@ describe('isAsyncIterable', () => {
expect(isAsyncIterable(generatorFunc())).to.equal(false);

const invalidAsyncIteratable = {
// $FlowFixMe[prop-missing] Flow doesn't support Symbol.asyncIterator
[Symbol.asyncIterator]: { next: identityFunc },
};
expect(isAsyncIterable(invalidAsyncIteratable)).to.equal(false);
Expand Down
2 changes: 0 additions & 2 deletions src/polyfills/symbols.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ export const SYMBOL_ITERATOR: string =
// In ES2017 (or a polyfilled) environment, this will be Symbol.asyncIterator
// istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2317')
export const SYMBOL_ASYNC_ITERATOR: string =
// $FlowFixMe[prop-missing] Flow doesn't define `Symbol.asyncIterator` yet
typeof Symbol === 'function' ? Symbol.asyncIterator : '@@asyncIterator';

// istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2317')
export const SYMBOL_TO_STRING_TAG: string =
// $FlowFixMe[incompatible-type] Flow doesn't define `Symbol.toStringTag` yet
typeof Symbol === 'function' ? Symbol.toStringTag : '@@toStringTag';
1 change: 0 additions & 1 deletion src/subscription/__tests__/eventEmitterAsyncIterator.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export default function eventEmitterAsyncIterator(
emptyQueue();
return Promise.reject(error);
},
// $FlowFixMe[prop-missing] Blocked by https://github.com/facebook/flow/issues/3258
[Symbol.asyncIterator]() {
return this;
},
Expand Down
3 changes: 0 additions & 3 deletions src/subscription/__tests__/mapAsyncIterator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ describe('mapAsyncIterator', () => {
const items = [1, 2, 3];

const iterator: any = {
// $FlowFixMe[prop-missing] Blocked by https://github.com/facebook/flow/issues/3258
[Symbol.asyncIterator]() {
return this;
},
Expand Down Expand Up @@ -122,7 +121,6 @@ describe('mapAsyncIterator', () => {
const items = [1, 2, 3];

const iterator: any = {
// $FlowFixMe[prop-missing] Blocked by https://github.com/facebook/flow/issues/3258
[Symbol.asyncIterator]() {
return this;
},
Expand Down Expand Up @@ -186,7 +184,6 @@ describe('mapAsyncIterator', () => {
const items = [1, 2, 3];

const iterator: any = {
// $FlowFixMe[prop-missing] Blocked by https://github.com/facebook/flow/issues/3258
[Symbol.asyncIterator]() {
return this;
},
Expand Down

0 comments on commit e5a2b77

Please sign in to comment.