From 0f78875015b0d54f2a8fb1643da656ed3a915c38 Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU Date: Tue, 26 Jul 2022 13:58:26 +0300 Subject: [PATCH] Fixes --- packages/graphql-yoga/src/server.ts | 139 ++++++++++--------- packages/plugins/response-cache/package.json | 2 +- packages/plugins/response-cache/src/index.ts | 7 +- 3 files changed, 73 insertions(+), 75 deletions(-) diff --git a/packages/graphql-yoga/src/server.ts b/packages/graphql-yoga/src/server.ts index 602395031b..a46b00a102 100644 --- a/packages/graphql-yoga/src/server.ts +++ b/packages/graphql-yoga/src/server.ts @@ -34,7 +34,10 @@ import { } from './plugins/types.js' import { createFetch } from '@whatwg-node/fetch' import { ServerAdapter, createServerAdapter } from '@whatwg-node/server' -import { processRequest as processGraphQLParams } from './processRequest.js' +import { + processRequest as processGraphQLParams, + processResult, +} from './processRequest.js' import { defaultYogaLogger, titleBold, YogaLogger } from './logger.js' import { CORSPluginOptions, useCORS } from './plugins/useCORS.js' import { useHealthCheck } from './plugins/useHealthCheck.js' @@ -96,73 +99,73 @@ export type YogaServerOptions< TServerContext extends Record, TUserContext extends Record, TRootValue, - > = { - /** - * Enable/disable logging or provide a custom logger. - * @default true - */ - logging?: boolean | YogaLogger - /** - * Prevent leaking unexpected errors to the client. We highly recommend enabling this in production. - * If you throw `GraphQLYogaError`/`EnvelopError` within your GraphQL resolvers then that error will be sent back to the client. - * - * You can lean more about this here: - * @see https://graphql-yoga.vercel.app/docs/features/error-masking - * - * Default: `true` - */ - maskedErrors?: boolean | UseMaskedErrorsOpts - /** - * Context - */ - context?: +> = { + /** + * Enable/disable logging or provide a custom logger. + * @default true + */ + logging?: boolean | YogaLogger + /** + * Prevent leaking unexpected errors to the client. We highly recommend enabling this in production. + * If you throw `GraphQLYogaError`/`EnvelopError` within your GraphQL resolvers then that error will be sent back to the client. + * + * You can lean more about this here: + * @see https://graphql-yoga.vercel.app/docs/features/error-masking + * + * Default: `true` + */ + maskedErrors?: boolean | UseMaskedErrorsOpts + /** + * Context + */ + context?: | (( - initialContext: YogaInitialContext & TServerContext, - ) => Promise | TUserContext) + initialContext: YogaInitialContext & TServerContext, + ) => Promise | TUserContext) | Promise | TUserContext - cors?: CORSPluginOptions + cors?: CORSPluginOptions - /** - * GraphQL endpoint - */ - endpoint?: string + /** + * GraphQL endpoint + */ + endpoint?: string - /** - * GraphiQL options - * - * Default: `true` - */ - graphiql?: GraphiQLOptionsOrFactory + /** + * GraphiQL options + * + * Default: `true` + */ + graphiql?: GraphiQLOptionsOrFactory - renderGraphiQL?: (options?: GraphiQLOptions) => PromiseOrValue + renderGraphiQL?: (options?: GraphiQLOptions) => PromiseOrValue - schema?: + schema?: | GraphQLSchema | { - typeDefs: TypeSource - resolvers?: - | IResolvers< - TRootValue, - TUserContext & TServerContext & YogaInitialContext - > - | Array< - IResolvers< - TRootValue, - TUserContext & TServerContext & YogaInitialContext - > - > - } + typeDefs: TypeSource + resolvers?: + | IResolvers< + TRootValue, + TUserContext & TServerContext & YogaInitialContext + > + | Array< + IResolvers< + TRootValue, + TUserContext & TServerContext & YogaInitialContext + > + > + } - parserCache?: boolean | ParserCacheOptions - validationCache?: boolean | ValidationCache - fetchAPI?: FetchAPI - multipart?: boolean - id?: string - } & Partial< - OptionsWithPlugins - > + parserCache?: boolean | ParserCacheOptions + validationCache?: boolean | ValidationCache + fetchAPI?: FetchAPI + multipart?: boolean + id?: string +} & Partial< + OptionsWithPlugins +> export function getDefaultSchema() { return makeExecutableSchema({ @@ -207,7 +210,7 @@ export class YogaServer< TServerContext extends Record, TUserContext extends Record, TRootValue, - > { +> { /** * Instance of envelop */ @@ -239,9 +242,9 @@ export class YogaServer< ? isSchema(options.schema) ? options.schema : makeExecutableSchema({ - typeDefs: options.schema.typeDefs, - resolvers: options.schema.resolvers, - }) + typeDefs: options.schema.typeDefs, + resolvers: options.schema.resolvers, + }) : getDefaultSchema() const logger = options?.logging != null ? options.logging : true @@ -250,11 +253,11 @@ export class YogaServer< ? logger === true ? defaultYogaLogger : { - debug: () => { }, - error: () => { }, - warn: () => { }, - info: () => { }, - } + debug: () => {}, + error: () => {}, + warn: () => {}, + info: () => {}, + } : logger const maskedErrors = options?.maskedErrors ?? true @@ -634,8 +637,8 @@ export function createYoga< TServerContext extends Record = {}, TUserContext extends Record = {}, TRootValue = {}, - >( - options?: YogaServerOptions, +>( + options?: YogaServerOptions, ): YogaServerInstance { const server = new YogaServer( options, diff --git a/packages/plugins/response-cache/package.json b/packages/plugins/response-cache/package.json index ec48cfc6df..e25df5e78d 100644 --- a/packages/plugins/response-cache/package.json +++ b/packages/plugins/response-cache/package.json @@ -54,7 +54,7 @@ }, "peerDependencies": { "graphql": "^15.2.0 || ^16.0.0", - "@graphql-yoga/common": "^2.10.0" + "graphql-yoga": "^2.13.4" }, "type": "module" } diff --git a/packages/plugins/response-cache/src/index.ts b/packages/plugins/response-cache/src/index.ts index fb9570c3b9..6300ea4632 100644 --- a/packages/plugins/response-cache/src/index.ts +++ b/packages/plugins/response-cache/src/index.ts @@ -6,12 +6,7 @@ import { useResponseCache as useEnvelopResponseCache, UseResponseCacheParameter as UseEnvelopResponseCacheParameter, } from '@envelop/response-cache' -import { - GraphQLParams, - Maybe, - Plugin, - YogaInitialContext, -} from '@graphql-yoga/common' +import { GraphQLParams, Maybe, Plugin, YogaInitialContext } from 'graphql-yoga' export type UseResponseCacheParameter = Omit< UseEnvelopResponseCacheParameter,