mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Set search query max size to 255 char
This commit is contained in:
parent
e5ffd3f5bd
commit
c596e88f46
3 changed files with 41 additions and 3 deletions
|
|
@ -46,5 +46,43 @@ export const sanitizeDirectiveTransformer = (schema: GraphQLSchema) => {
|
|||
}
|
||||
return fieldConfig
|
||||
},
|
||||
[MapperKind.ARGUMENT]: (argConfig) => {
|
||||
const sanitizeDirective = getDirective(schema, argConfig, 'sanitize')?.[0]
|
||||
if (!sanitizeDirective) {
|
||||
return argConfig
|
||||
}
|
||||
|
||||
const maxLength = sanitizeDirective.maxLength as number | undefined
|
||||
const minLength = sanitizeDirective.minLength as number | undefined
|
||||
const allowedTags = sanitizeDirective.allowedTags as string[] | undefined
|
||||
const pattern = sanitizeDirective.pattern as string | undefined
|
||||
|
||||
if (
|
||||
argConfig.type instanceof GraphQLNonNull &&
|
||||
argConfig.type.ofType instanceof GraphQLScalarType
|
||||
) {
|
||||
argConfig.type = new GraphQLNonNull(
|
||||
new SanitizedString(
|
||||
argConfig.type.ofType,
|
||||
allowedTags,
|
||||
maxLength,
|
||||
minLength,
|
||||
pattern
|
||||
)
|
||||
)
|
||||
} else if (argConfig.type instanceof GraphQLScalarType) {
|
||||
argConfig.type = new SanitizedString(
|
||||
argConfig.type,
|
||||
allowedTags,
|
||||
maxLength,
|
||||
minLength,
|
||||
pattern
|
||||
)
|
||||
} else {
|
||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
||||
throw new Error(`Not a scalar type: ${argConfig.type}`)
|
||||
}
|
||||
return argConfig
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
directive @sanitize(allowedTags: [String], maxLength: Int, minLength: Int, pattern: String) on INPUT_FIELD_DEFINITION
|
||||
directive @sanitize(allowedTags: [String], maxLength: Int, minLength: Int, pattern: String) on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION
|
||||
|
||||
type AddPopularReadError {
|
||||
errorCodes: [AddPopularReadErrorCode!]!
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ const schema = gql`
|
|||
maxLength: Int
|
||||
minLength: Int
|
||||
pattern: String
|
||||
) on INPUT_FIELD_DEFINITION
|
||||
) on INPUT_FIELD_DEFINITION | ARGUMENT_DEFINITION
|
||||
|
||||
enum SortOrder {
|
||||
ASCENDING
|
||||
|
|
@ -2542,7 +2542,7 @@ const schema = gql`
|
|||
search(
|
||||
after: String
|
||||
first: Int
|
||||
query: String
|
||||
query: String @sanitize(maxLength: 255)
|
||||
includeContent: Boolean
|
||||
format: String
|
||||
): SearchResult!
|
||||
|
|
|
|||
Loading…
Reference in a new issue