Skip to content

Commit

Permalink
CR fixes for union type
Browse files Browse the repository at this point in the history
  • Loading branch information
felipesabino committed Oct 25, 2017
1 parent 2b50893 commit eac7b48
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 11 deletions.
5 changes: 3 additions & 2 deletions src/decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { OrderByTypeFactory } from './order-by.type-factory';
import { PageInfo } from './page-info.type';
import { PaginationResponse } from './pagination.type';

export * from './decorator/';
export * from './metadata/options';

export const GQ_QUERY_KEY = 'gq_query';
export const GQ_MUTATION_KEY = 'gq_mutation';
export const GQ_SUBSCRIPTION_KEY = 'gq_subscription';
Expand All @@ -17,8 +20,6 @@ export const GQ_OBJECT_METADATA_KEY = 'gq_object_type';
export const GQ_ENUM_METADATA_KEY = 'gq_enum_type';
export const GQ_DESCRIPTION_KEY = 'gq_description';



export interface TypeMetadata {
name?: string;
description?: string;
Expand Down
4 changes: 2 additions & 2 deletions src/decorator/union-type.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { MetadataStorage } from '../metadata-storage';
import { UnionOpton } from '../metadata';
import { UnionOption } from '../metadata';

/**
* Union Type. ref: http://graphql.org/learn/schema/#union-types
* @param option Options for a Union Type
*/
export function UnionType<T>(option: UnionOpton<T>) {
export function UnionType<T>(option: UnionOption<T>) {
return function (target: any) {
MetadataStorage.addUnionMetadata({
name: target.name,
Expand Down
2 changes: 0 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
export * from './decorator';
export * from './decorator/';
export * from './metadata/options';
export { schemaFactory } from './schema_factory';
export * from './order-by-item';
export * from './pagination.type';
2 changes: 1 addition & 1 deletion src/metadata/options/union.option.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Arguments for a Union type on graphql schema
*/
export interface UnionOpton<T> {
export interface UnionOption<T> {
/**
* (Optional) Description
*/
Expand Down
3 changes: 1 addition & 2 deletions src/schema_factory.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'reflect-metadata';

import * as D from './decorator';
import * as DD from './decorator/';
import * as graphql from 'graphql';

import { SchemaFactoryError, SchemaFactoryErrorType, schemaFactory } from './schema_factory';
Expand Down Expand Up @@ -366,7 +365,7 @@ describe('schemaFactory', function() {
class ObjB { @D.Field() fieldB: string; }

type MyType = ObjA | ObjB;
@DD.UnionType<MyType>({
@D.UnionType<MyType>({
types: [ObjA, ObjB],
resolver: (obj: any): string | null => {
if (obj.fieldA) { return ObjA.name; }
Expand Down
4 changes: 2 additions & 2 deletions src/type-factory/union.type-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { MetadataStorage } from '../metadata-storage';
import { UnionTypeMetadata } from '../metadata';
import { objectTypeFactory } from '../object_type_factory';

export function unionTypeFactory(name: string, isInput: boolean): graphql.GraphQLUnionType {
export function unionTypeFactory(name: string, isInput: boolean): graphql.GraphQLUnionType | undefined {
return MetadataStorage.getUnionMetadata()
.filter(union => union.name === name)
.map(union => {
Expand All @@ -16,5 +16,5 @@ export function unionTypeFactory(name: string, isInput: boolean): graphql.GraphQ
.filter(_ => _), //filter null values
});
})
.find((_, index) => index === 0) || null;
.find((_, index) => index === 0);
}

0 comments on commit eac7b48

Please sign in to comment.