Is your feature request related to a problem? Please describe.
Rather a feature request than a problem :)
Role: {
Perms: () => {
return [...]
}
}
Perm: {
detail: (source) => "extra field populated from source";
}
=>
export type ResolversTypes = {
Query: {...};
Role: RoleDocument;
Perm: Omit<PermDocument, 'detail'> & {
detail: Maybe<...>
};
}
Describe the solution you'd like
The easiest solution I guess is marking the resolved field optional:
{ detail?: Maybe<...> }
If I understand your problem correctly, you might possibly want to take a look at this part of the documentation.
Wherever in your codegen config you have
- typescript-resolvers
you'd instead use
- typescript-resolvers:
defaultMapper: Partial<{T}>
With this setting, all the fields in the object returned from the resolver are optional, which allows you to return part of the result in the top-level resolver and then populate the rest in the nested resolvers.
Thanks for your reply. And yes, that's the problem.
The Partial<{T}> defaultMapper, on the opposite side, will ask for source.field! in the field resolver implementation, which seems not a perfect solution to me.
The field resolver is a nice feature in graphql, and it deserves a better support in codegen (typescript-resolvers, more specifically), IMHO.
Hi @flisky ,
I think @ohmoses is right, you can use defaultMapper to get it.
I'm not 100% sure, but maybe the generated should have ? when it's not a required field, can you please share your schema, or a repo with a reproduction?
It's difficult to understand what you mean by
The
Partial<{T}>defaultMapper … will ask forsource.field!in the field resolver implementation
In general, when having issues, it's best to provide a minimal example of schema + resolvers which illustrates your problem, but which is complete (e.g. doesn't use ... to skim over details), and then paste in the TypeScript error you're getting (or otherwise describe the difference between expected and actual behavior).
Sorry, I found the root case after investigating this issue more.
Please take a look at #1733 (hope I say it clearly this time:)
Most helpful comment
If I understand your problem correctly, you might possibly want to take a look at this part of the documentation.
Wherever in your codegen config you have
you'd instead use
With this setting, all the fields in the object returned from the resolver are optional, which allows you to return part of the result in the top-level resolver and then populate the rest in the nested resolvers.