Is it possible for resolver functions to use Named Arguments instead of Positional Arguments?
Current implementation
Most of our code is filled with unused vars because we frequently end up writing code like this
// other mutation code
resolve: async (query, root, { projectId }, ctx) =>
await prisma.project.delete({
...query,
where: {
userId: ctx.userId!,
id: projectId
}
})
In the above function, root is unused and if I set eslint to throw an error on unused vars, it will end up catching all of these vars.
Proposed Implementation
// other mutation code
resolve: async ({query, args, ctx}) =>
await prisma.project.delete({
...query,
where: {
userId: ctx.userId!,
id: args.projectId
}
})
Would it be possible to use Named arguments? This way, we only define vars that will be used.
Currently this isn't possible. The resolver args are based on how resolvers are implemented in the reference graphql implementation. Making arguments positional requires wrapping every resolver to transform the arguments. This adds more overhead than is acceptable to include in core, and would be a huge breaking change for anyone using Pothos.
I'm am making progress on a 4.0 release. It adds a lot of new flexibility for what plugins can do, and could theoretically allow building a plugin that could enable resolvers with names arguments
Most eslint rules that check for unused variables, should be configurable to ignore unused arguments that proceed used arguments. It's also common to ignore unused arguments prefixed with _
This happened to pop up on my phones news feed, and is somewhat relevant: https://johnnyreilly.com/typescript-eslint-no-unused-vars
Most eslint rules that check for unused variables, should be configurable to ignore unused arguments that proceed used arguments. It's also common to ignore unused arguments prefixed with
_
Yes, I am aware of that but it's just cleaner to not have those vars lying around. Thanks for the reply!