When creating a subscriptionField, if one returns a properly typed AsyncIterator it should properly type the root of the resolve method. Unfortunately because the type is T = any, it seems like it overrides the real typing.
Example:
export const MySub = subscriptionField('MySub', {
type: SomeType,
resolve: (payload) => {
// payload is type object
},
subscribe: (_root, _args, _ctx) => {
return createIterator() as AsyncIterator<SomeTypePayload>
},
})
@Sytten I believe this is fixed in 0.19 - caught some errors in the kitchen sink actually. Can you give it a shot and see if it's any better?
I will trust you on this, I am still on 0.14 and I don't expect I will have time to update for a while... I can test with a pet project to see though.
Doesn't seem to be working:
unknown type for resolver param here https://github.com/graphql-nexus/nexus-plugin-prisma/blob/83c7596dc43f184562d44207af015b84b8b14cda/examples/hello-world/api.ts#L88What is the return type of the method subscribe? I found that sometimes with complex/nested constructs they don't properly bubble up the type of generic parameters. I have this problem with my nexus-shield plugin on objects.
AsyncGenerator<boolean, void, unknown>
@jasonkuhrt I could be wrong, but I don't know if it's possible to use the return type to infer the type usage in resolve. I could go dig up the TS issue, but I'm pretty sure you need to specify the type annotation of the first arg of resolve, it'll be type-safe (will check that the typing you supply for the source is correct), it's just not inferred.
I think you are right!
I thought that TS was able to infer a generic parameter from the output but it doesn't seem like it. :(
Looks like a TS bug actually https://github.com/microsoft/TypeScript/issues/41456
Closing, since we're technically now correct on the typings, and it's out of scope for Nexus to solve the inference issue.
Most helpful comment
Closing, since we're technically now correct on the typings, and it's out of scope for Nexus to solve the inference issue.