Skip to content

Flow type errors #1

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

Open
wants to merge 2 commits into
base: wrapmethods
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/__tests__/starWarsSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
GraphQLEnumType,
GraphQLInterfaceType,
GraphQLObjectType,
GraphQLNonNull,
GraphQLSchema,
GraphQLString,
} from '../type';
Expand Down Expand Up @@ -109,7 +108,7 @@ const characterInterface = new GraphQLInterfaceType({
description: 'A character in the Star Wars Trilogy',
fields: () => ({
id: {
type: new GraphQLNonNull(GraphQLString),
type: GraphQLString.wrapNonNull(),
description: 'The id of the character.',
},
name: {
Expand Down Expand Up @@ -157,7 +156,7 @@ const humanType = new GraphQLObjectType({
description: 'A humanoid creature in the Star Wars universe.',
fields: () => ({
id: {
type: new GraphQLNonNull(GraphQLString),
type: GraphQLString.wrapNonNull(),
description: 'The id of the human.',
},
name: {
Expand Down Expand Up @@ -207,7 +206,7 @@ const droidType = new GraphQLObjectType({
description: 'A mechanical creature in the Star Wars universe.',
fields: () => ({
id: {
type: new GraphQLNonNull(GraphQLString),
type: GraphQLString.wrapNonNull(),
description: 'The id of the droid.',
},
name: {
Expand Down Expand Up @@ -272,7 +271,7 @@ const queryType = new GraphQLObjectType({
args: {
id: {
description: 'id of the human',
type: new GraphQLNonNull(GraphQLString)
type: GraphQLString.wrapNonNull()
}
},
resolve: (root, { id }) => getHuman(id),
Expand All @@ -282,7 +281,7 @@ const queryType = new GraphQLObjectType({
args: {
id: {
description: 'id of the droid',
type: new GraphQLNonNull(GraphQLString)
type: GraphQLString.wrapNonNull()
}
},
resolve: (root, { id }) => getDroid(id),
Expand Down
5 changes: 2 additions & 3 deletions src/execution/__tests__/executor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
GraphQLBoolean,
GraphQLInt,
GraphQLString,
GraphQLNonNull,
} from '../../type';

describe('Execute: Handles basic execution tasks', () => {
Expand Down Expand Up @@ -500,11 +499,11 @@ describe('Execute: Handles basic execution tasks', () => {
resolve: () => ({}),
},
nonNullA: {
type: new GraphQLNonNull(A),
type: A.wrapNonNull(),
resolve: () => ({}),
},
throws: {
type: new GraphQLNonNull(GraphQLString),
type: GraphQLString.wrapNonNull(),
resolve: () => {
throw new Error('Catch me if you can');
},
Expand Down
4 changes: 2 additions & 2 deletions src/execution/__tests__/lists-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ describe('Execute: Handles list nullability', () => {
});

describe('[T!]', () => {
const type = (new GraphQLNonNull(GraphQLInt)).wrapList();
const type = (GraphQLInt.wrapNonNull()).wrapList();

describe('Array<T>', () => {

Expand Down Expand Up @@ -369,7 +369,7 @@ describe('Execute: Handles list nullability', () => {

describe('[T!]!', () => {
const type =
new GraphQLNonNull((new GraphQLNonNull(GraphQLInt)).wrapList());
new GraphQLNonNull((GraphQLInt.wrapNonNull()).wrapList());

describe('Array<T>', () => {

Expand Down
9 changes: 4 additions & 5 deletions src/execution/__tests__/nonnull-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
GraphQLSchema,
GraphQLObjectType,
GraphQLString,
GraphQLNonNull
} from '../../type';

const syncError = new Error('sync');
Expand Down Expand Up @@ -106,13 +105,13 @@ const dataType = new GraphQLObjectType({
name: 'DataType',
fields: () => ({
sync: { type: GraphQLString },
nonNullSync: { type: new GraphQLNonNull(GraphQLString) },
nonNullSync: { type: GraphQLString.wrapNonNull() },
promise: { type: GraphQLString },
nonNullPromise: { type: new GraphQLNonNull(GraphQLString) },
nonNullPromise: { type: GraphQLString.wrapNonNull() },
nest: { type: dataType },
nonNullNest: { type: new GraphQLNonNull(dataType) },
nonNullNest: { type: dataType.wrapNonNull() },
promiseNest: { type: dataType },
nonNullPromiseNest: { type: new GraphQLNonNull(dataType) },
nonNullPromiseNest: { type: dataType.wrapNonNull() },
})
});
const schema = new GraphQLSchema({
Expand Down
3 changes: 1 addition & 2 deletions src/execution/__tests__/schema-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { parse } from '../../language';
import {
GraphQLSchema,
GraphQLObjectType,
GraphQLNonNull,
GraphQLInt,
GraphQLString,
GraphQLBoolean,
Expand Down Expand Up @@ -50,7 +49,7 @@ describe('Execute: Handles execution with a complex schema', () => {
const BlogArticle = new GraphQLObjectType({
name: 'Article',
fields: {
id: { type: new GraphQLNonNull(GraphQLString) },
id: { type: GraphQLString.wrapNonNull() },
isPublished: { type: GraphQLBoolean },
author: { type: BlogAuthor },
title: { type: GraphQLString },
Expand Down
12 changes: 6 additions & 6 deletions src/execution/__tests__/variables-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ const TestInputObject = new GraphQLInputObjectType({
fields: {
a: { type: GraphQLString },
b: { type: GraphQLString.wrapList() },
c: { type: new GraphQLNonNull(GraphQLString) },
c: { type: GraphQLString.wrapNonNull() },
d: { type: TestComplexScalar },
}
});

const TestNestedInputObject = new GraphQLInputObjectType({
name: 'TestNestedInputObject',
fields: {
na: { type: new GraphQLNonNull(TestInputObject) },
nb: { type: new GraphQLNonNull(GraphQLString) },
na: { type: TestInputObject.wrapNonNull() },
nb: { type: GraphQLString.wrapNonNull() },
},
});

Expand All @@ -77,7 +77,7 @@ const TestType = new GraphQLObjectType({
},
fieldWithNonNullableStringInput: {
type: GraphQLString,
args: { input: { type: new GraphQLNonNull(GraphQLString) } },
args: { input: { type: GraphQLString.wrapNonNull() } },
resolve: (_, { input }) => input && JSON.stringify(input)
},
fieldWithDefaultArgumentValue: {
Expand Down Expand Up @@ -106,13 +106,13 @@ const TestType = new GraphQLObjectType({
},
listNN: {
type: GraphQLString,
args: { input: { type: (new GraphQLNonNull(GraphQLString)).wrapList() } },
args: { input: { type: (GraphQLString.wrapNonNull()).wrapList() } },
resolve: (_, { input }) => input && JSON.stringify(input)
},
nnListNN: {
type: GraphQLString,
args: { input: { type:
new GraphQLNonNull((new GraphQLNonNull(GraphQLString)).wrapList())
new GraphQLNonNull((GraphQLString.wrapNonNull()).wrapList())
} },
resolve: (_, { input }) => input && JSON.stringify(input)
},
Expand Down
16 changes: 8 additions & 8 deletions src/type/__tests__/validation-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const SomeInputObjectType = new GraphQLInputObjectType({
function withModifiers(types) {
return types
.concat(types.map(type => type.wrapList()))
.concat(types.map(type => new GraphQLNonNull(type)))
.concat(types.map(type => type.wrapNonNull()))
.concat(types.map(type => new GraphQLNonNull(type.wrapList())));
}

Expand Down Expand Up @@ -1630,11 +1630,11 @@ describe('Type System: NonNull must accept GraphQL types', () => {
SomeEnumType,
SomeInputObjectType,
GraphQLString.wrapList(),
(new GraphQLNonNull(GraphQLString)).wrapList(),
(GraphQLString.wrapNonNull()).wrapList(),
];

const notNullableTypes = [
new GraphQLNonNull(GraphQLString),
GraphQLString.wrapNonNull(),
{},
String,
undefined,
Expand All @@ -1643,13 +1643,13 @@ describe('Type System: NonNull must accept GraphQL types', () => {

nullableTypes.forEach(type => {
it(`accepts an type as nullable type of non-null: ${type}`, () => {
expect(() => new GraphQLNonNull(type)).not.to.throw();
expect(() => type.wrapNonNull()).not.to.throw();
});
});

notNullableTypes.forEach(type => {
it(`rejects a non-type as nullable type of non-null: ${type}`, () => {
expect(() => new GraphQLNonNull(type)).to.throw(
expect(() => type.wrapNonNull()).to.throw(
`Can only create NonNull of a Nullable GraphQLType but got: ${type}.`
);
});
Expand Down Expand Up @@ -1781,7 +1781,7 @@ describe('Objects must adhere to Interface they implement', () => {
type: GraphQLString,
args: {
input: { type: GraphQLString },
anotherInput: { type: new GraphQLNonNull(GraphQLString) },
anotherInput: { type: GraphQLString.wrapNonNull() },
}
}
}
Expand Down Expand Up @@ -2085,7 +2085,7 @@ describe('Objects must adhere to Interface they implement', () => {
name: 'AnotherObject',
interfaces: [ AnotherInterface ],
fields: {
field: { type: new GraphQLNonNull(GraphQLString) }
field: { type: GraphQLString.wrapNonNull() }
}
});

Expand All @@ -2099,7 +2099,7 @@ describe('Objects must adhere to Interface they implement', () => {
name: 'AnotherInterface',
resolveType: () => null,
fields: {
field: { type: new GraphQLNonNull(GraphQLString) }
field: { type: GraphQLString.wrapNonNull() }
}
});

Expand Down
49 changes: 49 additions & 0 deletions src/type/definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ export class GraphQLScalarType {

_scalarConfig: GraphQLScalarTypeConfig<*, *>;
_wrappedList: ?GraphQLList<*>;
_wrappedNonNull: ?GraphQLNonNull<*>;

constructor(config: GraphQLScalarTypeConfig<*, *>): void {
assertValidName(config.name);
Expand Down Expand Up @@ -371,6 +372,12 @@ export class GraphQLScalarType {
return this._wrappedList || (this._wrappedList = new GraphQLList(this));
}

wrapNonNull(): GraphQLNonNull<*> {
return this._wrappedNonNull || (this._wrappedNonNull =
new GraphQLNonNull(this)
);
}

toJSON: () => string;
inspect: () => string;
}
Expand Down Expand Up @@ -439,6 +446,7 @@ export class GraphQLObjectType {
_fields: GraphQLFieldMap<*, *>;
_interfaces: Array<GraphQLInterfaceType>;
_wrappedList: ?GraphQLList<*>;
_wrappedNonNull: ?GraphQLNonNull<*>;

constructor(config: GraphQLObjectTypeConfig<*, *>): void {
assertValidName(config.name, config.isIntrospection);
Expand Down Expand Up @@ -476,6 +484,12 @@ export class GraphQLObjectType {
return this._wrappedList || (this._wrappedList = new GraphQLList(this));
}

wrapNonNull(): GraphQLNonNull<*> {
return this._wrappedNonNull || (this._wrappedNonNull =
new GraphQLNonNull(this)
);
}

toJSON: () => string;
inspect: () => string;
}
Expand Down Expand Up @@ -729,6 +743,7 @@ export class GraphQLInterfaceType {
_typeConfig: GraphQLInterfaceTypeConfig<*, *>;
_fields: GraphQLFieldMap<*, *>;
_wrappedList: ?GraphQLList<*>;
_wrappedNonNull: ?GraphQLNonNull<*>;

constructor(config: GraphQLInterfaceTypeConfig<*, *>): void {
assertValidName(config.name);
Expand Down Expand Up @@ -758,6 +773,12 @@ export class GraphQLInterfaceType {
return this._wrappedList || (this._wrappedList = new GraphQLList(this));
}

wrapNonNull(): GraphQLNonNull<*> {
return this._wrappedNonNull || (this._wrappedNonNull =
new GraphQLNonNull(this)
);
}

toJSON: () => string;
inspect: () => string;
}
Expand Down Expand Up @@ -814,6 +835,7 @@ export class GraphQLUnionType {
_typeConfig: GraphQLUnionTypeConfig<*, *>;
_types: Array<GraphQLObjectType>;
_wrappedList: ?GraphQLList<*>;
_wrappedNonNull: ?GraphQLNonNull<*>;

constructor(config: GraphQLUnionTypeConfig<*, *>): void {
assertValidName(config.name);
Expand Down Expand Up @@ -844,6 +866,12 @@ export class GraphQLUnionType {
return this._wrappedList || (this._wrappedList = new GraphQLList(this));
}

wrapNonNull(): GraphQLNonNull<*> {
return this._wrappedNonNull || (this._wrappedNonNull =
new GraphQLNonNull(this)
);
}

toJSON: () => string;
inspect: () => string;
}
Expand Down Expand Up @@ -936,6 +964,7 @@ export class GraphQLEnumType/* <T> */ {
_valueLookup: Map<any/* T */, GraphQLEnumValue>;
_nameLookup: ObjMap<GraphQLEnumValue>;
_wrappedList: ?GraphQLList<*>;
_wrappedNonNull: ?GraphQLNonNull<*>;

constructor(config: GraphQLEnumTypeConfig/* <T> */): void {
this.name = config.name;
Expand Down Expand Up @@ -1017,6 +1046,12 @@ export class GraphQLEnumType/* <T> */ {
return this._wrappedList || (this._wrappedList = new GraphQLList(this));
}

wrapNonNull(): GraphQLNonNull<*> {
return this._wrappedNonNull || (this._wrappedNonNull =
new GraphQLNonNull(this)
);
}

toJSON: () => string;
inspect: () => string;
}
Expand Down Expand Up @@ -1125,6 +1160,7 @@ export class GraphQLInputObjectType {
_typeConfig: GraphQLInputObjectTypeConfig;
_fields: GraphQLInputFieldMap;
_wrappedList: ?GraphQLList<*>;
_wrappedNonNull: ?GraphQLNonNull<*>;

constructor(config: GraphQLInputObjectTypeConfig): void {
assertValidName(config.name);
Expand Down Expand Up @@ -1181,6 +1217,12 @@ export class GraphQLInputObjectType {
return this._wrappedList || (this._wrappedList = new GraphQLList(this));
}

wrapNonNull(): GraphQLNonNull<*> {
return this._wrappedNonNull || (this._wrappedNonNull =
new GraphQLNonNull(this)
);
}

toJSON: () => string;
inspect: () => string;
}
Expand Down Expand Up @@ -1241,6 +1283,7 @@ export type GraphQLInputFieldMap =
export class GraphQLList<T: GraphQLType> {
ofType: T;
_wrappedList: ?GraphQLList<*>;
_wrappedNonNull: ?GraphQLNonNull<*>;

constructor(type: T): void {
invariant(
Expand All @@ -1258,6 +1301,12 @@ export class GraphQLList<T: GraphQLType> {
return this._wrappedList || (this._wrappedList = new GraphQLList(this));
}

wrapNonNull(): GraphQLNonNull<*> {
return this._wrappedNonNull || (this._wrappedNonNull =
new GraphQLNonNull(this)
);
}

toJSON: () => string;
inspect: () => string;
}
Expand Down
Loading