Skip to content

Query params in non-GET request #108

@jakubkoje

Description

@jakubkoje

I have a DELETE endpoint that needs an optional access query param:

// Validator
export const exampleDeleteValidatorV1 = vine.compile(
  vine.object({
    params: vine.object({...}),
    access: vine.string().trim().optional(),
  })
)

On the client side, I want to pass access as a query param:

$tuyau.request('example.delete', {
  params: {...},
  query: { access: 'token' }, // TS error: 'query' does not exist
})

This gives a type error because Tuyau uses different type extractors for GET vs non-GET:

  • GET/HEAD: ExtractQueryForGet<T> — takes all flat validator properties (minus params/headers/cookies) as query
  • POST/PUT/PATCH/DELETE: ExtractQuery<T> — only recognizes query if the validator has an explicit query property

So for non-GET, flat validator props become body, not query. The workaround is to send access in body instead — AdonisJS request.all() merges body + qs flat, so the validator receives it either way. But it feels wrong to send query-like params in the body of a DELETE request.

Is there a recommended way to define query params in validators for non-GET requests? I noticed ExtractQuery<T> looks for a query key, but AdonisJS's request.validateUsing() doesn't populate a query key — it uses qs for query string data. So adding query: vine.object({...}) to the validator would fix Tuyau types but break runtime validation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions