Type safety with custom resolvers and `selectGraphQLResultFromTable`
See original GitHub issueSummary
Is it possible to have type-safe queries in makeExtendSchemaPlugin resolvers, so that the resolvers break at build time if incompatible database schema changes are made?
Details
I’ve been following the makeExtendSchemaPlugin docs and have written some custom resolvers.
I’ve converted my resolvers to TypeScript and have used Zapatos to generate a TypeScript schema from the DB. Now I get squiggly lines in my IDE and compile errors if my queries don’t match the database schema (see images below)
This is perfect, but I don’t see a way to get the same type-safety when using the selectGraphQLResultFromTable
query builder. This means the resolvers may still compile if I change the schema, but fail at runtime.
I’ve tried building the queries using Zapatos and using a hacked version of the resulting SQL in the query builder using sql.raw()
, but this seems like a bad idea.
Is there some way to get type safety when using selectGraphQLResultFromTable
? If not, could I start a feature-request discussion to have Postgraphile generate a TypeScript schema to be used with pgClient
and selectGraphQLResultFromTable
?
Additional context
Squigglies in VS Code
TypeScript compile errors
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
pg-sql2, the library we use for templating SQL, can also be used with pgClient - please refer to its readme 👍
I’ve used Zapatos within PostGraphile projects 👍
selectGraphQLResultFromTable
is going away in PostGraphile V5; it was only ever intended to be a wrapper method to stop people having to write so much boilerplate. I’d love your input on the new stuff once it’s ready to be shared publicly, so I’ll leave this open.