You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am making a nexus plugin, which computes expensive operations (e.g. database fetch) and passes them into context to be used by different sub-resolvers
An example usage of the plugin can be something like:
queryField("postQuery", {
...
// This is the field that my plugin adds which return an object of the values to be computed
compute: (_, { id }, { db })=> {
return {
post: fetchPost(db);
}
},
authorize: (_, __, {db, computed}, )=> {
// use computed.post (not type-safe)
},
validate: (_,__,{computed})=> {
// use computed.post (not type-safe)
},
resolver: (_,__,)=> {
// use computed.post (not type-safe)
}
}
)
Everything is working fine except that It's not type-safe.
The plugin factory method should accept a parameter called additonalContextType which is a string e.g.
type SomeType<T> = {
computed: T
}
plugin(
{
additionlContextType: "SomeType<T>"
}
)
Then all additionalContextType parameters from all plugins should be merged with the original context type
So, Right now one problem is solved, the plugin is able to add an additional type to context, but still this T generic should be the return type of the compute function. How can that be achieved ?
The text was updated successfully, but these errors were encountered:
Hi there!
I am making a nexus plugin, which computes expensive operations (e.g. database fetch) and passes them into context to be used by different sub-resolvers
An example usage of the plugin can be something like:
Everything is working fine except that It's not type-safe.
Here is how the context is typed right now
Proposed Solution
The
plugin
factory method should accept a parameter calledadditonalContextType
which is a string e.g.Then all
additionalContextType
parameters from all plugins should be merged with the original context typeSo, Right now one problem is solved, the plugin is able to add an additional type to context, but still this
T
generic should be the return type of thecompute
function. How can that be achieved ?The text was updated successfully, but these errors were encountered: