Does anyone use a strategy to type the results of ...
# random
l
Does anyone use a strategy to type the results of a
gql
string? I want to use the generated types, but there’s no guarantee we actually put the field in the query. Using the generated types, TypeScript tells us
user.firstName
is guaranteed to exist, but it’s not in this case. Having to have a custom type for each query seems fragile, redundant and a lot of extra work, so I was wondering if there’re any solutions for this?
🤔 2
b
we use this not sure it hits exactly what your asking for https://www.graphql-code-generator.com/
l
Yeah, we use that. I guess the problem is like, if you don’t include
firstName
in your
gql
query, it’ll actually be undefined, even though the generated types say it’s there. I kinda’ want a type generated from the
gql
string, although i know that’s probably an absurdly hard problem.
(Or like, a
Partial
with the types from the
gql
string. We can do it ourselves but again, it feels redundant as well as less foolproof.
b
oh well the flavor we are using is that you actually write the query/mutations and based on those it generates the output, its the documents option