1

How do I validate a GraphQL query parameter. I want the bookings query not to receive negative values on page parameter.

I am using these modules for typescript types generation, is it possible to generate a constraint? (page > 0)

{
    "@graphql-codegen/cli": "2.6.2",
    "graphql-codegen/typescript": "2.4.5"
{
type Booking { 
    id: ID!
    totalPrice: Float!
    user: User!
    event: Event!
    address: Address!
    createdAt: String!
}

type Query {
    bookings(page: Int!): [Booking!]!
}

1 Answers1

1

Neither GraphQL scheme nor Typescript support this type of restriction. I suggest you instead control it server-side

Update:

There is, in fact, an npm package implementing it

Vladyslav Zavalykhatko
  • 15,202
  • 8
  • 65
  • 100