From ec9727093d7176bf6e007f10bb831414876fe09e Mon Sep 17 00:00:00 2001 From: Maciej Sikorski Date: Mon, 25 Jan 2021 12:40:00 +0100 Subject: [PATCH] feat: allow to config cors async Bump version of the fastify-cors. Add CorsOptionsDelegate interface. Add CorsOptionsDelegate as an acceptable type for every enableCors usage. Closes nestjs/nest#6118 --- integration/cors/e2e/express.spec.ts | 177 ++++++++++++ integration/cors/e2e/fastify.spec.ts | 177 ++++++++++++ integration/cors/src/app.controller.ts | 9 + integration/cors/src/app.module.ts | 7 + integration/cors/tsconfig.json | 22 ++ .../src/kafka/kafka.controller.ts | 9 +- packages/common/exceptions/http.exception.ts | 1 - .../external/cors-options.interface.ts | 7 + .../interfaces/http/http-server.interface.ts | 7 +- .../nest-application-options.interface.ts | 7 +- .../interfaces/nest-application.interface.ts | 7 +- packages/core/adapters/http-adapter.ts | 6 +- packages/core/application-config.ts | 8 +- .../core/helpers/external-context-creator.ts | 4 +- packages/core/nest-application.ts | 14 +- .../context/rpc-context-creator.ts | 4 +- .../adapters/express-adapter.ts | 3 +- .../adapters/fastify-adapter.ts | 15 +- .../websockets/context/ws-context-creator.ts | 4 +- .../22-graphql-prisma/src/graphql.schema.d.ts | 255 ++++++++++-------- tools/gulp/tasks/samples.ts | 2 +- 21 files changed, 600 insertions(+), 145 deletions(-) create mode 100644 integration/cors/e2e/express.spec.ts create mode 100644 integration/cors/e2e/fastify.spec.ts create mode 100644 integration/cors/src/app.controller.ts create mode 100644 integration/cors/src/app.module.ts create mode 100644 integration/cors/tsconfig.json diff --git a/integration/cors/e2e/express.spec.ts b/integration/cors/e2e/express.spec.ts new file mode 100644 index 000000000..482ddea09 --- /dev/null +++ b/integration/cors/e2e/express.spec.ts @@ -0,0 +1,177 @@ +import { NestFastifyApplication } from '@nestjs/platform-fastify'; +import { Test } from '@nestjs/testing'; +import * as request from 'supertest'; +import { AppModule } from '../src/app.module'; + +describe('Express Cors', () => { + let app: NestFastifyApplication; + const configs = [ + { + origin: 'example.com', + methods: 'GET', + credentials: true, + exposedHeaders: ['foo', 'bar'], + allowedHeaders: ['baz', 'woo'], + maxAge: 123, + }, + { + origin: 'sample.com', + methods: 'GET', + credentials: true, + exposedHeaders: ['zoo', 'bar'], + allowedHeaders: ['baz', 'foo'], + maxAge: 321, + }, + ]; + describe('Dynamic config', () => { + describe('enableCors', () => { + before(async () => { + const module = await Test.createTestingModule({ + imports: [AppModule], + }).compile(); + + app = module.createNestApplication(); + + let requestId = 0; + const configDelegation = function (req, cb) { + const config = configs[requestId]; + requestId++; + cb(null, config); + }; + app.enableCors(configDelegation); + + await app.init(); + }); + + it(`Should add cors headers based on the first config`, async () => { + return request(app.getHttpServer()) + .get('/') + .expect('access-control-allow-origin', 'example.com') + .expect('vary', 'Origin') + .expect('access-control-allow-credentials', 'true') + .expect('access-control-expose-headers', 'foo,bar') + .expect('content-length', '0'); + }); + + it(`Should add cors headers based on the second config`, async () => { + return request(app.getHttpServer()) + .options('/') + .expect('access-control-allow-origin', 'sample.com') + .expect('vary', 'Origin') + .expect('access-control-allow-credentials', 'true') + .expect('access-control-expose-headers', 'zoo,bar') + .expect('access-control-allow-methods', 'GET') + .expect('access-control-allow-headers', 'baz,foo') + .expect('access-control-max-age', '321') + .expect('content-length', '0'); + }); + + after(async () => { + await app.close(); + }); + }); + + describe('Application Options', () => { + before(async () => { + const module = await Test.createTestingModule({ + imports: [AppModule], + }).compile(); + + let requestId = 0; + const configDelegation = function (req, cb) { + const config = configs[requestId]; + requestId++; + cb(null, config); + }; + + app = module.createNestApplication(null, { + cors: configDelegation, + }); + + await app.init(); + }); + + it(`Should add cors headers based on the first config`, async () => { + return request(app.getHttpServer()) + .get('/') + .expect('access-control-allow-origin', 'example.com') + .expect('vary', 'Origin') + .expect('access-control-allow-credentials', 'true') + .expect('access-control-expose-headers', 'foo,bar') + .expect('content-length', '0'); + }); + + it(`Should add cors headers based on the second config`, async () => { + return request(app.getHttpServer()) + .options('/') + .expect('access-control-allow-origin', 'sample.com') + .expect('vary', 'Origin') + .expect('access-control-allow-credentials', 'true') + .expect('access-control-expose-headers', 'zoo,bar') + .expect('access-control-allow-methods', 'GET') + .expect('access-control-allow-headers', 'baz,foo') + .expect('access-control-max-age', '321') + .expect('content-length', '0'); + }); + + after(async () => { + await app.close(); + }); + }); + }); + describe('Static config', () => { + describe('enableCors', () => { + before(async () => { + const module = await Test.createTestingModule({ + imports: [AppModule], + }).compile(); + + app = module.createNestApplication(); + app.enableCors(configs[0]); + + await app.init(); + }); + + it(`CORS headers`, async () => { + return request(app.getHttpServer()) + .get('/') + .expect('access-control-allow-origin', 'example.com') + .expect('vary', 'Origin') + .expect('access-control-allow-credentials', 'true') + .expect('access-control-expose-headers', 'foo,bar') + .expect('content-length', '0'); + }); + }); + + after(async () => { + await app.close(); + }); + + describe('Application Options', () => { + before(async () => { + const module = await Test.createTestingModule({ + imports: [AppModule], + }).compile(); + + app = module.createNestApplication(null, { + cors: configs[0], + }); + await app.init(); + }); + + it(`CORS headers`, async () => { + return request(app.getHttpServer()) + .get('/') + .expect('access-control-allow-origin', 'example.com') + .expect('vary', 'Origin') + .expect('access-control-allow-credentials', 'true') + .expect('access-control-expose-headers', 'foo,bar') + .expect('content-length', '0'); + }); + + after(async () => { + await app.close(); + }); + }); + }); +}); diff --git a/integration/cors/e2e/fastify.spec.ts b/integration/cors/e2e/fastify.spec.ts new file mode 100644 index 000000000..7406dadb3 --- /dev/null +++ b/integration/cors/e2e/fastify.spec.ts @@ -0,0 +1,177 @@ +import { NestFastifyApplication } from '@nestjs/platform-fastify'; +import { Test } from '@nestjs/testing'; +import * as request from 'supertest'; +import { AppModule } from '../src/app.module'; + +describe('Fastify Cors', () => { + let app: NestFastifyApplication; + const configs = [ + { + origin: 'example.com', + methods: 'GET', + credentials: true, + exposedHeaders: ['foo', 'bar'], + allowedHeaders: ['baz', 'woo'], + maxAge: 123, + }, + { + origin: 'sample.com', + methods: 'GET', + credentials: true, + exposedHeaders: ['zoo', 'bar'], + allowedHeaders: ['baz', 'foo'], + maxAge: 321, + }, + ]; + describe('Dynamic config', () => { + describe('enableCors', () => { + before(async () => { + const module = await Test.createTestingModule({ + imports: [AppModule], + }).compile(); + + app = module.createNestApplication(); + + let requestId = 0; + const configDelegation = function (req, cb) { + const config = configs[requestId]; + requestId++; + cb(null, config); + }; + app.enableCors(configDelegation); + + await app.init(); + }); + + it(`Should add cors headers based on the first config`, async () => { + return request(app.getHttpServer()) + .get('/') + .expect('access-control-allow-origin', 'example.com') + .expect('vary', 'Origin') + .expect('access-control-allow-credentials', 'true') + .expect('access-control-expose-headers', 'foo,bar') + .expect('content-length', '0'); + }); + + it(`Should add cors headers based on the second config`, async () => { + return request(app.getHttpServer()) + .options('/') + .expect('access-control-allow-origin', 'sample.com') + .expect('vary', 'Origin') + .expect('access-control-allow-credentials', 'true') + .expect('access-control-expose-headers', 'zoo,bar') + .expect('access-control-allow-methods', 'GET') + .expect('access-control-allow-headers', 'baz,foo') + .expect('access-control-max-age', '321') + .expect('content-length', '0'); + }); + + after(async () => { + await app.close(); + }); + }); + + describe('Application Options', () => { + before(async () => { + const module = await Test.createTestingModule({ + imports: [AppModule], + }).compile(); + + let requestId = 0; + const configDelegation = function (req, cb) { + const config = configs[requestId]; + requestId++; + cb(null, config); + }; + + app = module.createNestApplication(null, { + cors: configDelegation, + }); + + await app.init(); + }); + + it(`Should add cors headers based on the first config`, async () => { + return request(app.getHttpServer()) + .get('/') + .expect('access-control-allow-origin', 'example.com') + .expect('vary', 'Origin') + .expect('access-control-allow-credentials', 'true') + .expect('access-control-expose-headers', 'foo,bar') + .expect('content-length', '0'); + }); + + it(`Should add cors headers based on the second config`, async () => { + return request(app.getHttpServer()) + .options('/') + .expect('access-control-allow-origin', 'sample.com') + .expect('vary', 'Origin') + .expect('access-control-allow-credentials', 'true') + .expect('access-control-expose-headers', 'zoo,bar') + .expect('access-control-allow-methods', 'GET') + .expect('access-control-allow-headers', 'baz,foo') + .expect('access-control-max-age', '321') + .expect('content-length', '0'); + }); + + after(async () => { + await app.close(); + }); + }); + }); + + describe('Static config', () => { + describe('enableCors', () => { + before(async () => { + const module = await Test.createTestingModule({ + imports: [AppModule], + }).compile(); + + app = module.createNestApplication(); + app.enableCors(configs[0]); + + await app.init(); + }); + + it(`CORS headers`, async () => { + return request(app.getHttpServer()) + .get('/') + .expect('access-control-allow-origin', 'example.com') + .expect('vary', 'Origin') + .expect('access-control-allow-credentials', 'true') + .expect('access-control-expose-headers', 'foo,bar') + .expect('content-length', '0'); + }); + }); + + after(async () => { + await app.close(); + }); + describe('Application Options', () => { + before(async () => { + const module = await Test.createTestingModule({ + imports: [AppModule], + }).compile(); + + app = module.createNestApplication(null, { + cors: configs[0], + }); + await app.init(); + }); + + it(`CORS headers`, async () => { + return request(app.getHttpServer()) + .get('/') + .expect('access-control-allow-origin', 'example.com') + .expect('vary', 'Origin') + .expect('access-control-allow-credentials', 'true') + .expect('access-control-expose-headers', 'foo,bar') + .expect('content-length', '0'); + }); + }); + + after(async () => { + await app.close(); + }); + }); +}); diff --git a/integration/cors/src/app.controller.ts b/integration/cors/src/app.controller.ts new file mode 100644 index 000000000..a145c9297 --- /dev/null +++ b/integration/cors/src/app.controller.ts @@ -0,0 +1,9 @@ +import { Controller, Get } from '@nestjs/common'; + +@Controller() +export class AppController { + @Get() + getGlobals() { + return ''; + } +} diff --git a/integration/cors/src/app.module.ts b/integration/cors/src/app.module.ts new file mode 100644 index 000000000..848d4aaa7 --- /dev/null +++ b/integration/cors/src/app.module.ts @@ -0,0 +1,7 @@ +import { Module } from '@nestjs/common'; +import { AppController } from './app.controller'; + +@Module({ + controllers: [AppController], +}) +export class AppModule {} diff --git a/integration/cors/tsconfig.json b/integration/cors/tsconfig.json new file mode 100644 index 000000000..c6354c564 --- /dev/null +++ b/integration/cors/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "declaration": false, + "noImplicitAny": false, + "removeComments": true, + "noLib": false, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "target": "es6", + "sourceMap": true, + "allowJs": true, + "outDir": "./dist" + }, + "include": [ + "src/**/*", + "e2e/**/*" + ], + "exclude": [ + "node_modules", + ] +} \ No newline at end of file diff --git a/integration/microservices/src/kafka/kafka.controller.ts b/integration/microservices/src/kafka/kafka.controller.ts index 0efe6e0eb..e279b99f0 100644 --- a/integration/microservices/src/kafka/kafka.controller.ts +++ b/integration/microservices/src/kafka/kafka.controller.ts @@ -1,4 +1,11 @@ -import { Body, Controller, HttpCode, OnModuleInit, Post, OnModuleDestroy } from '@nestjs/common'; +import { + Body, + Controller, + HttpCode, + OnModuleInit, + Post, + OnModuleDestroy, +} from '@nestjs/common'; import { Logger } from '@nestjs/common/services/logger.service'; import { Client, ClientKafka, Transport } from '@nestjs/microservices'; import { Observable } from 'rxjs'; diff --git a/packages/common/exceptions/http.exception.ts b/packages/common/exceptions/http.exception.ts index 29877fe0a..eea9b4179 100644 --- a/packages/common/exceptions/http.exception.ts +++ b/packages/common/exceptions/http.exception.ts @@ -78,4 +78,3 @@ export class HttpException extends Error { : { statusCode, message: objectOrError, error: description }; } } - diff --git a/packages/common/interfaces/external/cors-options.interface.ts b/packages/common/interfaces/external/cors-options.interface.ts index 81accdef8..cfbc31af9 100644 --- a/packages/common/interfaces/external/cors-options.interface.ts +++ b/packages/common/interfaces/external/cors-options.interface.ts @@ -52,3 +52,10 @@ export interface CorsOptions { */ optionsSuccessStatus?: number; } + +export interface CorsOptionsCallback { + (error: Error, options: CorsOptions): void; +} +export interface CorsOptionsDelegate { + (req: T, cb: CorsOptionsCallback): void; +} diff --git a/packages/common/interfaces/http/http-server.interface.ts b/packages/common/interfaces/http/http-server.interface.ts index f1d11a4fb..30f8c5562 100644 --- a/packages/common/interfaces/http/http-server.interface.ts +++ b/packages/common/interfaces/http/http-server.interface.ts @@ -1,5 +1,8 @@ import { RequestMethod } from '../../enums'; -import { CorsOptions } from '../../interfaces/external/cors-options.interface'; +import { + CorsOptions, + CorsOptionsDelegate, +} from '../../interfaces/external/cors-options.interface'; import { NestApplicationOptions } from '../../interfaces/nest-application-options.interface'; export type ErrorHandler = ( @@ -62,7 +65,7 @@ export interface HttpServer { getRequestUrl?(request: TResponse): string; getInstance(): any; registerParserMiddleware(): any; - enableCors(options: CorsOptions): any; + enableCors(options: CorsOptions | CorsOptionsDelegate): any; getHttpServer(): any; initHttpServer(options: NestApplicationOptions): void; close(): any; diff --git a/packages/common/interfaces/nest-application-options.interface.ts b/packages/common/interfaces/nest-application-options.interface.ts index 85124591d..a21bfed98 100644 --- a/packages/common/interfaces/nest-application-options.interface.ts +++ b/packages/common/interfaces/nest-application-options.interface.ts @@ -1,4 +1,7 @@ -import { CorsOptions } from './external/cors-options.interface'; +import { + CorsOptions, + CorsOptionsDelegate, +} from './external/cors-options.interface'; import { HttpsOptions } from './external/https-options.interface'; import { NestApplicationContextOptions } from './nest-application-context-options.interface'; @@ -9,7 +12,7 @@ export interface NestApplicationOptions extends NestApplicationContextOptions { /** * CORS options from [CORS package](https://github.com/expressjs/cors#configuration-options) */ - cors?: boolean | CorsOptions; + cors?: boolean | CorsOptions | CorsOptionsDelegate; /** * Whether to use underlying platform body parser. */ diff --git a/packages/common/interfaces/nest-application.interface.ts b/packages/common/interfaces/nest-application.interface.ts index 436cc9f8e..865977f32 100644 --- a/packages/common/interfaces/nest-application.interface.ts +++ b/packages/common/interfaces/nest-application.interface.ts @@ -1,4 +1,7 @@ -import { CorsOptions } from './external/cors-options.interface'; +import { + CorsOptions, + CorsOptionsDelegate, +} from './external/cors-options.interface'; import { CanActivate } from './features/can-activate.interface'; import { NestInterceptor } from './features/nest-interceptor.interface'; import { HttpServer } from './http/http-server.interface'; @@ -30,7 +33,7 @@ export interface INestApplication extends INestApplicationContext { * * @returns {void} */ - enableCors(options?: CorsOptions): void; + enableCors(options?: CorsOptions | CorsOptionsDelegate): void; /** * Starts the application. diff --git a/packages/core/adapters/http-adapter.ts b/packages/core/adapters/http-adapter.ts index f880b88ad..3ab5b5c3f 100644 --- a/packages/core/adapters/http-adapter.ts +++ b/packages/core/adapters/http-adapter.ts @@ -2,6 +2,7 @@ import { HttpServer, RequestMethod } from '@nestjs/common'; import { RequestHandler } from '@nestjs/common/interfaces'; import { CorsOptions } from '@nestjs/common/interfaces/external/cors-options.interface'; import { NestApplicationOptions } from '@nestjs/common/interfaces/nest-application-options.interface'; +import { CorsOptionsDelegate } from '../../common/interfaces/external/cors-options.interface'; /** * @publicApi @@ -97,7 +98,10 @@ export abstract class AbstractHttpAdapter< abstract setNotFoundHandler(handler: Function, prefix?: string); abstract setHeader(response, name: string, value: string); abstract registerParserMiddleware(prefix?: string); - abstract enableCors(options: CorsOptions, prefix?: string); + abstract enableCors( + options: CorsOptions | CorsOptionsDelegate, + prefix?: string, + ); abstract createMiddlewareFactory( requestMethod: RequestMethod, ): diff --git a/packages/core/application-config.ts b/packages/core/application-config.ts index 45fc67c9b..90965e653 100644 --- a/packages/core/application-config.ts +++ b/packages/core/application-config.ts @@ -14,12 +14,8 @@ export class ApplicationConfig { private globalInterceptors: NestInterceptor[] = []; private globalGuards: CanActivate[] = []; private readonly globalRequestPipes: InstanceWrapper[] = []; - private readonly globalRequestFilters: InstanceWrapper< - ExceptionFilter - >[] = []; - private readonly globalRequestInterceptors: InstanceWrapper< - NestInterceptor - >[] = []; + private readonly globalRequestFilters: InstanceWrapper[] = []; + private readonly globalRequestInterceptors: InstanceWrapper[] = []; private readonly globalRequestGuards: InstanceWrapper[] = []; constructor(private ioAdapter: WebSocketAdapter | null = null) {} diff --git a/packages/core/helpers/external-context-creator.ts b/packages/core/helpers/external-context-creator.ts index 6948f58d2..45b5f7872 100644 --- a/packages/core/helpers/external-context-creator.ts +++ b/packages/core/helpers/external-context-creator.ts @@ -38,9 +38,7 @@ export interface ExternalContextOptions { export class ExternalContextCreator { private readonly contextUtils = new ContextUtils(); private readonly externalErrorProxy = new ExternalErrorProxy(); - private readonly handlerMetadataStorage = new HandlerMetadataStorage< - ExternalHandlerMetadata - >(); + private readonly handlerMetadataStorage = new HandlerMetadataStorage(); private container: NestContainer; constructor( diff --git a/packages/core/nest-application.ts b/packages/core/nest-application.ts index 417390300..6229a916b 100644 --- a/packages/core/nest-application.ts +++ b/packages/core/nest-application.ts @@ -26,6 +26,8 @@ import { MiddlewareModule } from './middleware/middleware-module'; import { NestApplicationContext } from './nest-application-context'; import { Resolver } from './router/interfaces/resolver.interface'; import { RoutesResolver } from './router/routes-resolver'; +import { isFunction } from 'util'; +import { CorsOptionsDelegate } from '../common/interfaces/external/cors-options.interface'; const { SocketModule } = optionalRequire( '@nestjs/websockets/socket-module', @@ -102,11 +104,15 @@ export class NestApplication if (!this.appOptions || !this.appOptions.cors) { return undefined; } - const isCorsOptionsObj = isObject(this.appOptions.cors); - if (!isCorsOptionsObj) { + const passCustomOptions = + isObject(this.appOptions.cors) || + typeof this.appOptions.cors === 'function'; + if (!passCustomOptions) { return this.enableCors(); } - return this.enableCors(this.appOptions.cors as CorsOptions); + return this.enableCors( + this.appOptions.cors as CorsOptions | CorsOptionsDelegate, + ); } public createServer(): T { @@ -224,7 +230,7 @@ export class NestApplication return this; } - public enableCors(options?: CorsOptions): void { + public enableCors(options?: CorsOptions | CorsOptionsDelegate): void { this.httpAdapter.enableCors(options); } diff --git a/packages/microservices/context/rpc-context-creator.ts b/packages/microservices/context/rpc-context-creator.ts index 45d7dc725..346dbd101 100644 --- a/packages/microservices/context/rpc-context-creator.ts +++ b/packages/microservices/context/rpc-context-creator.ts @@ -41,9 +41,7 @@ export interface RpcHandlerMetadata { export class RpcContextCreator { private readonly contextUtils = new ContextUtils(); private readonly rpcParamsFactory = new RpcParamsFactory(); - private readonly handlerMetadataStorage = new HandlerMetadataStorage< - RpcHandlerMetadata - >(); + private readonly handlerMetadataStorage = new HandlerMetadataStorage(); constructor( private readonly rpcProxy: RpcProxy, diff --git a/packages/platform-express/adapters/express-adapter.ts b/packages/platform-express/adapters/express-adapter.ts index 576fb2aeb..99e383d7b 100644 --- a/packages/platform-express/adapters/express-adapter.ts +++ b/packages/platform-express/adapters/express-adapter.ts @@ -10,6 +10,7 @@ import * as express from 'express'; import * as http from 'http'; import * as https from 'https'; import { ServeStaticOptions } from '../interfaces/serve-static-options.interface'; +import { CorsOptionsDelegate } from '../../common/interfaces/external/cors-options.interface'; export class ExpressAdapter extends AbstractHttpAdapter { private readonly routerMethodFactory = new RouterMethodFactory(); @@ -108,7 +109,7 @@ export class ExpressAdapter extends AbstractHttpAdapter { return request.originalUrl; } - public enableCors(options: CorsOptions) { + public enableCors(options: CorsOptions | CorsOptionsDelegate) { return this.use(cors(options)); } diff --git a/packages/platform-fastify/adapters/fastify-adapter.ts b/packages/platform-fastify/adapters/fastify-adapter.ts index 76e532967..c0772370f 100644 --- a/packages/platform-fastify/adapters/fastify-adapter.ts +++ b/packages/platform-fastify/adapters/fastify-adapter.ts @@ -33,6 +33,7 @@ import { FastifyStaticOptions, PointOfViewOptions, } from '../interfaces/external'; +import { CorsOptionsDelegate } from '../../common/interfaces/external/cors-options.interface'; type FastifyHttp2SecureOptions< Server extends http2.Http2SecureServer, @@ -257,8 +258,18 @@ export class FastifyAdapter< return request.raw ? request.raw.url : request.url; } - public enableCors(options: CorsOptions) { - this.register(require('fastify-cors'), options); + public enableCors( + options: + | CorsOptions + | CorsOptionsDelegate< + FastifyRequest + >, + ) { + if (typeof options === 'function') { + this.register(require('fastify-cors'), () => options); + } else { + this.register(require('fastify-cors'), options); + } } public registerParserMiddleware() { diff --git a/packages/websockets/context/ws-context-creator.ts b/packages/websockets/context/ws-context-creator.ts index 8e4db797c..e1b674373 100644 --- a/packages/websockets/context/ws-context-creator.ts +++ b/packages/websockets/context/ws-context-creator.ts @@ -39,9 +39,7 @@ export interface WsHandlerMetadata { export class WsContextCreator { private readonly contextUtils = new ContextUtils(); private readonly wsParamsFactory = new WsParamsFactory(); - private readonly handlerMetadataStorage = new HandlerMetadataStorage< - WsHandlerMetadata - >(); + private readonly handlerMetadataStorage = new HandlerMetadataStorage(); constructor( private readonly wsProxy: WsProxy, diff --git a/sample/22-graphql-prisma/src/graphql.schema.d.ts b/sample/22-graphql-prisma/src/graphql.schema.d.ts index 303c33b0a..d818b240e 100644 --- a/sample/22-graphql-prisma/src/graphql.schema.d.ts +++ b/sample/22-graphql-prisma/src/graphql.schema.d.ts @@ -1,4 +1,3 @@ - /** ------------------------------------------------------ * THIS FILE WAS AUTOMATICALLY GENERATED (DO NOT MODIFY) * ------------------------------------------------------- @@ -6,175 +5,205 @@ /* tslint:disable */ export enum MutationType { - CREATED = "CREATED", - UPDATED = "UPDATED", - DELETED = "DELETED" + CREATED = 'CREATED', + UPDATED = 'UPDATED', + DELETED = 'DELETED', } export enum PostOrderByInput { - id_ASC = "id_ASC", - id_DESC = "id_DESC", - isPublished_ASC = "isPublished_ASC", - isPublished_DESC = "isPublished_DESC", - title_ASC = "title_ASC", - title_DESC = "title_DESC", - text_ASC = "text_ASC", - text_DESC = "text_DESC" + id_ASC = 'id_ASC', + id_DESC = 'id_DESC', + isPublished_ASC = 'isPublished_ASC', + isPublished_DESC = 'isPublished_DESC', + title_ASC = 'title_ASC', + title_DESC = 'title_DESC', + text_ASC = 'text_ASC', + text_DESC = 'text_DESC', } export class PostCreateInput { - id?: string; - isPublished?: boolean; - title: string; - text: string; + id?: string; + isPublished?: boolean; + title: string; + text: string; } export class PostSubscriptionWhereInput { - AND?: PostSubscriptionWhereInput[]; - OR?: PostSubscriptionWhereInput[]; - NOT?: PostSubscriptionWhereInput[]; - mutation_in?: MutationType[]; - updatedFields_contains?: string; - updatedFields_contains_every?: string[]; - updatedFields_contains_some?: string[]; - node?: PostWhereInput; + AND?: PostSubscriptionWhereInput[]; + OR?: PostSubscriptionWhereInput[]; + NOT?: PostSubscriptionWhereInput[]; + mutation_in?: MutationType[]; + updatedFields_contains?: string; + updatedFields_contains_every?: string[]; + updatedFields_contains_some?: string[]; + node?: PostWhereInput; } export class PostUpdateInput { - isPublished?: boolean; - title?: string; - text?: string; + isPublished?: boolean; + title?: string; + text?: string; } export class PostUpdateManyMutationInput { - isPublished?: boolean; - title?: string; - text?: string; + isPublished?: boolean; + title?: string; + text?: string; } export class PostWhereInput { - AND?: PostWhereInput[]; - OR?: PostWhereInput[]; - NOT?: PostWhereInput[]; - id?: string; - id_not?: string; - id_in?: string[]; - id_not_in?: string[]; - id_lt?: string; - id_lte?: string; - id_gt?: string; - id_gte?: string; - id_contains?: string; - id_not_contains?: string; - id_starts_with?: string; - id_not_starts_with?: string; - id_ends_with?: string; - id_not_ends_with?: string; - isPublished?: boolean; - isPublished_not?: boolean; - title?: string; - title_not?: string; - title_in?: string[]; - title_not_in?: string[]; - title_lt?: string; - title_lte?: string; - title_gt?: string; - title_gte?: string; - title_contains?: string; - title_not_contains?: string; - title_starts_with?: string; - title_not_starts_with?: string; - title_ends_with?: string; - title_not_ends_with?: string; - text?: string; - text_not?: string; - text_in?: string[]; - text_not_in?: string[]; - text_lt?: string; - text_lte?: string; - text_gt?: string; - text_gte?: string; - text_contains?: string; - text_not_contains?: string; - text_starts_with?: string; - text_not_starts_with?: string; - text_ends_with?: string; - text_not_ends_with?: string; + AND?: PostWhereInput[]; + OR?: PostWhereInput[]; + NOT?: PostWhereInput[]; + id?: string; + id_not?: string; + id_in?: string[]; + id_not_in?: string[]; + id_lt?: string; + id_lte?: string; + id_gt?: string; + id_gte?: string; + id_contains?: string; + id_not_contains?: string; + id_starts_with?: string; + id_not_starts_with?: string; + id_ends_with?: string; + id_not_ends_with?: string; + isPublished?: boolean; + isPublished_not?: boolean; + title?: string; + title_not?: string; + title_in?: string[]; + title_not_in?: string[]; + title_lt?: string; + title_lte?: string; + title_gt?: string; + title_gte?: string; + title_contains?: string; + title_not_contains?: string; + title_starts_with?: string; + title_not_starts_with?: string; + title_ends_with?: string; + title_not_ends_with?: string; + text?: string; + text_not?: string; + text_in?: string[]; + text_not_in?: string[]; + text_lt?: string; + text_lte?: string; + text_gt?: string; + text_gte?: string; + text_contains?: string; + text_not_contains?: string; + text_starts_with?: string; + text_not_starts_with?: string; + text_ends_with?: string; + text_not_ends_with?: string; } export class PostWhereUniqueInput { - id?: string; + id?: string; } export interface Node { - id: string; + id: string; } export class AggregatePost { - count: number; + count: number; } export class BatchPayload { - count: Long; + count: Long; } export abstract class IMutation { - abstract createPost(data: PostCreateInput): Post | Promise; - abstract updatePost(data: PostUpdateInput, where: PostWhereUniqueInput): Post | Promise; - abstract deletePost(where: PostWhereUniqueInput): Post | Promise; - abstract upsertPost(where: PostWhereUniqueInput, create: PostCreateInput, update: PostUpdateInput): Post | Promise; - abstract updateManyPosts(data: PostUpdateManyMutationInput, where?: PostWhereInput): BatchPayload | Promise; - abstract deleteManyPosts(where?: PostWhereInput): BatchPayload | Promise; + abstract createPost(data: PostCreateInput): Post | Promise; + abstract updatePost( + data: PostUpdateInput, + where: PostWhereUniqueInput, + ): Post | Promise; + abstract deletePost(where: PostWhereUniqueInput): Post | Promise; + abstract upsertPost( + where: PostWhereUniqueInput, + create: PostCreateInput, + update: PostUpdateInput, + ): Post | Promise; + abstract updateManyPosts( + data: PostUpdateManyMutationInput, + where?: PostWhereInput, + ): BatchPayload | Promise; + abstract deleteManyPosts( + where?: PostWhereInput, + ): BatchPayload | Promise; } export class PageInfo { - hasNextPage: boolean; - hasPreviousPage: boolean; - startCursor?: string; - endCursor?: string; + hasNextPage: boolean; + hasPreviousPage: boolean; + startCursor?: string; + endCursor?: string; } export class Post implements Node { - id: string; - isPublished: boolean; - title: string; - text: string; + id: string; + isPublished: boolean; + title: string; + text: string; } export class PostConnection { - pageInfo: PageInfo; - edges: PostEdge[]; - aggregate: AggregatePost; + pageInfo: PageInfo; + edges: PostEdge[]; + aggregate: AggregatePost; } export class PostEdge { - node: Post; - cursor: string; + node: Post; + cursor: string; } export class PostPreviousValues { - id: string; - isPublished: boolean; - title: string; - text: string; + id: string; + isPublished: boolean; + title: string; + text: string; } export class PostSubscriptionPayload { - mutation: MutationType; - node?: Post; - updatedFields?: string[]; - previousValues?: PostPreviousValues; + mutation: MutationType; + node?: Post; + updatedFields?: string[]; + previousValues?: PostPreviousValues; } export abstract class IQuery { - abstract posts(where?: PostWhereInput, orderBy?: PostOrderByInput, skip?: number, after?: string, before?: string, first?: number, last?: number): Post[] | Promise; - abstract post(where: PostWhereUniqueInput): Post | Promise; - abstract postsConnection(where?: PostWhereInput, orderBy?: PostOrderByInput, skip?: number, after?: string, before?: string, first?: number, last?: number): PostConnection | Promise; - abstract node(id: string): Node | Promise; + abstract posts( + where?: PostWhereInput, + orderBy?: PostOrderByInput, + skip?: number, + after?: string, + before?: string, + first?: number, + last?: number, + ): Post[] | Promise; + abstract post(where: PostWhereUniqueInput): Post | Promise; + abstract postsConnection( + where?: PostWhereInput, + orderBy?: PostOrderByInput, + skip?: number, + after?: string, + before?: string, + first?: number, + last?: number, + ): PostConnection | Promise; + abstract node(id: string): Node | Promise; } export abstract class ISubscription { - abstract post(where?: PostSubscriptionWhereInput): PostSubscriptionPayload | Promise; + abstract post( + where?: PostSubscriptionWhereInput, + ): PostSubscriptionPayload | Promise; } export type Long = any; diff --git a/tools/gulp/tasks/samples.ts b/tools/gulp/tasks/samples.ts index 1abcc313e..dffb6acf5 100644 --- a/tools/gulp/tasks/samples.ts +++ b/tools/gulp/tasks/samples.ts @@ -49,7 +49,7 @@ async function executeNpmScriptInSamples( task('install:samples', async () => executeNpmScriptInSamples( // 'npm ci --no-audit --no-shrinkwrap --no-optional', - 'npm install' + 'npm install', ), ); task('build:samples', async () => executeNpmScriptInSamples('npm run build'));