Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Jul 27, 2022
1 parent fe50675 commit 0f78875
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 75 deletions.
139 changes: 71 additions & 68 deletions packages/graphql-yoga/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -96,73 +99,73 @@ export type YogaServerOptions<
TServerContext extends Record<string, any>,
TUserContext extends Record<string, any>,
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> | TUserContext)
initialContext: YogaInitialContext & TServerContext,
) => Promise<TUserContext> | TUserContext)
| Promise<TUserContext>
| TUserContext

cors?: CORSPluginOptions<TServerContext>
cors?: CORSPluginOptions<TServerContext>

/**
* GraphQL endpoint
*/
endpoint?: string
/**
* GraphQL endpoint
*/
endpoint?: string

/**
* GraphiQL options
*
* Default: `true`
*/
graphiql?: GraphiQLOptionsOrFactory<TServerContext>
/**
* GraphiQL options
*
* Default: `true`
*/
graphiql?: GraphiQLOptionsOrFactory<TServerContext>

renderGraphiQL?: (options?: GraphiQLOptions) => PromiseOrValue<BodyInit>
renderGraphiQL?: (options?: GraphiQLOptions) => PromiseOrValue<BodyInit>

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<TUserContext & TServerContext & YogaInitialContext>
>
parserCache?: boolean | ParserCacheOptions
validationCache?: boolean | ValidationCache
fetchAPI?: FetchAPI
multipart?: boolean
id?: string
} & Partial<
OptionsWithPlugins<TUserContext & TServerContext & YogaInitialContext>
>

export function getDefaultSchema() {
return makeExecutableSchema({
Expand Down Expand Up @@ -207,7 +210,7 @@ export class YogaServer<
TServerContext extends Record<string, any>,
TUserContext extends Record<string, any>,
TRootValue,
> {
> {
/**
* Instance of envelop
*/
Expand Down Expand Up @@ -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
Expand All @@ -250,11 +253,11 @@ export class YogaServer<
? logger === true
? defaultYogaLogger
: {
debug: () => { },
error: () => { },
warn: () => { },
info: () => { },
}
debug: () => {},
error: () => {},
warn: () => {},
info: () => {},
}
: logger

const maskedErrors = options?.maskedErrors ?? true
Expand Down Expand Up @@ -634,8 +637,8 @@ export function createYoga<
TServerContext extends Record<string, any> = {},
TUserContext extends Record<string, any> = {},
TRootValue = {},
>(
options?: YogaServerOptions<TServerContext, TUserContext, TRootValue>,
>(
options?: YogaServerOptions<TServerContext, TUserContext, TRootValue>,
): YogaServerInstance<TServerContext, TUserContext, TRootValue> {
const server = new YogaServer<TServerContext, TUserContext, TRootValue>(
options,
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/response-cache/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
7 changes: 1 addition & 6 deletions packages/plugins/response-cache/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 0f78875

Please sign in to comment.