Skip to content

Commit

Permalink
..
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Jul 27, 2022
1 parent 992eba3 commit f769172
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
24 changes: 17 additions & 7 deletions packages/graphql-yoga/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import { useCheckMethodForGraphQL } from './plugins/requestValidation/useCheckMe
import { useCheckGraphQLQueryParam } from './plugins/requestValidation/useCheckGraphQLQueryParam.js'
import { useHTTPValidationError } from './plugins/requestValidation/useHTTPValidationError.js'
import { usePreventMutationViaGET } from './plugins/requestValidation/usePreventMutationViaGET.js'
import { formatError } from './utils/formatError.js'

interface OptionsWithPlugins<TContext> {
/**
Expand Down Expand Up @@ -256,7 +257,21 @@ export class YogaServer<
}
: logger

const maskedErrors = options?.maskedErrors ?? true
let maskedErrorsOpts: UseMaskedErrorsOpts | null =
options?.maskedErrors === false
? null
: {
formatError,
}
if (
options?.maskedErrors != null &&
typeof options?.maskedErrors === 'object'
) {
maskedErrorsOpts = {
formatError,
...options.maskedErrors,
}
}

const server = this
this.endpoint = options?.endpoint
Expand Down Expand Up @@ -388,12 +403,7 @@ export class YogaServer<
// We make sure that the user doesn't send a mutation with GET
usePreventMutationViaGET(),

enableIf(
!!maskedErrors,
useMaskedErrors(
typeof maskedErrors === 'object' ? maskedErrors : undefined,
),
),
enableIf(maskedErrorsOpts != null, useMaskedErrors(maskedErrorsOpts!)),
]

this.getEnveloped = envelop({
Expand Down
9 changes: 9 additions & 0 deletions packages/graphql-yoga/src/utils/formatError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { FormatErrorHandler } from '@envelop/core'
import { GraphQLError } from 'graphql'

export const formatError: FormatErrorHandler = (err, message, isDev) => {
if (err instanceof GraphQLError) {
return err
}
return new GraphQLError(message)
}
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10169,7 +10169,7 @@ esbuild-windows-arm64@0.14.50:
resolved "https://registry.yarnpkg.com/esbuild-windows-arm64/-/esbuild-windows-arm64-0.14.50.tgz#e7ddde6a97194051a5a4ac05f4f5900e922a7ea5"
integrity sha512-EMS4lQnsIe12ZyAinOINx7eq2mjpDdhGZZWDwPZE/yUTN9cnc2Ze/xUTYIAyaJqrqQda3LnDpADKpvLvol6ENQ==

esbuild@0.14.47, esbuild@0.14.49, esbuild@0.14.50, esbuild@^0.14.25, esbuild@^0.14.47, esbuild@^0.14.48:
esbuild@0.14.47, esbuild@0.14.50, esbuild@^0.14.25, esbuild@^0.14.47, esbuild@^0.14.48:
version "0.14.50"
resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.14.50.tgz#7a665392c8df94bf6e1ae1e999966a5ee62c6cbc"
integrity sha512-SbC3k35Ih2IC6trhbMYW7hYeGdjPKf9atTKwBUHqMCYFZZ9z8zhuvfnZihsnJypl74FjiAKjBRqFkBkAd0rS/w==
Expand Down

0 comments on commit f769172

Please sign in to comment.