Skip to content

Commit

Permalink
feat: add responses payload for array types
Browse files Browse the repository at this point in the history
  • Loading branch information
temarusanov committed Nov 27, 2021
1 parent e27dc19 commit d92e16d
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/filters/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './response.exception-filter'
export * from './response.exception-filter'
3 changes: 2 additions & 1 deletion lib/filters/response.exception-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export class ResponseFilter implements GqlExceptionFilter {

const { stack } = this._config

const stackMessage = stack === undefined || stack === true ? exception.stack : undefined
const stackMessage =
stack === undefined || stack === true ? exception.stack : undefined

this._logger.error(`${message} (${description})`, exception.stack)

Expand Down
2 changes: 1 addition & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './filters'
export * from './interfaces'
export * from './types'
export * from './types'
2 changes: 1 addition & 1 deletion lib/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './response-error.interface'
export * from './response-payload.interface'
export * from './response-filter-config.interface'
export * from './response-filter-config.interface'
2 changes: 1 addition & 1 deletion lib/interfaces/response-filter-config.interface.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export interface ResponseFilterConfig {
stack?: boolean
}
}
4 changes: 2 additions & 2 deletions lib/interfaces/response-payload.interface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ResponseError } from "./response-error.interface"
import { ResponseError } from './response-error.interface'

export interface ResponsePayload<T> {
data?: T
data?: T | T[]
error?: ResponseError
}
2 changes: 1 addition & 1 deletion lib/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './response-error.type'
export * from './response-payload.type'
export * from './response-payload.type'
20 changes: 20 additions & 0 deletions lib/types/responses-payload.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Type } from '@nestjs/common'
import { Field, ObjectType } from '@nestjs/graphql'
import { ResponseError } from '../interfaces/response-error.interface'
import { ResponsePayload } from '../interfaces/response-payload.interface'
import { ResponseErrorType } from './response-error.type'

export const ResponsePayloadType = <T>(
classRef: Type<T>,
): Type<ResponsePayload<T>> => {
@ObjectType('ResponsesPayload', { isAbstract: true })
class ResponsePayloadType implements ResponsePayload<T> {
@Field(() => [classRef], { nullable: true })
data?: T[]

@Field(() => ResponseErrorType, { nullable: true })
error?: ResponseError
}

return ResponsePayloadType
}

0 comments on commit d92e16d

Please # to comment.