type-graphql
Advanced tools
Comparing version 0.11.1 to 0.11.2
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const metadata_storage_1 = require("../metadata/metadata-storage"); | ||
const getMetadataStorage_1 = require("../metadata/getMetadataStorage"); | ||
const params_1 = require("../helpers/params"); | ||
@@ -9,5 +9,5 @@ const decorators_1 = require("../helpers/decorators"); | ||
const { options, returnTypeFunc } = decorators_1.getTypeDecoratorParams(returnTypeFuncOrOptions, maybeOptions); | ||
metadata_storage_1.MetadataStorage.collectHandlerParamMetadata(Object.assign({ kind: "arg", name, description: options.description }, params_1.getParamInfo({ prototype, propertyKey, parameterIndex, returnTypeFunc, options }))); | ||
getMetadataStorage_1.getMetadataStorage().collectHandlerParamMetadata(Object.assign({ kind: "arg", name, description: options.description }, params_1.getParamInfo({ prototype, propertyKey, parameterIndex, returnTypeFunc, options }))); | ||
}; | ||
} | ||
exports.Arg = Arg; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const metadata_storage_1 = require("../metadata/metadata-storage"); | ||
const getMetadataStorage_1 = require("../metadata/getMetadataStorage"); | ||
const params_1 = require("../helpers/params"); | ||
function Args(options = {}) { | ||
return (prototype, propertyKey, parameterIndex) => { | ||
metadata_storage_1.MetadataStorage.collectHandlerParamMetadata(Object.assign({ kind: "args" }, params_1.getParamInfo({ prototype, propertyKey, parameterIndex, options }))); | ||
getMetadataStorage_1.getMetadataStorage().collectHandlerParamMetadata(Object.assign({ kind: "args" }, params_1.getParamInfo({ prototype, propertyKey, parameterIndex, options }))); | ||
}; | ||
} | ||
exports.Args = Args; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const metadata_storage_1 = require("../metadata/metadata-storage"); | ||
const getMetadataStorage_1 = require("../metadata/getMetadataStorage"); | ||
function ArgsType() { | ||
return target => { | ||
metadata_storage_1.MetadataStorage.collectArgsMetadata({ | ||
getMetadataStorage_1.getMetadataStorage().collectArgsMetadata({ | ||
name: target.name, | ||
@@ -8,0 +8,0 @@ target, |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const metadata_storage_1 = require("../metadata/metadata-storage"); | ||
const getMetadataStorage_1 = require("../metadata/getMetadataStorage"); | ||
const errors_1 = require("../errors"); | ||
@@ -12,3 +12,3 @@ const decorators_1 = require("../helpers/decorators"); | ||
} | ||
metadata_storage_1.MetadataStorage.collectAuthorizedFieldMetadata({ | ||
getMetadataStorage_1.getMetadataStorage().collectAuthorizedFieldMetadata({ | ||
target: prototype.constructor, | ||
@@ -15,0 +15,0 @@ fieldName: propertyKey, |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const metadata_storage_1 = require("../metadata/metadata-storage"); | ||
const getMetadataStorage_1 = require("../metadata/getMetadataStorage"); | ||
const errors_1 = require("../errors"); | ||
@@ -10,3 +10,3 @@ function Ctx(propertyName) { | ||
} | ||
metadata_storage_1.MetadataStorage.collectHandlerParamMetadata({ | ||
getMetadataStorage_1.getMetadataStorage().collectHandlerParamMetadata({ | ||
kind: "context", | ||
@@ -13,0 +13,0 @@ target: prototype.constructor, |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const metadata_storage_1 = require("../metadata/metadata-storage"); | ||
const getMetadataStorage_1 = require("../metadata/getMetadataStorage"); | ||
function registerEnumType(enumObj, enumConfig) { | ||
metadata_storage_1.MetadataStorage.collectEnumMetadata({ | ||
getMetadataStorage_1.getMetadataStorage().collectEnumMetadata({ | ||
enumObj, | ||
@@ -7,0 +7,0 @@ name: enumConfig.name, |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const metadata_storage_1 = require("../metadata/metadata-storage"); | ||
const getMetadataStorage_1 = require("../metadata/getMetadataStorage"); | ||
const findType_1 = require("../helpers/findType"); | ||
@@ -22,3 +22,3 @@ const decorators_1 = require("../helpers/decorators"); | ||
}); | ||
metadata_storage_1.MetadataStorage.collectClassFieldMetadata({ | ||
getMetadataStorage_1.getMetadataStorage().collectClassFieldMetadata({ | ||
name: propertyKey, | ||
@@ -32,3 +32,3 @@ getType, | ||
if (isResolver) { | ||
metadata_storage_1.MetadataStorage.collectFieldResolverMetadata({ | ||
getMetadataStorage_1.getMetadataStorage().collectFieldResolverMetadata({ | ||
kind: "internal", | ||
@@ -35,0 +35,0 @@ methodName: propertyKey, |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const metadata_storage_1 = require("../metadata/metadata-storage"); | ||
const getMetadataStorage_1 = require("../metadata/getMetadataStorage"); | ||
const errors_1 = require("../errors"); | ||
@@ -29,3 +29,3 @@ const decorators_1 = require("../helpers/decorators"); | ||
catch (_a) { } | ||
metadata_storage_1.MetadataStorage.collectFieldResolverMetadata({ | ||
getMetadataStorage_1.getMetadataStorage().collectFieldResolverMetadata({ | ||
kind: "external", | ||
@@ -32,0 +32,0 @@ methodName: propertyKey, |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const metadata_storage_1 = require("../metadata/metadata-storage"); | ||
const getMetadataStorage_1 = require("../metadata/getMetadataStorage"); | ||
const errors_1 = require("../errors"); | ||
@@ -10,3 +10,3 @@ function Info() { | ||
} | ||
metadata_storage_1.MetadataStorage.collectHandlerParamMetadata({ | ||
getMetadataStorage_1.getMetadataStorage().collectHandlerParamMetadata({ | ||
kind: "info", | ||
@@ -13,0 +13,0 @@ target: prototype.constructor, |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const metadata_storage_1 = require("../metadata/metadata-storage"); | ||
const getMetadataStorage_1 = require("../metadata/getMetadataStorage"); | ||
const decorators_1 = require("../helpers/decorators"); | ||
@@ -8,3 +8,3 @@ function InputType(nameOrOptions, maybeOptions) { | ||
return target => { | ||
metadata_storage_1.MetadataStorage.collectInputMetadata({ | ||
getMetadataStorage_1.getMetadataStorage().collectInputMetadata({ | ||
name: name || target.name, | ||
@@ -11,0 +11,0 @@ target, |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const metadata_storage_1 = require("../metadata/metadata-storage"); | ||
const getMetadataStorage_1 = require("../metadata/getMetadataStorage"); | ||
const decorators_1 = require("../helpers/decorators"); | ||
@@ -8,3 +8,3 @@ function InterfaceType(nameOrOptions, maybeOptions) { | ||
return target => { | ||
metadata_storage_1.MetadataStorage.collectInterfaceMetadata({ | ||
getMetadataStorage_1.getMetadataStorage().collectInterfaceMetadata({ | ||
name: name || target.name, | ||
@@ -11,0 +11,0 @@ target, |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const metadata_storage_1 = require("../metadata/metadata-storage"); | ||
const getMetadataStorage_1 = require("../metadata/getMetadataStorage"); | ||
const handlers_1 = require("../helpers/handlers"); | ||
@@ -10,5 +10,5 @@ const decorators_1 = require("../helpers/decorators"); | ||
const handler = handlers_1.getHandlerInfo(prototype, methodName, returnTypeFunc, options); | ||
metadata_storage_1.MetadataStorage.collectMutationHandlerMetadata(handler); | ||
getMetadataStorage_1.getMetadataStorage().collectMutationHandlerMetadata(handler); | ||
}; | ||
} | ||
exports.Mutation = Mutation; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const metadata_storage_1 = require("../metadata/metadata-storage"); | ||
const getMetadataStorage_1 = require("../metadata/getMetadataStorage"); | ||
const decorators_1 = require("../helpers/decorators"); | ||
@@ -9,3 +9,3 @@ function ObjectType(nameOrOptions, maybeOptions) { | ||
return target => { | ||
metadata_storage_1.MetadataStorage.collectObjectMetadata({ | ||
getMetadataStorage_1.getMetadataStorage().collectObjectMetadata({ | ||
name: name || target.name, | ||
@@ -12,0 +12,0 @@ target, |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const metadata_storage_1 = require("../metadata/metadata-storage"); | ||
const getMetadataStorage_1 = require("../metadata/getMetadataStorage"); | ||
const errors_1 = require("../errors"); | ||
@@ -10,3 +10,3 @@ function PubSub(triggerKey) { | ||
} | ||
metadata_storage_1.MetadataStorage.collectHandlerParamMetadata({ | ||
getMetadataStorage_1.getMetadataStorage().collectHandlerParamMetadata({ | ||
kind: "pubSub", | ||
@@ -13,0 +13,0 @@ target: prototype.constructor, |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const metadata_storage_1 = require("../metadata/metadata-storage"); | ||
const getMetadataStorage_1 = require("../metadata/getMetadataStorage"); | ||
const handlers_1 = require("../helpers/handlers"); | ||
@@ -10,5 +10,5 @@ const decorators_1 = require("../helpers/decorators"); | ||
const handler = handlers_1.getHandlerInfo(prototype, methodName, returnTypeFunc, options); | ||
metadata_storage_1.MetadataStorage.collectQueryHandlerMetadata(handler); | ||
getMetadataStorage_1.getMetadataStorage().collectQueryHandlerMetadata(handler); | ||
}; | ||
} | ||
exports.Query = Query; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const metadata_storage_1 = require("../metadata/metadata-storage"); | ||
const getMetadataStorage_1 = require("../metadata/getMetadataStorage"); | ||
function Resolver(objectTypeOrTypeFunc) { | ||
@@ -13,3 +13,3 @@ return target => { | ||
}; | ||
metadata_storage_1.MetadataStorage.collectResolverClassMetadata({ | ||
getMetadataStorage_1.getMetadataStorage().collectResolverClassMetadata({ | ||
target, | ||
@@ -16,0 +16,0 @@ getObjectType, |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const metadata_storage_1 = require("../metadata/metadata-storage"); | ||
const getMetadataStorage_1 = require("../metadata/getMetadataStorage"); | ||
const findType_1 = require("../helpers/findType"); | ||
@@ -24,3 +24,3 @@ const errors_1 = require("../errors"); | ||
} | ||
metadata_storage_1.MetadataStorage.collectHandlerParamMetadata({ | ||
getMetadataStorage_1.getMetadataStorage().collectHandlerParamMetadata({ | ||
kind: "root", | ||
@@ -27,0 +27,0 @@ target: prototype.constructor, |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const metadata_storage_1 = require("../metadata/metadata-storage"); | ||
const getMetadataStorage_1 = require("../metadata/getMetadataStorage"); | ||
const handlers_1 = require("../helpers/handlers"); | ||
@@ -15,5 +15,5 @@ const decorators_1 = require("../helpers/decorators"); | ||
} | ||
metadata_storage_1.MetadataStorage.collectSubscriptionHandlerMetadata(Object.assign({}, handler, { topics, filter: options.filter })); | ||
getMetadataStorage_1.getMetadataStorage().collectSubscriptionHandlerMetadata(Object.assign({}, handler, { topics, filter: options.filter })); | ||
}; | ||
} | ||
exports.Subscription = Subscription; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const metadata_storage_1 = require("../metadata/metadata-storage"); | ||
const getMetadataStorage_1 = require("../metadata/getMetadataStorage"); | ||
// #endregion | ||
function createUnionType({ types, name, description }) { | ||
const unionMetadata = metadata_storage_1.MetadataStorage.collectUnionMetadata({ | ||
const unionMetadata = getMetadataStorage_1.getMetadataStorage().collectUnionMetadata({ | ||
types, | ||
@@ -8,0 +8,0 @@ name, |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const errors_1 = require("../errors"); | ||
const metadata_storage_1 = require("../metadata/metadata-storage"); | ||
const getMetadataStorage_1 = require("../metadata/getMetadataStorage"); | ||
const decorators_1 = require("../helpers/decorators"); | ||
@@ -12,3 +12,3 @@ function UseMiddleware(...middlewaresOrMiddlewareArray) { | ||
} | ||
metadata_storage_1.MetadataStorage.collectMiddlewareMetadata({ | ||
getMetadataStorage_1.getMetadataStorage().collectMiddlewareMetadata({ | ||
target: prototype.constructor, | ||
@@ -15,0 +15,0 @@ fieldName: propertyKey, |
@@ -7,3 +7,3 @@ export * from "./decorators"; | ||
export { useContainer } from "./utils/container"; | ||
export { ActionData, FilterActionData } from "./types"; | ||
export { ResolverData, ResolverFilterData } from "./types"; | ||
export { PubSubEngine } from "graphql-subscriptions"; |
@@ -1,3 +0,3 @@ | ||
import { ActionData } from "../types/action-data"; | ||
export declare type AuthChecker<ContextType = {}> = (actionData: ActionData<ContextType>, roles: string[]) => boolean | Promise<boolean>; | ||
import { ResolverData } from "../types/action-data"; | ||
export declare type AuthChecker<ContextType = {}> = (resolverData: ResolverData<ContextType>, roles: string[]) => boolean | Promise<boolean>; | ||
export declare type AuthMode = "error" | "null"; |
@@ -1,4 +0,4 @@ | ||
import { ActionData } from "../types"; | ||
import { ResolverData } from "../types"; | ||
export declare type NextFn = () => Promise<any>; | ||
export declare type MiddlewareFn<TContext = {}> = (action: ActionData<TContext>, next: NextFn) => Promise<any>; | ||
export declare type MiddlewareFn<TContext = {}> = (action: ResolverData<TContext>, next: NextFn) => Promise<any>; | ||
export interface MiddlewareInterface<TContext = {}> { | ||
@@ -5,0 +5,0 @@ use: MiddlewareFn<TContext>; |
import { ResolverMetadata, ClassMetadata, FieldMetadata, ParamMetadata, FieldResolverMetadata, AuthorizedMetadata, EnumMetadata, UnionMetadata, UnionMetadataWithSymbol, ResolverClassMetadata, SubscriptionResolverMetadata, MiddlewareMetadata } from "./definitions"; | ||
export declare abstract class MetadataStorage { | ||
static queries: ResolverMetadata[]; | ||
static mutations: ResolverMetadata[]; | ||
static subscriptions: SubscriptionResolverMetadata[]; | ||
static fieldResolvers: FieldResolverMetadata[]; | ||
static objectTypes: ClassMetadata[]; | ||
static inputTypes: ClassMetadata[]; | ||
static argumentTypes: ClassMetadata[]; | ||
static interfaceTypes: ClassMetadata[]; | ||
static authorizedFields: AuthorizedMetadata[]; | ||
static enums: EnumMetadata[]; | ||
static unions: UnionMetadataWithSymbol[]; | ||
static middlewares: MiddlewareMetadata[]; | ||
private static resolvers; | ||
private static fields; | ||
private static params; | ||
static collectQueryHandlerMetadata(definition: ResolverMetadata): void; | ||
static collectMutationHandlerMetadata(definition: ResolverMetadata): void; | ||
static collectSubscriptionHandlerMetadata(definition: SubscriptionResolverMetadata): void; | ||
static collectFieldResolverMetadata(definition: FieldResolverMetadata): void; | ||
static collectObjectMetadata(definition: ClassMetadata): void; | ||
static collectInputMetadata(definition: ClassMetadata): void; | ||
static collectArgsMetadata(definition: ClassMetadata): void; | ||
static collectInterfaceMetadata(definition: ClassMetadata): void; | ||
static collectAuthorizedFieldMetadata(definition: AuthorizedMetadata): void; | ||
static collectEnumMetadata(definition: EnumMetadata): void; | ||
static collectUnionMetadata(definition: UnionMetadata): symbol; | ||
static collectMiddlewareMetadata(definition: MiddlewareMetadata): void; | ||
static collectResolverClassMetadata(definition: ResolverClassMetadata): void; | ||
static collectClassFieldMetadata(definition: FieldMetadata): void; | ||
static collectHandlerParamMetadata(definition: ParamMetadata): void; | ||
static build(): void; | ||
static clear(): void; | ||
private static buildClassMetadata(definitions); | ||
private static buildResolversMetadata(definitions); | ||
private static buildFieldResolverMetadata(definitions); | ||
private static findFieldRoles(target, fieldName); | ||
private static mapMetadataToMiddlewares(metadata); | ||
export declare class MetadataStorage { | ||
queries: ResolverMetadata[]; | ||
mutations: ResolverMetadata[]; | ||
subscriptions: SubscriptionResolverMetadata[]; | ||
fieldResolvers: FieldResolverMetadata[]; | ||
objectTypes: ClassMetadata[]; | ||
inputTypes: ClassMetadata[]; | ||
argumentTypes: ClassMetadata[]; | ||
interfaceTypes: ClassMetadata[]; | ||
authorizedFields: AuthorizedMetadata[]; | ||
enums: EnumMetadata[]; | ||
unions: UnionMetadataWithSymbol[]; | ||
middlewares: MiddlewareMetadata[]; | ||
private resolvers; | ||
private fields; | ||
private params; | ||
collectQueryHandlerMetadata(definition: ResolverMetadata): void; | ||
collectMutationHandlerMetadata(definition: ResolverMetadata): void; | ||
collectSubscriptionHandlerMetadata(definition: SubscriptionResolverMetadata): void; | ||
collectFieldResolverMetadata(definition: FieldResolverMetadata): void; | ||
collectObjectMetadata(definition: ClassMetadata): void; | ||
collectInputMetadata(definition: ClassMetadata): void; | ||
collectArgsMetadata(definition: ClassMetadata): void; | ||
collectInterfaceMetadata(definition: ClassMetadata): void; | ||
collectAuthorizedFieldMetadata(definition: AuthorizedMetadata): void; | ||
collectEnumMetadata(definition: EnumMetadata): void; | ||
collectUnionMetadata(definition: UnionMetadata): symbol; | ||
collectMiddlewareMetadata(definition: MiddlewareMetadata): void; | ||
collectResolverClassMetadata(definition: ResolverClassMetadata): void; | ||
collectClassFieldMetadata(definition: FieldMetadata): void; | ||
collectHandlerParamMetadata(definition: ParamMetadata): void; | ||
build(): void; | ||
clear(): void; | ||
private buildClassMetadata(definitions); | ||
private buildResolversMetadata(definitions); | ||
private buildFieldResolverMetadata(definitions); | ||
private findFieldRoles(target, fieldName); | ||
private mapMetadataToMiddlewares(metadata); | ||
} |
@@ -5,33 +5,50 @@ "use strict"; | ||
class MetadataStorage { | ||
static collectQueryHandlerMetadata(definition) { | ||
constructor() { | ||
this.queries = []; | ||
this.mutations = []; | ||
this.subscriptions = []; | ||
this.fieldResolvers = []; | ||
this.objectTypes = []; | ||
this.inputTypes = []; | ||
this.argumentTypes = []; | ||
this.interfaceTypes = []; | ||
this.authorizedFields = []; | ||
this.enums = []; | ||
this.unions = []; | ||
this.middlewares = []; | ||
this.resolvers = []; | ||
this.fields = []; | ||
this.params = []; | ||
} | ||
collectQueryHandlerMetadata(definition) { | ||
this.queries.push(definition); | ||
} | ||
static collectMutationHandlerMetadata(definition) { | ||
collectMutationHandlerMetadata(definition) { | ||
this.mutations.push(definition); | ||
} | ||
static collectSubscriptionHandlerMetadata(definition) { | ||
collectSubscriptionHandlerMetadata(definition) { | ||
this.subscriptions.push(definition); | ||
} | ||
static collectFieldResolverMetadata(definition) { | ||
collectFieldResolverMetadata(definition) { | ||
this.fieldResolvers.push(definition); | ||
} | ||
static collectObjectMetadata(definition) { | ||
collectObjectMetadata(definition) { | ||
this.objectTypes.push(definition); | ||
} | ||
static collectInputMetadata(definition) { | ||
collectInputMetadata(definition) { | ||
this.inputTypes.push(definition); | ||
} | ||
static collectArgsMetadata(definition) { | ||
collectArgsMetadata(definition) { | ||
this.argumentTypes.push(definition); | ||
} | ||
static collectInterfaceMetadata(definition) { | ||
collectInterfaceMetadata(definition) { | ||
this.interfaceTypes.push(definition); | ||
} | ||
static collectAuthorizedFieldMetadata(definition) { | ||
collectAuthorizedFieldMetadata(definition) { | ||
this.authorizedFields.push(definition); | ||
} | ||
static collectEnumMetadata(definition) { | ||
collectEnumMetadata(definition) { | ||
this.enums.push(definition); | ||
} | ||
static collectUnionMetadata(definition) { | ||
collectUnionMetadata(definition) { | ||
const unionSymbol = Symbol(definition.name); | ||
@@ -41,15 +58,15 @@ this.unions.push(Object.assign({}, definition, { symbol: unionSymbol })); | ||
} | ||
static collectMiddlewareMetadata(definition) { | ||
collectMiddlewareMetadata(definition) { | ||
this.middlewares.push(definition); | ||
} | ||
static collectResolverClassMetadata(definition) { | ||
collectResolverClassMetadata(definition) { | ||
this.resolvers.push(definition); | ||
} | ||
static collectClassFieldMetadata(definition) { | ||
collectClassFieldMetadata(definition) { | ||
this.fields.push(definition); | ||
} | ||
static collectHandlerParamMetadata(definition) { | ||
collectHandlerParamMetadata(definition) { | ||
this.params.push(definition); | ||
} | ||
static build() { | ||
build() { | ||
// TODO: disable next build attempts | ||
@@ -65,3 +82,3 @@ this.buildClassMetadata(this.objectTypes); | ||
} | ||
static clear() { | ||
clear() { | ||
this.queries = []; | ||
@@ -83,3 +100,3 @@ this.mutations = []; | ||
} | ||
static buildClassMetadata(definitions) { | ||
buildClassMetadata(definitions) { | ||
definitions.forEach(def => { | ||
@@ -95,3 +112,3 @@ const fields = this.fields.filter(field => field.target === def.target); | ||
} | ||
static buildResolversMetadata(definitions) { | ||
buildResolversMetadata(definitions) { | ||
definitions.forEach(def => { | ||
@@ -103,3 +120,3 @@ def.params = this.params.filter(param => param.target === def.target && def.methodName === param.methodName); | ||
} | ||
static buildFieldResolverMetadata(definitions) { | ||
buildFieldResolverMetadata(definitions) { | ||
this.buildResolversMetadata(definitions); | ||
@@ -149,3 +166,3 @@ definitions.forEach(def => { | ||
} | ||
static findFieldRoles(target, fieldName) { | ||
findFieldRoles(target, fieldName) { | ||
const authorizedField = this.authorizedFields.find(authField => authField.target === target && authField.fieldName === fieldName); | ||
@@ -157,3 +174,3 @@ if (!authorizedField) { | ||
} | ||
static mapMetadataToMiddlewares(metadata) { | ||
mapMetadataToMiddlewares(metadata) { | ||
return metadata | ||
@@ -164,17 +181,2 @@ .map(m => m.middlewares) | ||
} | ||
MetadataStorage.queries = []; | ||
MetadataStorage.mutations = []; | ||
MetadataStorage.subscriptions = []; | ||
MetadataStorage.fieldResolvers = []; | ||
MetadataStorage.objectTypes = []; | ||
MetadataStorage.inputTypes = []; | ||
MetadataStorage.argumentTypes = []; | ||
MetadataStorage.interfaceTypes = []; | ||
MetadataStorage.authorizedFields = []; | ||
MetadataStorage.enums = []; | ||
MetadataStorage.unions = []; | ||
MetadataStorage.middlewares = []; | ||
MetadataStorage.resolvers = []; | ||
MetadataStorage.fields = []; | ||
MetadataStorage.params = []; | ||
exports.MetadataStorage = MetadataStorage; |
{ | ||
"name": "type-graphql", | ||
"version": "0.11.1", | ||
"version": "0.11.2", | ||
"main": "./index.js", | ||
@@ -42,3 +42,3 @@ "author": { | ||
"@types/graphql": "^0.13.0", | ||
"@types/node": "^9.6.4", | ||
"@types/node": "^9.6.7", | ||
"class-transformer": "^0.1.9", | ||
@@ -60,7 +60,8 @@ "class-validator": "^0.8.5", | ||
"apollo-client": "^2.2.8", | ||
"apollo-link-ws": "^1.0.7", | ||
"apollo-link": "^1.2.2", | ||
"apollo-link-ws": "^1.0.8", | ||
"del": "^3.0.0", | ||
"graphql-redis-subscriptions": "^1.4.0", | ||
"graphql-tag": "^2.8.0", | ||
"graphql-yoga": "^1.8.5", | ||
"graphql-redis-subscriptions": "^1.5.0", | ||
"graphql-tag": "^2.9.1", | ||
"graphql-yoga": "^1.12.1", | ||
"gulp-replace": "^0.6.1", | ||
@@ -70,17 +71,17 @@ "gulp-shell": "^0.6.5", | ||
"gulpclass": "^0.1.2", | ||
"husky": "^1.0.0-rc.1", | ||
"husky": "^1.0.0-rc.2", | ||
"ioredis": "^3.2.2", | ||
"jest": "^22.4.3", | ||
"mysql": "^2.15.0", | ||
"prettier": "^1.12.0", | ||
"prettier": "^1.12.1", | ||
"reflect-metadata": "^0.1.12", | ||
"subscriptions-transport-ws": "^0.9.7", | ||
"ts-jest": "^22.4.2", | ||
"ts-node": "^5.0.1", | ||
"subscriptions-transport-ws": "^0.9.8", | ||
"ts-jest": "^22.4.4", | ||
"ts-node": "^6.0.1", | ||
"tslint": "^5.9.1", | ||
"tslint-eslint-rules": "^5.1.0", | ||
"typedi": "^0.7.2", | ||
"typeorm": "^0.1.20", | ||
"typeorm-typedi-extensions": "^0.2.0", | ||
"typescript": "~2.7.2" | ||
"typeorm": "^0.2.3", | ||
"typeorm-typedi-extensions": "^0.2.1", | ||
"typescript": "^2.8.3" | ||
}, | ||
@@ -87,0 +88,0 @@ "husky": { |
@@ -21,5 +21,5 @@ "use strict"; | ||
return (root, args, context, info) => __awaiter(this, void 0, void 0, function* () { | ||
const actionData = { root, args, context, info }; | ||
return helpers_1.applyMiddlewares(actionData, middlewares, () => __awaiter(this, void 0, void 0, function* () { | ||
const params = yield helpers_1.getParams(resolverMetadata.params, actionData, globalValidate, pubSub); | ||
const resolverData = { root, args, context, info }; | ||
return helpers_1.applyMiddlewares(resolverData, middlewares, () => __awaiter(this, void 0, void 0, function* () { | ||
const params = yield helpers_1.getParams(resolverMetadata.params, resolverData, globalValidate, pubSub); | ||
return resolverMetadata.handler.apply(targetInstance, params); | ||
@@ -39,8 +39,8 @@ })); | ||
return (root, args, context, info) => __awaiter(this, void 0, void 0, function* () { | ||
const actionData = { root, args, context, info }; | ||
const resolverData = { root, args, context, info }; | ||
const targetInstance = types_1.convertToType(targetType, root); | ||
return helpers_1.applyMiddlewares(actionData, middlewares, () => __awaiter(this, void 0, void 0, function* () { | ||
return helpers_1.applyMiddlewares(resolverData, middlewares, () => __awaiter(this, void 0, void 0, function* () { | ||
// method | ||
if (fieldResolverMetadata.handler) { | ||
const params = yield helpers_1.getParams(fieldResolverMetadata.params, actionData, globalValidate, pubSub); | ||
const params = yield helpers_1.getParams(fieldResolverMetadata.params, resolverData, globalValidate, pubSub); | ||
return fieldResolverMetadata.handler.apply(targetInstance, params); | ||
@@ -59,6 +59,6 @@ } | ||
return (root, args, context, info) => __awaiter(this, void 0, void 0, function* () { | ||
const actionData = { root, args, context, info }; | ||
return yield helpers_1.applyMiddlewares(actionData, middlewares, () => root[fieldMetadata.name]); | ||
const resolverData = { root, args, context, info }; | ||
return yield helpers_1.applyMiddlewares(resolverData, middlewares, () => root[fieldMetadata.name]); | ||
}); | ||
} | ||
exports.createSimpleFieldResolver = createSimpleFieldResolver; |
@@ -5,6 +5,6 @@ import { PubSubEngine } from "graphql-subscriptions"; | ||
import { AuthChecker, AuthMode } from "../interfaces/auth-checker"; | ||
import { ActionData } from "../types"; | ||
import { ResolverData } from "../types"; | ||
import { Middleware } from "../interfaces/Middleware"; | ||
export declare function getParams(params: ParamMetadata[], {root, args, context, info}: ActionData<any>, globalValidate: boolean | ValidatorOptions, pubSub: PubSubEngine): Promise<any[]>; | ||
export declare function getParams(params: ParamMetadata[], {root, args, context, info}: ResolverData<any>, globalValidate: boolean | ValidatorOptions, pubSub: PubSubEngine): Promise<any[]>; | ||
export declare function applyAuthChecker(middlewares: Array<Middleware<any>>, authMode: AuthMode, authChecker?: AuthChecker, roles?: string[]): void; | ||
export declare function applyMiddlewares(actionData: ActionData<any>, middlewares: Array<Middleware<any>>, resolverHandlerFunction: () => any): Promise<any>; | ||
export declare function applyMiddlewares(resolverData: ResolverData<any>, middlewares: Array<Middleware<any>>, resolverHandlerFunction: () => any): Promise<any>; |
@@ -52,3 +52,3 @@ "use strict"; | ||
exports.applyAuthChecker = applyAuthChecker; | ||
function applyMiddlewares(actionData, middlewares, resolverHandlerFunction) { | ||
function applyMiddlewares(resolverData, middlewares, resolverHandlerFunction) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -78,3 +78,3 @@ let middlewaresIndex = -1; | ||
let nextResult; | ||
const result = yield handlerFn(actionData, () => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield handlerFn(resolverData, () => __awaiter(this, void 0, void 0, function* () { | ||
nextResult = yield dispatchHandler(currentIndex + 1); | ||
@@ -81,0 +81,0 @@ return nextResult; |
@@ -22,3 +22,3 @@ "use strict"; | ||
const graphql_subscriptions_1 = require("graphql-subscriptions"); | ||
const metadata_storage_1 = require("../metadata/metadata-storage"); | ||
const getMetadataStorage_1 = require("../metadata/getMetadataStorage"); | ||
const types_1 = require("../helpers/types"); | ||
@@ -42,3 +42,3 @@ const create_1 = require("../resolvers/create"); | ||
build_context_1.BuildContext.create(options); | ||
metadata_storage_1.MetadataStorage.build(); | ||
getMetadataStorage_1.getMetadataStorage().build(); | ||
this.buildTypesInfo(); | ||
@@ -55,3 +55,3 @@ const schema = new graphql_1.GraphQLSchema({ | ||
static checkForErrors(options) { | ||
if (metadata_storage_1.MetadataStorage.authorizedFields.length !== 0 && options.authChecker === undefined) { | ||
if (getMetadataStorage_1.getMetadataStorage().authorizedFields.length !== 0 && options.authChecker === undefined) { | ||
throw new Error("You need to provide `authChecker` function for `@Authorized` decorator usage!"); | ||
@@ -61,3 +61,3 @@ } | ||
static buildTypesInfo() { | ||
this.unionTypesInfo = metadata_storage_1.MetadataStorage.unions.map(unionMetadata => { | ||
this.unionTypesInfo = getMetadataStorage_1.getMetadataStorage().unions.map(unionMetadata => { | ||
return { | ||
@@ -80,3 +80,3 @@ unionSymbol: unionMetadata.symbol, | ||
}); | ||
this.enumTypesInfo = metadata_storage_1.MetadataStorage.enums.map(enumMetadata => { | ||
this.enumTypesInfo = getMetadataStorage_1.getMetadataStorage().enums.map(enumMetadata => { | ||
const enumMap = types_1.getEnumValuesMap(enumMetadata.enumObj); | ||
@@ -97,3 +97,3 @@ return { | ||
}); | ||
this.interfaceTypesInfo = metadata_storage_1.MetadataStorage.interfaceTypes.map(interfaceType => { | ||
this.interfaceTypesInfo = getMetadataStorage_1.getMetadataStorage().interfaceTypes.map(interfaceType => { | ||
const interfaceSuperClass = Object.getPrototypeOf(interfaceType.target); | ||
@@ -131,3 +131,3 @@ const hasExtended = interfaceSuperClass.prototype !== undefined; | ||
}); | ||
this.objectTypesInfo = metadata_storage_1.MetadataStorage.objectTypes.map(objectType => { | ||
this.objectTypesInfo = getMetadataStorage_1.getMetadataStorage().objectTypes.map(objectType => { | ||
const objectSuperClass = Object.getPrototypeOf(objectType.target); | ||
@@ -162,3 +162,3 @@ const hasExtended = objectSuperClass.prototype !== undefined; | ||
let fields = objectType.fields.reduce((fieldsMap, field) => { | ||
const fieldResolverMetadata = metadata_storage_1.MetadataStorage.fieldResolvers.find(resolver => resolver.getObjectType() === objectType.target && | ||
const fieldResolverMetadata = getMetadataStorage_1.getMetadataStorage().fieldResolvers.find(resolver => resolver.getObjectType() === objectType.target && | ||
resolver.methodName === field.name); | ||
@@ -198,3 +198,3 @@ fieldsMap[field.name] = { | ||
}); | ||
this.inputTypesInfo = metadata_storage_1.MetadataStorage.inputTypes.map(inputType => { | ||
this.inputTypesInfo = getMetadataStorage_1.getMetadataStorage().inputTypes.map(inputType => { | ||
const objectSuperClass = Object.getPrototypeOf(inputType.target); | ||
@@ -235,10 +235,10 @@ const getSuperClassType = () => { | ||
name: "Query", | ||
fields: this.generateHandlerFields(metadata_storage_1.MetadataStorage.queries), | ||
fields: this.generateHandlerFields(getMetadataStorage_1.getMetadataStorage().queries), | ||
}); | ||
} | ||
static buildRootMutationType() { | ||
if (metadata_storage_1.MetadataStorage.mutations.length > 0) { | ||
if (getMetadataStorage_1.getMetadataStorage().mutations.length > 0) { | ||
return new graphql_1.GraphQLObjectType({ | ||
name: "Mutation", | ||
fields: this.generateHandlerFields(metadata_storage_1.MetadataStorage.mutations), | ||
fields: this.generateHandlerFields(getMetadataStorage_1.getMetadataStorage().mutations), | ||
}); | ||
@@ -249,6 +249,6 @@ } | ||
static buildRootSubscriptionType() { | ||
if (metadata_storage_1.MetadataStorage.subscriptions.length > 0) { | ||
if (getMetadataStorage_1.getMetadataStorage().subscriptions.length > 0) { | ||
return new graphql_1.GraphQLObjectType({ | ||
name: "Subscription", | ||
fields: this.generateSubscriptionsFields(metadata_storage_1.MetadataStorage.subscriptions), | ||
fields: this.generateSubscriptionsFields(getMetadataStorage_1.getMetadataStorage().subscriptions), | ||
}); | ||
@@ -285,4 +285,4 @@ } | ||
? graphql_subscriptions_1.withFilter(() => pubSub.asyncIterator(handler.topics), (payload, args, context, info) => { | ||
const actionData = { payload, args, context, info }; | ||
return handler.filter(actionData); | ||
const resolverFilterData = { payload, args, context, info }; | ||
return handler.filter(resolverFilterData); | ||
}) | ||
@@ -307,6 +307,6 @@ : () => pubSub.asyncIterator(handler.topics), | ||
else if (param.kind === "args") { | ||
const argumentType = metadata_storage_1.MetadataStorage.argumentTypes.find(it => it.target === param.getType()); | ||
const argumentType = getMetadataStorage_1.getMetadataStorage().argumentTypes.find(it => it.target === param.getType()); | ||
let superClass = Object.getPrototypeOf(argumentType.target); | ||
while (superClass.prototype !== undefined) { | ||
const superArgumentType = metadata_storage_1.MetadataStorage.argumentTypes.find(it => it.target === superClass); | ||
const superArgumentType = getMetadataStorage_1.getMetadataStorage().argumentTypes.find(it => it.target === superClass); | ||
this.mapArgFields(superArgumentType, args); | ||
@@ -313,0 +313,0 @@ superClass = Object.getPrototypeOf(superClass); |
@@ -5,3 +5,3 @@ import { GraphQLResolveInfo } from "graphql"; | ||
} | ||
export interface ActionData<ContextType = {}> { | ||
export interface ResolverData<ContextType = {}> { | ||
root: any; | ||
@@ -8,0 +8,0 @@ args: ArgsDictionary; |
import { GraphQLScalarType } from "graphql"; | ||
import { ValidatorOptions } from "class-validator"; | ||
import { FilterActionData } from "./filter-action-data"; | ||
import { ResolverFilterData } from "./filter-action-data"; | ||
export declare type TypeValue = ClassType | GraphQLScalarType | Function | object | symbol; | ||
@@ -9,3 +9,3 @@ export declare type ReturnTypeFuncValue = TypeValue | [TypeValue]; | ||
export declare type ReturnTypeFunc = (returnType?: void) => ReturnTypeFuncValue; | ||
export declare type SubscriptionFilterFunc = (actionData: FilterActionData<any, any, any>) => boolean | Promise<boolean>; | ||
export declare type SubscriptionFilterFunc = (resolverFilterData: ResolverFilterData<any, any, any>) => boolean | Promise<boolean>; | ||
export interface DecoratorTypeOptions { | ||
@@ -12,0 +12,0 @@ nullable?: boolean; |
import { GraphQLResolveInfo } from "graphql"; | ||
import { ArgsDictionary } from "./action-data"; | ||
export interface FilterActionData<TPayload = any, TArgs = ArgsDictionary, TContext = {}> { | ||
export interface ResolverFilterData<TPayload = any, TArgs = ArgsDictionary, TContext = {}> { | ||
payload: TPayload; | ||
@@ -5,0 +5,0 @@ args: TArgs; |
@@ -1,2 +0,4 @@ | ||
export { ActionData } from "./action-data"; | ||
export { FilterActionData } from "./filter-action-data"; | ||
export { ResolverData } from "./action-data"; | ||
export { ResolverFilterData } from "./filter-action-data"; | ||
export { ResolverData as ActionData } from "./action-data"; | ||
export { ResolverFilterData as FilterActionData } from "./filter-action-data"; |
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
116094
146
2415
34
Updated@types/node@^9.6.7