Will API Gateway always put any querystring as a s...
# help
a
Will API Gateway always put any querystring as a string? (I’m using HTTP API) Or this is something I can configure in cdk?
f
Hey @Albert Gao, not that I’m aware of. It’s always passed to u as strings.
r
queryStringParameters is an object containing all the keys of the query string params that the API received, the types of each value will be strings.
a
Thanks mates, turns out that the
ajv
has an option to try converting string to my declared type, no problems at all xD
r
might look into that myself, thanks!
a
*new* Ajv({ allErrors: true, coerceTypes: true })
You gonna love it
r
I'll have a read of the docs, but curious, can it apply TypeScript types?
Seems, you can use TS generics with ajv, https://ajv.js.org/guide/typescript.html
but have to maintain a TS definition and a json schema definition
a
You do not need to duplicate the code, let me share you my secret receipt:
That
_IPathParams_
is a TS type infered from pathParams, which is the
validate
ajv function generated from a schema
The
Type.blahblah
is from this lib: https://github.com/sinclairzx81/typebox which will convert your typebox def into TS type and ajv schema
r
I need to have a think. I think I have the opposite where I already have typescript definitions that I currently cast the query parameters to. Not at my computer at the moment but will have a play later. Thanks for sharing
a
sounds like the code-first or schema-first question in GraphQL 🤣