@escape.tech/graphql-armor-block-field-suggestions
Advanced tools
Comparing version 1.2.0 to 1.2.1
import type { Plugin } from '@envelop/core'; | ||
declare const blockFieldSuggestionsPlugin: () => Plugin; | ||
declare type BlockFieldSuggestionsOptions = { | ||
mask?: string; | ||
}; | ||
export declare const blockFieldSuggestionsDefaultOptions: BlockFieldSuggestionsOptions; | ||
declare const blockFieldSuggestionsPlugin: (options?: BlockFieldSuggestionsOptions) => Plugin; | ||
export { blockFieldSuggestionsPlugin }; |
@@ -7,5 +7,9 @@ 'use strict'; | ||
const formatter = error => { | ||
const blockFieldSuggestionsDefaultOptions = { | ||
mask: '[Suggestion message hidden by GraphQLArmor]' | ||
}; | ||
const formatter = (error, mask = '[Suggestion message hidden by GraphQLArmor]') => { | ||
if (error instanceof graphql.GraphQLError) { | ||
error.message = error.message.replace(/Did you mean ".+"/g, '[Suggestion message hidden by GraphQLArmor]'); | ||
error.message = error.message.replace(/Did you mean ".+"/g, mask); | ||
} | ||
@@ -16,3 +20,3 @@ | ||
const blockFieldSuggestionsPlugin = () => { | ||
const blockFieldSuggestionsPlugin = options => { | ||
return { | ||
@@ -26,3 +30,3 @@ onValidate: () => { | ||
if (!valid) { | ||
setResult(result.map(error => formatter(error))); | ||
setResult(result.map(error => formatter(error, options === null || options === void 0 ? void 0 : options.mask))); | ||
} | ||
@@ -34,2 +38,3 @@ }; | ||
exports.blockFieldSuggestionsDefaultOptions = blockFieldSuggestionsDefaultOptions; | ||
exports.blockFieldSuggestionsPlugin = blockFieldSuggestionsPlugin; |
@@ -7,5 +7,9 @@ 'use strict'; | ||
const formatter = error => { | ||
const blockFieldSuggestionsDefaultOptions = { | ||
mask: '[Suggestion message hidden by GraphQLArmor]' | ||
}; | ||
const formatter = (error, mask = '[Suggestion message hidden by GraphQLArmor]') => { | ||
if (error instanceof graphql.GraphQLError) { | ||
error.message = error.message.replace(/Did you mean ".+"/g, '[Suggestion message hidden by GraphQLArmor]'); | ||
error.message = error.message.replace(/Did you mean ".+"/g, mask); | ||
} | ||
@@ -16,3 +20,3 @@ | ||
const blockFieldSuggestionsPlugin = () => { | ||
const blockFieldSuggestionsPlugin = options => { | ||
return { | ||
@@ -26,3 +30,3 @@ onValidate: () => { | ||
if (!valid) { | ||
setResult(result.map(error => formatter(error))); | ||
setResult(result.map(error => formatter(error, options === null || options === void 0 ? void 0 : options.mask))); | ||
} | ||
@@ -34,2 +38,3 @@ }; | ||
exports.blockFieldSuggestionsDefaultOptions = blockFieldSuggestionsDefaultOptions; | ||
exports.blockFieldSuggestionsPlugin = blockFieldSuggestionsPlugin; |
import { GraphQLError } from 'graphql'; | ||
const formatter = error => { | ||
const blockFieldSuggestionsDefaultOptions = { | ||
mask: '[Suggestion message hidden by GraphQLArmor]' | ||
}; | ||
const formatter = (error, mask = '[Suggestion message hidden by GraphQLArmor]') => { | ||
if (error instanceof GraphQLError) { | ||
error.message = error.message.replace(/Did you mean ".+"/g, '[Suggestion message hidden by GraphQLArmor]'); | ||
error.message = error.message.replace(/Did you mean ".+"/g, mask); | ||
} | ||
@@ -11,3 +15,3 @@ | ||
const blockFieldSuggestionsPlugin = () => { | ||
const blockFieldSuggestionsPlugin = options => { | ||
return { | ||
@@ -21,3 +25,3 @@ onValidate: () => { | ||
if (!valid) { | ||
setResult(result.map(error => formatter(error))); | ||
setResult(result.map(error => formatter(error, options === null || options === void 0 ? void 0 : options.mask))); | ||
} | ||
@@ -29,2 +33,2 @@ }; | ||
export { blockFieldSuggestionsPlugin }; | ||
export { blockFieldSuggestionsDefaultOptions, blockFieldSuggestionsPlugin }; |
{ | ||
"name": "@escape.tech/graphql-armor-block-field-suggestions", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "Block graphql field suggestion.", | ||
@@ -5,0 +5,0 @@ "packageManager": "yarn@3.2.2", |
@@ -19,3 +19,3 @@ # @escape.tech/graphl-armor-block-field-suggestions | ||
## Usage example | ||
## Usage example default | ||
@@ -35,1 +35,19 @@ ### With `@envelop/core` from `@the-guild-org` | ||
``` | ||
## Usage example with custom mask | ||
### With `@envelop/core` from `@the-guild-org` | ||
```typescript | ||
import { envelop } from '@envelop/core'; | ||
import { blockFieldSuggestions } from '@escape.tech/graphql-armor-block-field-suggestions'; | ||
const getEnveloped = envelop({ | ||
plugins: [ | ||
// ... other plugins ... | ||
blockFieldSuggestions({ | ||
mask: '<[REDACTED]>' | ||
}), | ||
] | ||
}) | ||
``` |
5563
98
52