Skip to content

Commit

Permalink
fix(TypeMapper): Accept GraphQL[EnumType, List, NonNull] as shortand …
Browse files Browse the repository at this point in the history
…for fieldConfig
  • Loading branch information
nodkz committed Mar 13, 2017
1 parent 6f775e7 commit 8cd56d1
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 15 deletions.
36 changes: 36 additions & 0 deletions src/__tests__/typeMapper-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,18 @@ describe('TypeMapper', () => {
expect(fc.type).equal(type);
});

it('should accept GraphQLNonNull', () => {
const fc = typeMapper.convertOutputFieldConfig(new GraphQLNonNull(GraphQLString));
expect(fc.type).instanceof(GraphQLNonNull);
expect(fc.type.ofType).equal(GraphQLString);
});

it('should accept GraphQLList', () => {
const fc = typeMapper.convertOutputFieldConfig(new GraphQLList(GraphQLString));
expect(fc.type).instanceof(GraphQLList);
expect(fc.type.ofType).equal(GraphQLString);
});

it('should accept type as string', () => {
const fc = typeMapper.convertOutputFieldConfig({
type: 'String',
Expand Down Expand Up @@ -313,6 +325,18 @@ describe('TypeMapper', () => {
expect(ic.type).equal(type);
});

it('should accept GraphQLNonNull', () => {
const ic = typeMapper.convertInputFieldConfig(new GraphQLNonNull(GraphQLString));
expect(ic.type).instanceof(GraphQLNonNull);
expect(ic.type.ofType).equal(GraphQLString);
});

it('should accept GraphQLList', () => {
const ic = typeMapper.convertInputFieldConfig(new GraphQLList(GraphQLString));
expect(ic.type).instanceof(GraphQLList);
expect(ic.type.ofType).equal(GraphQLString);
});

it('should accept type name as string', () => {
const ic = typeMapper.convertInputFieldConfig({
type: 'String',
Expand Down Expand Up @@ -463,6 +487,18 @@ describe('TypeMapper', () => {
expect(ac.type).equal(type);
});

it('should accept GraphQLNonNull', () => {
const ac = typeMapper.convertArgConfig(new GraphQLNonNull(GraphQLString));
expect(ac.type).instanceof(GraphQLNonNull);
expect(ac.type.ofType).equal(GraphQLString);
});

it('should accept GraphQLList', () => {
const ac = typeMapper.convertArgConfig(new GraphQLList(GraphQLString));
expect(ac.type).instanceof(GraphQLList);
expect(ac.type.ofType).equal(GraphQLString);
});

it('should accept type name as string', () => {
const ac = typeMapper.convertArgConfig({
type: 'String',
Expand Down
21 changes: 6 additions & 15 deletions src/typeMapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,7 @@ class TypeMapper {
);
}

if (
typeof fieldConfig === 'string' ||
fieldConfig instanceof GraphQLScalarType ||
fieldConfig instanceof GraphQLObjectType
) {
if (typeof fieldConfig === 'string' || isOutputType(fieldConfig)) {
fieldConfig = {
type: fieldConfig,
};
Expand Down Expand Up @@ -282,11 +278,8 @@ class TypeMapper {
);
}

if (
typeof argConfig === 'string' ||
argConfig instanceof GraphQLScalarType ||
argConfig instanceof GraphQLInputObjectType
) {
// $FlowFixMe
if (typeof argConfig === 'string' || isInputType(argConfig)) {
argConfig = {
// $FlowFixMe
type: argConfig,
Expand Down Expand Up @@ -377,12 +370,10 @@ class TypeMapper {
);
}

if (
typeof fieldConfig === 'string' ||
fieldConfig instanceof GraphQLScalarType ||
fieldConfig instanceof GraphQLInputObjectType
) {
// $FlowFixMe
if (typeof fieldConfig === 'string' || isInputType(fieldConfig)) {
fieldConfig = {
// $FlowFixMe
type: fieldConfig,
};
}
Expand Down

0 comments on commit 8cd56d1

Please sign in to comment.