Skip to content

Commit

Permalink
feat(InputTypeComposer): add method getTypePlural and `getTypeNonNu…
Browse files Browse the repository at this point in the history
…ll`. Method `getTypeAsRequired` is deprecated and will be removed in 5.0.0
  • Loading branch information
nodkz committed Apr 27, 2018
1 parent 80939c2 commit 6e554dc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
16 changes: 13 additions & 3 deletions src/InputTypeComposer.js
@@ -1,9 +1,9 @@
/* @flow strict */
/* eslint-disable no-use-before-define */

import { GraphQLInputObjectType, GraphQLNonNull, getNamedType } from './graphql';
import { GraphQLInputObjectType, GraphQLNonNull, GraphQLList, getNamedType } from './graphql';
import { resolveMaybeThunk } from './utils/misc';
// import { deprecate } from './utils/debug';
import { deprecate } from './utils/debug';
import { isObject, isString } from './utils/is';
import { resolveInputConfigMapAsThunk, resolveInputConfigAsThunk } from './utils/configAsThunk';
import { typeByPath } from './utils/typeByPath';
Expand Down Expand Up @@ -342,10 +342,20 @@ export class InputTypeComposer {
return this.gqType;
}

getTypeAsRequired(): GraphQLNonNull<GraphQLInputObjectType> {
getTypePlural(): GraphQLList<GraphQLInputObjectType> {
return new GraphQLList(this.gqType);
}

getTypeNonNull(): GraphQLNonNull<GraphQLInputObjectType> {
return new GraphQLNonNull(this.gqType);
}

/** @deprecated 5.0.0 */
getTypeAsRequired(): GraphQLNonNull<GraphQLInputObjectType> {
deprecate('Use `InputTypeComposer.getTypeNonNull` method instead of `getTypeAsRequired`');
return this.getTypeNonNull();
}

getTypeName(): string {
return this.gqType.name;
}
Expand Down
8 changes: 4 additions & 4 deletions src/TypeComposer.js
Expand Up @@ -411,6 +411,10 @@ export class TypeComposer<TContext> {
return this;
}

isFieldNonNull(fieldName: string): boolean {
return this.getFieldType(fieldName) instanceof GraphQLNonNull;
}

addRelation<TSource>(
fieldName: string,
opts: RelationOpts<TSource, TContext>
Expand Down Expand Up @@ -629,10 +633,6 @@ export class TypeComposer<TContext> {
return this.constructor.schemaComposer.TypeComposer.createTemp(fieldType);
}

isFieldNonNull(fieldName: string): boolean {
return this.getFieldType(fieldName) instanceof GraphQLNonNull;
}

makeFieldNonNull(fieldNameOrArray: string | Array<string>): TypeComposer<TContext> {
const fieldNames = Array.isArray(fieldNameOrArray) ? fieldNameOrArray : [fieldNameOrArray];
fieldNames.forEach(fieldName => {
Expand Down
11 changes: 8 additions & 3 deletions src/__tests__/InputTypeComposer-test.js
Expand Up @@ -264,9 +264,14 @@ describe('InputTypeComposer', () => {
expect(itc.getType().name).toBe('InputType');
});

it('getTypeAsRequired()', () => {
expect(itc.getTypeAsRequired()).toBeInstanceOf(GraphQLNonNull);
expect(itc.getTypeAsRequired().ofType.name).toBe('InputType');
it('getTypeNonNull()', () => {
expect(itc.getTypeNonNull()).toBeInstanceOf(GraphQLNonNull);
expect(itc.getTypeNonNull().ofType.name).toBe('InputType');
});

it('getTypePlural()', () => {
expect(itc.getTypePlural()).toBeInstanceOf(GraphQLList);
expect(itc.getTypePlural().ofType.name).toBe('InputType');
});

it('getTypeName()', () => {
Expand Down

0 comments on commit 6e554dc

Please sign in to comment.