Description
Hi, I appreciate the attempts to improve typings, but it's worse than before, at least for smart queries. The issue that I failed to fix correctly in #726 is still in RC3, as more things have lost strict correct typing. I'm excited for 3.0 release and want to help ensure the typescript types are as correct as possible before release.
Issues
-
VueApolloQueryDefinition
allowsOperationVariables
for thevariables
, which means that we can no longer strongly typevariables
.OperationVariables
is just a generic index signature. This type might as well beany
. -
We also can't specify what kind of query definition is with
VueApolloQueryDefinition
, so the value ofupdate
is a generic any, rather than strongly typed.update: ((data: any) => any)
.
Previously, we could define what the variable type and the result type were, which allowed strong typing: VueApolloQueryOptions<EquipmentQueryVariables, EquipmentQuery>
. But now the generalized VueApolloQueryDefinition
just allows any
for basically everything.
I definitely appreciate an attempt to improve the typings, but this is a big step backwards for type safety. any
is an enemy!
Examples
< rc3, this strongly typed returns an EquipmentQuery
in Update, and the variables
are strongly typed for EquipmentQueryVariables
(supposed to be, see #726).
get (id: ID, type: EquipmentTypes): VueApolloQueryOptions<EquipmentQueryVariables, EquipmentQuery> {
return {
query: require('@/queries/gql/equipment.gql'),
variables: { id: parseInt(id), type }, // ❓should be type of EquipmentQueryVariables (#726)
update (data) {} // ✅ correctly inferred (parameter) data: EquipmentQuery
}
},
rc3 +, everything is basically "any"
get (id: ID, type: EquipmentTypes): VueApolloQueryDefinition {
return {
query: require('@/queries/gql/equipment.gql'),
variables: { id: parseInt(id), type }, // ❌inferred as any key signature
update (data) {} // ❌inferred as any
}
},
Purpose
We auto-generate our type definitions from our graphql schema using graphql-codegen
, much like someone would with React. All of our queries (and mutations, subscriptions) are strongly typed.
variables
being strongly typed is very important, as if we make changes to our server schema, we want to catch issues in our queries. This has been the source of at least two production issues now, which is what I tried to fix in Fix VariableFn<V> type returns Object instead of V #726.update
being strongly typed is very important for the same reason - making changes to the schema types should result compilation errors.
Thanks for reading.