Skip to content

Commit

Permalink
remove iterall, update types/tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lilianammmatos committed Jan 30, 2020
1 parent 2f415ad commit fb24857
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 60 deletions.
37 changes: 18 additions & 19 deletions src/__tests__/starWarsDeferredQuery-test.js
@@ -1,6 +1,5 @@
// @flow strict

import { forAwaitEach } from 'iterall';
import { expect } from 'chai';
import { describe, it } from 'mocha';

Expand Down Expand Up @@ -89,9 +88,9 @@ describe('Star Wars Query Deferred Tests', () => {

/* istanbul ignore else */
if (patchesIterable) {
await forAwaitEach(patchesIterable, patch => {
for await (const patch of patchesIterable) {
patches.push(patch);
});
}
}

expect(patches).to.have.lengthOf(1);
Expand Down Expand Up @@ -126,9 +125,9 @@ describe('Star Wars Query Deferred Tests', () => {

/* istanbul ignore else */
if (patchesIterable) {
await forAwaitEach(patchesIterable, patch => {
for await (const patch of patchesIterable) {
patches.push(patch);
});
}
}

expect(patches).to.have.lengthOf(1);
Expand Down Expand Up @@ -181,9 +180,9 @@ describe('Star Wars Query Deferred Tests', () => {

/* istanbul ignore else */
if (patchesIterable) {
await forAwaitEach(patchesIterable, patch => {
for await (const patch of patchesIterable) {
patches.push(patch);
});
}
}

expect(patches).to.have.lengthOf(2);
Expand Down Expand Up @@ -240,9 +239,9 @@ describe('Star Wars Query Deferred Tests', () => {

/* istanbul ignore else */
if (patchesIterable) {
await forAwaitEach(patchesIterable, patch => {
for await (const patch of patchesIterable) {
patches.push(patch);
});
}
}
expect(patches).to.have.lengthOf(1);
expect(patches[0]).to.deep.equal({
Expand Down Expand Up @@ -331,9 +330,9 @@ describe('Star Wars Query Deferred Tests', () => {

/* istanbul ignore else */
if (patchesIterable) {
await forAwaitEach(patchesIterable, patch => {
for await (const patch of patchesIterable) {
patches.push(patch);
});
}
}

expect(patches).to.have.lengthOf(2);
Expand Down Expand Up @@ -417,9 +416,9 @@ describe('Star Wars Query Deferred Tests', () => {

/* istanbul ignore else */
if (patchesIterable) {
await forAwaitEach(patchesIterable, patch => {
for await (const patch of patchesIterable) {
patches.push(patch);
});
}
}
expect(patches).to.have.lengthOf(1);
expect(patches[0]).to.deep.equal({
Expand Down Expand Up @@ -468,9 +467,9 @@ describe('Star Wars Query Deferred Tests', () => {

/* istanbul ignore else */
if (patchesIterable) {
await forAwaitEach(patchesIterable, patch => {
for await (const patch of patchesIterable) {
patches.push(patch);
});
}
}
expect(patches).to.have.lengthOf(1);
expect(patches[0]).to.deep.equal({
Expand Down Expand Up @@ -554,9 +553,9 @@ describe('Star Wars Query Deferred Tests', () => {

/* istanbul ignore else */
if (patchesIterable) {
await forAwaitEach(patchesIterable, patch => {
for await (const patch of patchesIterable) {
patches.push(patch);
});
}
}
expect(patches).to.have.lengthOf(1);
expect(patches[0]).to.deep.equal({
Expand Down Expand Up @@ -600,9 +599,9 @@ describe('Star Wars Query Deferred Tests', () => {

/* istanbul ignore else */
if (patchesIterable) {
await forAwaitEach(patchesIterable, patch => {
for await (const patch of patchesIterable) {
patches.push(patch);
});
}
}
expect(patches).to.have.lengthOf(1);
expect(patches[0]).to.deep.equal({
Expand Down
17 changes: 8 additions & 9 deletions src/__tests__/starWarsStreamQuery-test.js
@@ -1,6 +1,5 @@
// @flow strict

import { forAwaitEach } from 'iterall';
import { expect } from 'chai';
import { describe, it } from 'mocha';

Expand Down Expand Up @@ -217,9 +216,9 @@ describe('Star Wars Query Stream Tests', () => {

/* istanbul ignore else */
if (patchesIterable) {
await forAwaitEach(patchesIterable, patch => {
for await (const patch of patchesIterable) {
patches.push(patch);
});
}
}
expect(patches).to.have.lengthOf(1);
expect(patches[0]).to.deep.equal({
Expand Down Expand Up @@ -273,9 +272,9 @@ describe('Star Wars Query Stream Tests', () => {

/* istanbul ignore else */
if (patchesIterable) {
await forAwaitEach(patchesIterable, patch => {
for await (const patch of patchesIterable) {
patches.push(patch);
});
}
}
expect(patches).to.have.lengthOf(3);
expect(patches[0]).to.deep.equal({
Expand Down Expand Up @@ -336,9 +335,9 @@ describe('Star Wars Query Stream Tests', () => {

/* istanbul ignore else */
if (patchesIterable) {
await forAwaitEach(patchesIterable, patch => {
for await (const patch of patchesIterable) {
patches.push(patch);
});
}
}

expect(patches).to.have.lengthOf(1);
Expand Down Expand Up @@ -377,9 +376,9 @@ describe('Star Wars Query Stream Tests', () => {

/* istanbul ignore else */
if (patchesIterable) {
await forAwaitEach(patchesIterable, patch => {
for await (const patch of patchesIterable) {
patches.push(patch);
});
}
}

expect(patches).to.have.lengthOf(3);
Expand Down
4 changes: 2 additions & 2 deletions src/execution/dispatcher.js
@@ -1,6 +1,6 @@
// @flow strict

import { $$asyncIterator } from 'iterall';
import { SYMBOL_ASYNC_ITERATOR } from '../polyfills/symbols';

import { type Path, pathToArray } from '../jsutils/Path';
import { type PromiseOrValue } from '../jsutils/PromiseOrValue';
Expand Down Expand Up @@ -72,7 +72,7 @@ export class Dispatcher {
next() {
return getNext(results);
},
[$$asyncIterator]() {
[SYMBOL_ASYNC_ITERATOR]() {
return this;
},
}: any);
Expand Down
26 changes: 14 additions & 12 deletions src/execution/execute.js
Expand Up @@ -16,7 +16,6 @@ import promiseReduce from '../jsutils/promiseReduce';
import promiseForObject from '../jsutils/promiseForObject';
import { type PromiseOrValue } from '../jsutils/PromiseOrValue';
import { type Path, addPath, pathToArray } from '../jsutils/Path';
import { Dispatcher, type ExecutionPatchResult } from './dispatcher';

import { GraphQLError } from '../error/GraphQLError';
import { locatedError } from '../error/locatedError';
Expand Down Expand Up @@ -65,6 +64,8 @@ import {
import { typeFromAST } from '../utilities/typeFromAST';
import { getOperationRootType } from '../utilities/getOperationRootType';

import { Dispatcher, type ExecutionPatchResult } from './dispatcher';

import {
getVariableValues,
getArgumentValues,
Expand Down Expand Up @@ -548,9 +549,10 @@ export function collectFields(
continue;
}

const patchLabel = exeContext.schema.__experimentalDefer
? getDeferredNodeLabel(exeContext, selection)
: '';
const patchLabel =
exeContext.schema.__experimentalDefer === true
? getDeferredNodeLabel(exeContext, selection)
: '';

if (patchLabel) {
const { fields: patchFields } = collectFields(
Expand Down Expand Up @@ -584,9 +586,10 @@ export function collectFields(
continue;
}

const patchLabel = exeContext.schema.__experimentalDefer
? getDeferredNodeLabel(exeContext, selection)
: '';
const patchLabel =
exeContext.schema.__experimentalDefer === true
? getDeferredNodeLabel(exeContext, selection)
: '';

if (
visitedFragmentNames[fragName] &&
Expand Down Expand Up @@ -1083,7 +1086,7 @@ function completeListValue(
// since from here on it is not ever accessed by resolver functions.
const fieldPath = addPath(path, index);
if (
exeContext.schema.__experimentalStream &&
exeContext.schema.__experimentalStream === true &&
stream &&
stream.if !== false &&
typeof stream.label === 'string' &&
Expand Down Expand Up @@ -1120,11 +1123,10 @@ function completeListValue(
if (!containsPromise && isPromise(completedItem)) {
containsPromise = true;
}
}

return completedItem;
});

return completedItem;
}
}).filter(val => val !== undefined);
return containsPromise ? Promise.all(completedResults) : completedResults;
}

Expand Down
20 changes: 10 additions & 10 deletions src/type/schema.js
Expand Up @@ -172,6 +172,16 @@ export class GraphQLSchema {
// Provide specified directives (e.g. @include and @skip) by default.
this._directives = config.directives || specifiedDirectives;

if (config.experimentalDefer === true) {
this.__experimentalDefer = true;
this._directives = [].concat(this._directives, [GraphQLDeferDirective]);
}

if (config.experimentalStream === true) {
this.__experimentalStream = true;
this._directives = [].concat(this._directives, [GraphQLStreamDirective]);
}

// To preserve order of user-provided types, we add first to add them to
// the set of "collected" types, so `collectReferencedTypes` ignore them.
const allReferencedTypes: Set<GraphQLNamedType> = new Set(config.types);
Expand All @@ -184,16 +194,6 @@ export class GraphQLSchema {
}
}

if (config.experimentalDefer) {
this.__experimentalDefer = true;
this._directives = [].concat(this._directives, [GraphQLDeferDirective]);
}

if (config.experimentalStream) {
this.__experimentalStream = true;
this._directives = [].concat(this._directives, [GraphQLStreamDirective]);
}

if (this._queryType != null) {
collectReferencedTypes(this._queryType, allReferencedTypes);
}
Expand Down
6 changes: 0 additions & 6 deletions src/utilities/__tests__/schemaPrinter-test.js
Expand Up @@ -922,12 +922,6 @@ describe('Type System Printer', () => {
deprecationReason: String
}
# Marks an element of a GraphQL schema as no longer supported.
directive @deprecated(
# Explains why this element was deprecated, usually also including a suggestion for how to access supported similar data. Formatted using the Markdown syntax, as specified by [CommonMark](https://commonmark.org/).
reason: String = "No longer supported"
) on FIELD_DEFINITION | ENUM_VALUE
# A Directive provides a way to describe alternate runtime execution and type validation behavior in a GraphQL document.
#
# In some cases, you need to provide options to alter GraphQL's execution behavior in ways field arguments will not suffice, such as conditionally including or skipping a field. Directives provide this by describing additional information to the executor.
Expand Down
4 changes: 2 additions & 2 deletions src/utilities/buildASTSchema.js
Expand Up @@ -109,15 +109,15 @@ export function buildASTSchema(

if (
options &&
options.experimentalDefer &&
options.experimentalDefer === true &&
!directives.some(directive => directive.name === 'defer')
) {
directives.push(GraphQLDeferDirective);
}

if (
options &&
options.experimentalStream &&
options.experimentalStream === true &&
!directives.some(directive => directive.name === 'stream')
) {
directives.push(GraphQLStreamDirective);
Expand Down

0 comments on commit fb24857

Please sign in to comment.