type-graphql
Advanced tools
Comparing version 0.13.1 to 0.14.0
@@ -27,2 +27,3 @@ "use strict"; | ||
typeOptions, | ||
complexity: options.complexity, | ||
target: prototype.constructor, | ||
@@ -39,2 +40,3 @@ description: options.description, | ||
handler: isResolverMethod ? prototype[propertyKey] : undefined, | ||
complexity: options.complexity, | ||
}); | ||
@@ -41,0 +43,0 @@ } |
@@ -37,2 +37,3 @@ "use strict"; | ||
typeOptions, | ||
complexity: options.complexity, | ||
description: options.description, | ||
@@ -39,0 +40,0 @@ deprecationReason: options.deprecationReason, |
@@ -1,2 +0,3 @@ | ||
import { ClassType, ClassTypeResolver, ResolverClassOptions } from "./types"; | ||
import { ClassTypeResolver, ResolverClassOptions } from "./types"; | ||
import { ClassType } from "../interfaces"; | ||
export declare function Resolver(): ClassDecorator; | ||
@@ -3,0 +4,0 @@ export declare function Resolver(options: ResolverClassOptions): ClassDecorator; |
@@ -1,4 +0,4 @@ | ||
import { ReturnTypeFunc, AdvancedOptions, SubscriptionFilterFunc } from "./types"; | ||
import { ReturnTypeFunc, AdvancedOptions, SubscriptionFilterFunc, SubscriptionTopicFunc } from "./types"; | ||
export interface SubscriptionOptions extends AdvancedOptions { | ||
topics: string | string[]; | ||
topics: string | string[] | SubscriptionTopicFunc; | ||
filter?: SubscriptionFilterFunc; | ||
@@ -5,0 +5,0 @@ } |
@@ -9,11 +9,11 @@ "use strict"; | ||
const { options, returnTypeFunc } = decorators_1.getTypeDecoratorParams(returnTypeFuncOrOptions, maybeOptions); | ||
const topics = [].concat(options.topics || []); | ||
return (prototype, methodName) => { | ||
const handler = handlers_1.getHandlerInfo(prototype, methodName, returnTypeFunc, options); | ||
if (topics.length === 0) { | ||
const subscriptionOptions = options; | ||
if (Array.isArray(options.topics) && options.topics.length === 0) { | ||
throw new errors_1.MissingSubscriptionTopicsError(handler.target, handler.methodName); | ||
} | ||
getMetadataStorage_1.getMetadataStorage().collectSubscriptionHandlerMetadata(Object.assign({}, handler, { topics, filter: options.filter })); | ||
getMetadataStorage_1.getMetadataStorage().collectSubscriptionHandlerMetadata(Object.assign({}, handler, { topics: subscriptionOptions.topics, filter: subscriptionOptions.filter })); | ||
}; | ||
} | ||
exports.Subscription = Subscription; |
import { GraphQLScalarType } from "graphql"; | ||
import { ValidatorOptions } from "class-validator"; | ||
import { ResolverFilterData } from "../interfaces"; | ||
import { ResolverFilterData, ClassType, ResolverTopicData, Complexity } from "../interfaces"; | ||
export declare type TypeValue = ClassType | GraphQLScalarType | Function | object | symbol; | ||
@@ -10,2 +10,3 @@ export declare type ReturnTypeFuncValue = TypeValue | [TypeValue]; | ||
export declare type SubscriptionFilterFunc = (resolverFilterData: ResolverFilterData<any, any, any>) => boolean | Promise<boolean>; | ||
export declare type SubscriptionTopicFunc = (resolverTopicData: ResolverTopicData<any, any, any>) => string | string[]; | ||
export interface DecoratorTypeOptions { | ||
@@ -26,2 +27,5 @@ nullable?: boolean; | ||
} | ||
export interface ComplexityOptions { | ||
complexity?: Complexity; | ||
} | ||
export interface SchemaNameOptions { | ||
@@ -31,6 +35,3 @@ name?: string; | ||
export declare type BasicOptions = DecoratorTypeOptions & DescriptionOptions; | ||
export declare type AdvancedOptions = BasicOptions & DepreciationOptions & SchemaNameOptions; | ||
export interface ClassType<T = any> { | ||
new (): T; | ||
} | ||
export declare type AdvancedOptions = BasicOptions & DepreciationOptions & SchemaNameOptions & ComplexityOptions; | ||
export interface EnumConfig { | ||
@@ -37,0 +38,0 @@ name: string; |
@@ -1,2 +0,3 @@ | ||
import { ClassType } from "./types"; | ||
import { ClassType } from "../interfaces"; | ||
import { InstanceSideOfClass, ArrayElementTypes } from "../helpers/utils"; | ||
export interface UnionTypeConfig<ObjectTypes extends ClassType[]> { | ||
@@ -7,12 +8,4 @@ name: string; | ||
} | ||
export declare function createUnionType<T1, T2>(config: UnionTypeConfig<[ClassType<T1>, ClassType<T2>]>): T1 | T2; | ||
export declare function createUnionType<T1, T2, T3>(config: UnionTypeConfig<[ClassType<T1>, ClassType<T2>, ClassType<T3>]>): T1 | T2 | T3; | ||
export declare function createUnionType<T1, T2, T3, T4>(config: UnionTypeConfig<[ClassType<T1>, ClassType<T2>, ClassType<T3>, ClassType<T4>]>): T1 | T2 | T3 | T4; | ||
export declare function createUnionType<T1, T2, T3, T4, T5>(config: UnionTypeConfig<[ClassType<T1>, ClassType<T2>, ClassType<T3>, ClassType<T4>, ClassType<T5>]>): T1 | T2 | T3 | T4 | T5; | ||
export declare function createUnionType<T1, T2, T3, T4, T5, T6>(config: UnionTypeConfig<[ClassType<T1>, ClassType<T2>, ClassType<T3>, ClassType<T4>, ClassType<T5>, ClassType<T6>]>): T1 | T2 | T3 | T4 | T5 | T6; | ||
export declare function createUnionType<T1, T2, T3, T4, T5, T6, T7>(config: UnionTypeConfig<[ClassType<T1>, ClassType<T2>, ClassType<T3>, ClassType<T4>, ClassType<T5>, ClassType<T6>, ClassType<T7>]>): T1 | T2 | T3 | T4 | T5 | T6 | T7; | ||
export declare function createUnionType<T1, T2, T3, T4, T5, T6, T7, T8>(config: UnionTypeConfig<[ClassType<T1>, ClassType<T2>, ClassType<T3>, ClassType<T4>, ClassType<T5>, ClassType<T6>, ClassType<T7>, ClassType<T8>]>): T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8; | ||
export declare function createUnionType<T1, T2, T3, T4, T5, T6, T7, T8, T9>(config: UnionTypeConfig<[ClassType<T1>, ClassType<T2>, ClassType<T3>, ClassType<T4>, ClassType<T5>, ClassType<T6>, ClassType<T7>, ClassType<T8>, ClassType<T9>]>): T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9; | ||
export declare function createUnionType<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(config: UnionTypeConfig<[ClassType<T1>, ClassType<T2>, ClassType<T3>, ClassType<T4>, ClassType<T5>, ClassType<T6>, ClassType<T7>, ClassType<T8>, ClassType<T9>, ClassType<T10>]>): T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9 | T10; | ||
export declare function createUnionType({ types, name, description, }: UnionTypeConfig<ClassType[]>): ClassType[]; | ||
export declare type UnionFromClasses<T extends any[]> = InstanceSideOfClass<ArrayElementTypes<T>>; | ||
export declare function createUnionType<T extends ClassType[]>({ types, name, description, }: UnionTypeConfig<T>): UnionFromClasses<T>; | ||
//# sourceMappingURL=unions.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const getMetadataStorage_1 = require("../metadata/getMetadataStorage"); | ||
// #endregion | ||
function createUnionType({ types, name, description }) { | ||
@@ -6,0 +5,0 @@ const unionMetadataSymbol = getMetadataStorage_1.getMetadataStorage().collectUnionMetadata({ |
@@ -26,4 +26,5 @@ "use strict"; | ||
deprecationReason: options.deprecationReason, | ||
complexity: options.complexity, | ||
}; | ||
} | ||
exports.getHandlerInfo = getHandlerInfo; |
@@ -23,5 +23,3 @@ "use strict"; | ||
case Date: | ||
return build_context_1.BuildContext.dateScalarMode === "isoDate" | ||
? isodate_1.GraphQLISODateTime | ||
: timestamp_1.GraphQLTimestamp; | ||
return build_context_1.BuildContext.dateScalarMode === "isoDate" ? isodate_1.GraphQLISODateTime : timestamp_1.GraphQLTimestamp; | ||
default: | ||
@@ -28,0 +26,0 @@ return undefined; |
export { MiddlewareFn, NextFn, MiddlewareInterface } from "./Middleware"; | ||
export * from "./AuthChecker"; | ||
export * from "./ClassType"; | ||
export * from "./Complexity"; | ||
export * from "./Publisher"; | ||
export * from "./ResolverData"; | ||
export * from "./ResolverFilterData"; | ||
export * from "./ResolverTopicData"; | ||
export * from "./ResolverInterface"; | ||
//# sourceMappingURL=index.d.ts.map |
import { ParamMetadata } from "./param-metadata"; | ||
import { TypeValueThunk, TypeOptions } from "../../decorators/types"; | ||
import { Middleware } from "../../interfaces/Middleware"; | ||
import { Complexity } from "../../interfaces"; | ||
export interface FieldMetadata { | ||
@@ -12,2 +13,3 @@ target: Function; | ||
deprecationReason: string | undefined; | ||
complexity: Complexity | undefined; | ||
params?: ParamMetadata[]; | ||
@@ -14,0 +16,0 @@ roles?: any[]; |
@@ -1,4 +0,5 @@ | ||
import { TypeValueThunk, TypeOptions, ClassTypeResolver, SubscriptionFilterFunc } from "../../decorators/types"; | ||
import { TypeValueThunk, TypeOptions, ClassTypeResolver, SubscriptionFilterFunc, SubscriptionTopicFunc } from "../../decorators/types"; | ||
import { ParamMetadata } from "./param-metadata"; | ||
import { Middleware } from "../../interfaces/Middleware"; | ||
import { Complexity } from "../../interfaces"; | ||
export interface BaseResolverMetadata { | ||
@@ -9,2 +10,3 @@ methodName: string; | ||
handler: Function | undefined; | ||
complexity: Complexity | undefined; | ||
resolverClassMetadata?: ResolverClassMetadata; | ||
@@ -31,3 +33,3 @@ params?: ParamMetadata[]; | ||
export interface SubscriptionResolverMetadata extends ResolverMetadata { | ||
topics: string[]; | ||
topics: string | string[] | SubscriptionTopicFunc; | ||
filter: SubscriptionFilterFunc | undefined; | ||
@@ -34,0 +36,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { ClassType } from "../../decorators/types"; | ||
import { ClassType } from "../../interfaces"; | ||
export interface UnionMetadata { | ||
@@ -3,0 +3,0 @@ types: ClassType[]; |
@@ -145,2 +145,3 @@ "use strict"; | ||
description: def.description, | ||
complexity: def.complexity, | ||
roles: def.roles, | ||
@@ -154,2 +155,3 @@ middlewares: def.middlewares, | ||
else { | ||
objectTypeField.complexity = def.complexity; | ||
if (objectTypeField.params.length === 0) { | ||
@@ -156,0 +158,0 @@ objectTypeField.params = def.params; |
{ | ||
"name": "type-graphql", | ||
"version": "0.13.1", | ||
"version": "0.14.0", | ||
"main": "./index.js", | ||
@@ -46,2 +46,3 @@ "author": { | ||
"graphql": "^0.13.2", | ||
"graphql-query-complexity": "^0.2.0", | ||
"graphql-subscriptions": "^0.5.8", | ||
@@ -76,2 +77,3 @@ "tslib": "^1.9.3" | ||
"jest": "^23.4.2", | ||
"lint-staged": "^7.2.2", | ||
"mysql": "^2.16.0", | ||
@@ -93,3 +95,4 @@ "prettier": "^1.14.0", | ||
"hooks": { | ||
"pre-push": "npm run verify" | ||
"pre-push": "npm run verify", | ||
"pre-commit": "lint-staged" | ||
} | ||
@@ -96,0 +99,0 @@ }, |
@@ -8,2 +8,3 @@ ![logo](https://github.com/19majkel94/type-graphql/blob/master/logo.png?raw=true) | ||
[![dependencies](https://david-dm.org/19majkel94/type-graphql/status.svg)](https://david-dm.org/19majkel94/type-graphql) | ||
[![install size](https://packagephobia.now.sh/badge?p=type-graphql)](https://packagephobia.now.sh/result?p=type-graphql) | ||
[![gitter](https://badges.gitter.im/type-graphql.svg)](https://gitter.im/type-graphql?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
@@ -47,3 +48,3 @@ | ||
@Field(type => [Rate]) | ||
ratings: Rate[] | ||
ratings: Rate[]; | ||
@@ -50,0 +51,0 @@ @Field({ nullable: true }) |
@@ -146,2 +146,3 @@ "use strict"; | ||
type: this.getGraphQLOutputType(field.name, field.getType(), field.typeOptions), | ||
complexity: field.complexity, | ||
args: this.generateHandlerArgs(field.params), | ||
@@ -255,2 +256,3 @@ resolve: fieldResolverMetadata | ||
deprecationReason: handler.deprecationReason, | ||
complexity: handler.complexity, | ||
}; | ||
@@ -268,8 +270,24 @@ return fields; | ||
} | ||
let pubSubIterator; | ||
if (typeof handler.topics === "function") { | ||
const getTopics = handler.topics; | ||
pubSubIterator = (payload, args, context, info) => { | ||
const resolverTopicData = { payload, args, context, info }; | ||
const topics = getTopics(resolverTopicData); | ||
if (Array.isArray(topics) && topics.length === 0) { | ||
throw new errors_1.MissingSubscriptionTopicsError(handler.target, handler.methodName); | ||
} | ||
return pubSub.asyncIterator(topics); | ||
}; | ||
} | ||
else { | ||
const topics = handler.topics; | ||
pubSubIterator = () => pubSub.asyncIterator(topics); | ||
} | ||
fields[handler.schemaName].subscribe = handler.filter | ||
? graphql_subscriptions_1.withFilter(() => pubSub.asyncIterator(handler.topics), (payload, args, context, info) => { | ||
? graphql_subscriptions_1.withFilter(pubSubIterator, (payload, args, context, info) => { | ||
const resolverFilterData = { payload, args, context, info }; | ||
return handler.filter(resolverFilterData); | ||
}) | ||
: () => pubSub.asyncIterator(handler.topics); | ||
: pubSubIterator; | ||
return fields; | ||
@@ -276,0 +294,0 @@ }, basicFields); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
128345
162
2607
191
9
39
+ Addedgraphql-query-complexity@0.2.3(transitive)
+ Addedlodash.get@4.4.2(transitive)