Writing a custom resolver in typescript and I want to use the type returned from my gql query in my TypeScript return type.
For example, in my custom resolver I query for a Person
const Person = await ctx.api.gqlRequest(PERSON_QUERY)
This returns a row from the Person table, exactly as you’d expect. I then want to return this from my custom resolver. So my function’s return type looks like:
Promise<FunctionResult<{?}>>
I’m confused on how to get the Type to put as a generic here. I can’t just put Person, as that isn’t defined. I don’t want to spend time manually defining this Type, as it has many columns, and I’d have to manually update it everytime I add or remove a column.
So how do I get my typescript types from my graphql schema?
Even more, there should be a way to get these types in my frontend. But the typical tool used (graphql-codegen) doesn’t work, and returns each field as optional. This may be a question for another post though.
Welcome back to the community! Let me dig into this and see if I can find an answer. It’s certainly an interesting one since the awesome part of GraphQL is that your requests are usually very specific to just the fields you’re looking for with that request (ie. only a certain number of fields or even requests from multiple objects), but if you’re making a request that’s asking for the entire Person object I can see why this would be useful.